Merge branch 'pm-cpufreq'
[linux-2.6-block.git] / drivers / crypto / caam / caamalg.c
CommitLineData
8e8ec596
KP
1/*
2 * caam - Freescale FSL CAAM support for crypto API
3 *
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 *
6 * Based on talitos crypto API driver.
7 *
8 * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
9 *
10 * --------------- ---------------
11 * | JobDesc #1 |-------------------->| ShareDesc |
12 * | *(packet 1) | | (PDB) |
13 * --------------- |------------->| (hashKey) |
14 * . | | (cipherKey) |
15 * . | |-------->| (operation) |
16 * --------------- | | ---------------
17 * | JobDesc #2 |------| |
18 * | *(packet 2) | |
19 * --------------- |
20 * . |
21 * . |
22 * --------------- |
23 * | JobDesc #3 |------------
24 * | *(packet 3) |
25 * ---------------
26 *
27 * The SharedDesc never changes for a connection unless rekeyed, but
28 * each packet will likely be in a different place. So all we need
29 * to know to process the packet is where the input is, where the
30 * output goes, and what context we want to process with. Context is
31 * in the SharedDesc, packet references in the JobDesc.
32 *
33 * So, a job desc looks like:
34 *
35 * ---------------------
36 * | Header |
37 * | ShareDesc Pointer |
38 * | SEQ_OUT_PTR |
39 * | (output buffer) |
6ec47334 40 * | (output length) |
8e8ec596
KP
41 * | SEQ_IN_PTR |
42 * | (input buffer) |
6ec47334 43 * | (input length) |
8e8ec596
KP
44 * ---------------------
45 */
46
47#include "compat.h"
48
49#include "regs.h"
50#include "intern.h"
51#include "desc_constr.h"
52#include "jr.h"
53#include "error.h"
a299c837 54#include "sg_sw_sec4.h"
4c1ec1f9 55#include "key_gen.h"
8e8ec596
KP
56
57/*
58 * crypto alg
59 */
60#define CAAM_CRA_PRIORITY 3000
61/* max key is sum of AES_MAX_KEY_SIZE, max split key size */
62#define CAAM_MAX_KEY_SIZE (AES_MAX_KEY_SIZE + \
daebc465 63 CTR_RFC3686_NONCE_SIZE + \
8e8ec596
KP
64 SHA512_DIGEST_SIZE * 2)
65/* max IV is max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */
66#define CAAM_MAX_IV_LENGTH 16
67
f2147b88
HX
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)
479bcc7c
HX
71#define AUTHENC_DESC_JOB_IO_LEN (AEAD_DESC_JOB_IO_LEN + \
72 CAAM_CMD_SZ * 5)
f2147b88 73
4427b1b4 74/* length of descriptors text */
1acebad3 75#define DESC_AEAD_BASE (4 * CAAM_CMD_SZ)
479bcc7c
HX
76#define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 11 * CAAM_CMD_SZ)
77#define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ)
78#define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 9 * CAAM_CMD_SZ)
1acebad3 79
daebc465 80/* Note: Nonce is counted in enckeylen */
479bcc7c 81#define DESC_AEAD_CTR_RFC3686_LEN (4 * CAAM_CMD_SZ)
daebc465 82
ae4a825f 83#define DESC_AEAD_NULL_BASE (3 * CAAM_CMD_SZ)
479bcc7c
HX
84#define DESC_AEAD_NULL_ENC_LEN (DESC_AEAD_NULL_BASE + 11 * CAAM_CMD_SZ)
85#define DESC_AEAD_NULL_DEC_LEN (DESC_AEAD_NULL_BASE + 13 * CAAM_CMD_SZ)
ae4a825f 86
3ef8d945 87#define DESC_GCM_BASE (3 * CAAM_CMD_SZ)
f2147b88
HX
88#define DESC_GCM_ENC_LEN (DESC_GCM_BASE + 16 * CAAM_CMD_SZ)
89#define DESC_GCM_DEC_LEN (DESC_GCM_BASE + 12 * CAAM_CMD_SZ)
3ef8d945 90
bac68f2c 91#define DESC_RFC4106_BASE (3 * CAAM_CMD_SZ)
4aad0cc5
HG
92#define DESC_RFC4106_ENC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
93#define DESC_RFC4106_DEC_LEN (DESC_RFC4106_BASE + 13 * CAAM_CMD_SZ)
bac68f2c 94
5d0429a3 95#define DESC_RFC4543_BASE (3 * CAAM_CMD_SZ)
f2147b88
HX
96#define DESC_RFC4543_ENC_LEN (DESC_RFC4543_BASE + 11 * CAAM_CMD_SZ)
97#define DESC_RFC4543_DEC_LEN (DESC_RFC4543_BASE + 12 * CAAM_CMD_SZ)
5d0429a3 98
acdca31d
YK
99#define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ)
100#define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \
101 20 * CAAM_CMD_SZ)
102#define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \
103 15 * CAAM_CMD_SZ)
104
87e51b07
HX
105#define DESC_MAX_USED_BYTES (CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN)
106#define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ)
4427b1b4 107
8e8ec596
KP
108#ifdef DEBUG
109/* for print_hex_dumps with line references */
8e8ec596
KP
110#define debug(format, arg...) printk(format, arg)
111#else
112#define debug(format, arg...)
113#endif
cfc6f11b 114static struct list_head alg_list;
8e8ec596 115
479bcc7c
HX
116struct caam_alg_entry {
117 int class1_alg_type;
118 int class2_alg_type;
119 int alg_op;
120 bool rfc3686;
121 bool geniv;
122};
123
124struct caam_aead_alg {
125 struct aead_alg aead;
126 struct caam_alg_entry caam;
127 bool registered;
128};
129
1acebad3
YK
130/* Set DK bit in class 1 operation if shared */
131static inline void append_dec_op1(u32 *desc, u32 type)
132{
133 u32 *jump_cmd, *uncond_jump_cmd;
134
a60384df
HG
135 /* DK bit is valid only for AES */
136 if ((type & OP_ALG_ALGSEL_MASK) != OP_ALG_ALGSEL_AES) {
137 append_operation(desc, type | OP_ALG_AS_INITFINAL |
138 OP_ALG_DECRYPT);
139 return;
140 }
141
1acebad3
YK
142 jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD);
143 append_operation(desc, type | OP_ALG_AS_INITFINAL |
144 OP_ALG_DECRYPT);
145 uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL);
146 set_jump_tgt_here(desc, jump_cmd);
147 append_operation(desc, type | OP_ALG_AS_INITFINAL |
148 OP_ALG_DECRYPT | OP_ALG_AAI_DK);
149 set_jump_tgt_here(desc, uncond_jump_cmd);
150}
151
1acebad3
YK
152/*
153 * For aead functions, read payload and write payload,
154 * both of which are specified in req->src and req->dst
155 */
156static inline void aead_append_src_dst(u32 *desc, u32 msg_type)
157{
ae4a825f 158 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
1acebad3
YK
159 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH |
160 KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH);
1acebad3
YK
161}
162
acdca31d
YK
163/*
164 * For ablkcipher encrypt and decrypt, read from req->src and
165 * write to req->dst
166 */
167static inline void ablkcipher_append_src_dst(u32 *desc)
168{
70d793cc
KP
169 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
170 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
171 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 |
172 KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
173 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF);
acdca31d
YK
174}
175
8e8ec596
KP
176/*
177 * per-session context
178 */
179struct caam_ctx {
180 struct device *jrdev;
1acebad3
YK
181 u32 sh_desc_enc[DESC_MAX_USED_LEN];
182 u32 sh_desc_dec[DESC_MAX_USED_LEN];
183 u32 sh_desc_givenc[DESC_MAX_USED_LEN];
184 dma_addr_t sh_desc_enc_dma;
185 dma_addr_t sh_desc_dec_dma;
186 dma_addr_t sh_desc_givenc_dma;
8e8ec596
KP
187 u32 class1_alg_type;
188 u32 class2_alg_type;
189 u32 alg_op;
1acebad3 190 u8 key[CAAM_MAX_KEY_SIZE];
885e9e2f 191 dma_addr_t key_dma;
8e8ec596 192 unsigned int enckeylen;
8e8ec596
KP
193 unsigned int split_key_len;
194 unsigned int split_key_pad_len;
195 unsigned int authsize;
196};
197
1acebad3 198static void append_key_aead(u32 *desc, struct caam_ctx *ctx,
daebc465 199 int keys_fit_inline, bool is_rfc3686)
1acebad3 200{
daebc465
CV
201 u32 *nonce;
202 unsigned int enckeylen = ctx->enckeylen;
203
204 /*
205 * RFC3686 specific:
206 * | ctx->key = {AUTH_KEY, ENC_KEY, NONCE}
207 * | enckeylen = encryption key size + nonce size
208 */
209 if (is_rfc3686)
210 enckeylen -= CTR_RFC3686_NONCE_SIZE;
211
1acebad3
YK
212 if (keys_fit_inline) {
213 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
214 ctx->split_key_len, CLASS_2 |
215 KEY_DEST_MDHA_SPLIT | KEY_ENC);
216 append_key_as_imm(desc, (void *)ctx->key +
daebc465
CV
217 ctx->split_key_pad_len, enckeylen,
218 enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1acebad3
YK
219 } else {
220 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
221 KEY_DEST_MDHA_SPLIT | KEY_ENC);
222 append_key(desc, ctx->key_dma + ctx->split_key_pad_len,
daebc465
CV
223 enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
224 }
225
226 /* Load Counter into CONTEXT1 reg */
227 if (is_rfc3686) {
228 nonce = (u32 *)((void *)ctx->key + ctx->split_key_pad_len +
229 enckeylen);
230 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
231 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
232 append_move(desc,
233 MOVE_SRC_OUTFIFO |
234 MOVE_DEST_CLASS1CTX |
235 (16 << MOVE_OFFSET_SHIFT) |
236 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1acebad3
YK
237 }
238}
239
240static void init_sh_desc_key_aead(u32 *desc, struct caam_ctx *ctx,
daebc465 241 int keys_fit_inline, bool is_rfc3686)
1acebad3
YK
242{
243 u32 *key_jump_cmd;
244
daebc465
CV
245 /* Note: Context registers are saved. */
246 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1acebad3
YK
247
248 /* Skip if already shared */
249 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
250 JUMP_COND_SHRD);
251
daebc465 252 append_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
1acebad3
YK
253
254 set_jump_tgt_here(desc, key_jump_cmd);
1acebad3
YK
255}
256
ae4a825f
HG
257static int aead_null_set_sh_desc(struct crypto_aead *aead)
258{
ae4a825f
HG
259 struct caam_ctx *ctx = crypto_aead_ctx(aead);
260 struct device *jrdev = ctx->jrdev;
261 bool keys_fit_inline = false;
262 u32 *key_jump_cmd, *jump_cmd, *read_move_cmd, *write_move_cmd;
263 u32 *desc;
264
265 /*
266 * Job Descriptor and Shared Descriptors
267 * must all fit into the 64-word Descriptor h/w Buffer
268 */
479bcc7c 269 if (DESC_AEAD_NULL_ENC_LEN + AEAD_DESC_JOB_IO_LEN +
ae4a825f
HG
270 ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
271 keys_fit_inline = true;
272
479bcc7c 273 /* aead_encrypt shared descriptor */
ae4a825f
HG
274 desc = ctx->sh_desc_enc;
275
276 init_sh_desc(desc, HDR_SHARE_SERIAL);
277
278 /* Skip if already shared */
279 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
280 JUMP_COND_SHRD);
281 if (keys_fit_inline)
282 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
283 ctx->split_key_len, CLASS_2 |
284 KEY_DEST_MDHA_SPLIT | KEY_ENC);
285 else
286 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
287 KEY_DEST_MDHA_SPLIT | KEY_ENC);
288 set_jump_tgt_here(desc, key_jump_cmd);
289
479bcc7c
HX
290 /* assoclen + cryptlen = seqinlen */
291 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
ae4a825f 292
479bcc7c 293 /* Prepare to read and write cryptlen + assoclen bytes */
ae4a825f
HG
294 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
295 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
296
297 /*
298 * MOVE_LEN opcode is not available in all SEC HW revisions,
299 * thus need to do some magic, i.e. self-patch the descriptor
300 * buffer.
301 */
302 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
303 MOVE_DEST_MATH3 |
304 (0x6 << MOVE_LEN_SHIFT));
305 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 |
306 MOVE_DEST_DESCBUF |
307 MOVE_WAITCOMP |
308 (0x8 << MOVE_LEN_SHIFT));
309
310 /* Class 2 operation */
311 append_operation(desc, ctx->class2_alg_type |
312 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
313
314 /* Read and write cryptlen bytes */
315 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
316
317 set_move_tgt_here(desc, read_move_cmd);
318 set_move_tgt_here(desc, write_move_cmd);
319 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
320 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
321 MOVE_AUX_LS);
322
323 /* Write ICV */
324 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
325 LDST_SRCDST_BYTE_CONTEXT);
326
327 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
328 desc_bytes(desc),
329 DMA_TO_DEVICE);
330 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
331 dev_err(jrdev, "unable to map shared descriptor\n");
332 return -ENOMEM;
333 }
334#ifdef DEBUG
335 print_hex_dump(KERN_ERR,
336 "aead null enc shdesc@"__stringify(__LINE__)": ",
337 DUMP_PREFIX_ADDRESS, 16, 4, desc,
338 desc_bytes(desc), 1);
339#endif
340
341 /*
342 * Job Descriptor and Shared Descriptors
343 * must all fit into the 64-word Descriptor h/w Buffer
344 */
80cd88f2 345 keys_fit_inline = false;
ae4a825f
HG
346 if (DESC_AEAD_NULL_DEC_LEN + DESC_JOB_IO_LEN +
347 ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX)
348 keys_fit_inline = true;
349
350 desc = ctx->sh_desc_dec;
351
479bcc7c 352 /* aead_decrypt shared descriptor */
ae4a825f
HG
353 init_sh_desc(desc, HDR_SHARE_SERIAL);
354
355 /* Skip if already shared */
356 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
357 JUMP_COND_SHRD);
358 if (keys_fit_inline)
359 append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len,
360 ctx->split_key_len, CLASS_2 |
361 KEY_DEST_MDHA_SPLIT | KEY_ENC);
362 else
363 append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
364 KEY_DEST_MDHA_SPLIT | KEY_ENC);
365 set_jump_tgt_here(desc, key_jump_cmd);
366
367 /* Class 2 operation */
368 append_operation(desc, ctx->class2_alg_type |
369 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
370
479bcc7c 371 /* assoclen + cryptlen = seqoutlen */
ae4a825f 372 append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ);
ae4a825f 373
479bcc7c 374 /* Prepare to read and write cryptlen + assoclen bytes */
ae4a825f
HG
375 append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ);
376 append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ);
377
378 /*
379 * MOVE_LEN opcode is not available in all SEC HW revisions,
380 * thus need to do some magic, i.e. self-patch the descriptor
381 * buffer.
382 */
383 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF |
384 MOVE_DEST_MATH2 |
385 (0x6 << MOVE_LEN_SHIFT));
386 write_move_cmd = append_move(desc, MOVE_SRC_MATH2 |
387 MOVE_DEST_DESCBUF |
388 MOVE_WAITCOMP |
389 (0x8 << MOVE_LEN_SHIFT));
390
391 /* Read and write cryptlen bytes */
392 aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
393
394 /*
395 * Insert a NOP here, since we need at least 4 instructions between
396 * code patching the descriptor buffer and the location being patched.
397 */
398 jump_cmd = append_jump(desc, JUMP_TEST_ALL);
399 set_jump_tgt_here(desc, jump_cmd);
400
401 set_move_tgt_here(desc, read_move_cmd);
402 set_move_tgt_here(desc, write_move_cmd);
403 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
404 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO |
405 MOVE_AUX_LS);
406 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
407
408 /* Load ICV */
409 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
410 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
411
412 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
413 desc_bytes(desc),
414 DMA_TO_DEVICE);
415 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
416 dev_err(jrdev, "unable to map shared descriptor\n");
417 return -ENOMEM;
418 }
419#ifdef DEBUG
420 print_hex_dump(KERN_ERR,
421 "aead null dec shdesc@"__stringify(__LINE__)": ",
422 DUMP_PREFIX_ADDRESS, 16, 4, desc,
423 desc_bytes(desc), 1);
424#endif
425
426 return 0;
427}
428
1acebad3
YK
429static int aead_set_sh_desc(struct crypto_aead *aead)
430{
479bcc7c
HX
431 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
432 struct caam_aead_alg, aead);
add86d55 433 unsigned int ivsize = crypto_aead_ivsize(aead);
1acebad3
YK
434 struct caam_ctx *ctx = crypto_aead_ctx(aead);
435 struct device *jrdev = ctx->jrdev;
daebc465 436 bool keys_fit_inline;
1acebad3 437 u32 geniv, moveiv;
daebc465 438 u32 ctx1_iv_off = 0;
1acebad3 439 u32 *desc;
daebc465
CV
440 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
441 OP_ALG_AAI_CTR_MOD128);
479bcc7c 442 const bool is_rfc3686 = alg->caam.rfc3686;
1acebad3 443
ae4a825f
HG
444 /* NULL encryption / decryption */
445 if (!ctx->enckeylen)
446 return aead_null_set_sh_desc(aead);
447
daebc465
CV
448 /*
449 * AES-CTR needs to load IV in CONTEXT1 reg
450 * at an offset of 128bits (16bytes)
451 * CONTEXT1[255:128] = IV
452 */
453 if (ctr_mode)
454 ctx1_iv_off = 16;
455
456 /*
457 * RFC3686 specific:
458 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
459 */
460 if (is_rfc3686)
461 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
462
479bcc7c
HX
463 if (alg->caam.geniv)
464 goto skip_enc;
465
1acebad3
YK
466 /*
467 * Job Descriptor and Shared Descriptors
468 * must all fit into the 64-word Descriptor h/w Buffer
469 */
daebc465 470 keys_fit_inline = false;
479bcc7c 471 if (DESC_AEAD_ENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
daebc465
CV
472 ctx->split_key_pad_len + ctx->enckeylen +
473 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
1acebad3 474 CAAM_DESC_BYTES_MAX)
2af8f4a2 475 keys_fit_inline = true;
1acebad3 476
479bcc7c 477 /* aead_encrypt shared descriptor */
1acebad3
YK
478 desc = ctx->sh_desc_enc;
479
daebc465
CV
480 /* Note: Context registers are saved. */
481 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
1acebad3
YK
482
483 /* Class 2 operation */
484 append_operation(desc, ctx->class2_alg_type |
485 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
486
479bcc7c
HX
487 /* Read and write assoclen bytes */
488 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
489 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
1acebad3 490
479bcc7c
HX
491 /* Skip assoc data */
492 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1acebad3
YK
493
494 /* read assoc before reading payload */
495 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
479bcc7c 496 FIFOLDST_VLF);
daebc465
CV
497
498 /* Load Counter into CONTEXT1 reg */
499 if (is_rfc3686)
500 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
501 LDST_CLASS_1_CCB |
502 LDST_SRCDST_BYTE_CONTEXT |
503 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
504 LDST_OFFSET_SHIFT));
1acebad3
YK
505
506 /* Class 1 operation */
507 append_operation(desc, ctx->class1_alg_type |
508 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
509
510 /* Read and write cryptlen bytes */
479bcc7c
HX
511 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
512 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1acebad3
YK
513 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
514
515 /* Write ICV */
516 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
517 LDST_SRCDST_BYTE_CONTEXT);
518
519 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
520 desc_bytes(desc),
521 DMA_TO_DEVICE);
522 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
523 dev_err(jrdev, "unable to map shared descriptor\n");
524 return -ENOMEM;
525 }
526#ifdef DEBUG
514df281 527 print_hex_dump(KERN_ERR, "aead enc shdesc@"__stringify(__LINE__)": ",
1acebad3
YK
528 DUMP_PREFIX_ADDRESS, 16, 4, desc,
529 desc_bytes(desc), 1);
530#endif
531
479bcc7c 532skip_enc:
1acebad3
YK
533 /*
534 * Job Descriptor and Shared Descriptors
535 * must all fit into the 64-word Descriptor h/w Buffer
536 */
80cd88f2 537 keys_fit_inline = false;
479bcc7c 538 if (DESC_AEAD_DEC_LEN + AUTHENC_DESC_JOB_IO_LEN +
daebc465
CV
539 ctx->split_key_pad_len + ctx->enckeylen +
540 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
1acebad3 541 CAAM_DESC_BYTES_MAX)
2af8f4a2 542 keys_fit_inline = true;
1acebad3 543
479bcc7c 544 /* aead_decrypt shared descriptor */
4464a7d4 545 desc = ctx->sh_desc_dec;
1acebad3 546
daebc465
CV
547 /* Note: Context registers are saved. */
548 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
1acebad3
YK
549
550 /* Class 2 operation */
551 append_operation(desc, ctx->class2_alg_type |
552 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
553
479bcc7c
HX
554 /* Read and write assoclen bytes */
555 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
556 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
557
558 /* Skip assoc data */
559 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1acebad3
YK
560
561 /* read assoc before reading payload */
562 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
563 KEY_VLF);
564
daebc465
CV
565 /* Load Counter into CONTEXT1 reg */
566 if (is_rfc3686)
567 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
568 LDST_CLASS_1_CCB |
569 LDST_SRCDST_BYTE_CONTEXT |
570 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
571 LDST_OFFSET_SHIFT));
572
573 /* Choose operation */
574 if (ctr_mode)
575 append_operation(desc, ctx->class1_alg_type |
576 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
577 else
578 append_dec_op1(desc, ctx->class1_alg_type);
1acebad3
YK
579
580 /* Read and write cryptlen bytes */
479bcc7c
HX
581 append_math_add(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
582 append_math_add(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1acebad3
YK
583 aead_append_src_dst(desc, FIFOLD_TYPE_MSG);
584
585 /* Load ICV */
586 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 |
587 FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV);
1acebad3
YK
588
589 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
590 desc_bytes(desc),
591 DMA_TO_DEVICE);
592 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
593 dev_err(jrdev, "unable to map shared descriptor\n");
594 return -ENOMEM;
595 }
596#ifdef DEBUG
514df281 597 print_hex_dump(KERN_ERR, "aead dec shdesc@"__stringify(__LINE__)": ",
1acebad3
YK
598 DUMP_PREFIX_ADDRESS, 16, 4, desc,
599 desc_bytes(desc), 1);
600#endif
601
479bcc7c
HX
602 if (!alg->caam.geniv)
603 goto skip_givenc;
604
1acebad3
YK
605 /*
606 * Job Descriptor and Shared Descriptors
607 * must all fit into the 64-word Descriptor h/w Buffer
608 */
80cd88f2 609 keys_fit_inline = false;
479bcc7c 610 if (DESC_AEAD_GIVENC_LEN + AUTHENC_DESC_JOB_IO_LEN +
daebc465
CV
611 ctx->split_key_pad_len + ctx->enckeylen +
612 (is_rfc3686 ? DESC_AEAD_CTR_RFC3686_LEN : 0) <=
1acebad3 613 CAAM_DESC_BYTES_MAX)
2af8f4a2 614 keys_fit_inline = true;
1acebad3
YK
615
616 /* aead_givencrypt shared descriptor */
617 desc = ctx->sh_desc_givenc;
618
daebc465
CV
619 /* Note: Context registers are saved. */
620 init_sh_desc_key_aead(desc, ctx, keys_fit_inline, is_rfc3686);
1acebad3 621
479bcc7c
HX
622 if (is_rfc3686)
623 goto copy_iv;
624
1acebad3
YK
625 /* Generate IV */
626 geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
627 NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
add86d55 628 NFIFOENTRY_PTYPE_RND | (ivsize << NFIFOENTRY_DLEN_SHIFT);
1acebad3
YK
629 append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
630 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
631 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
daebc465
CV
632 append_move(desc, MOVE_WAITCOMP |
633 MOVE_SRC_INFIFO | MOVE_DEST_CLASS1CTX |
634 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
add86d55 635 (ivsize << MOVE_LEN_SHIFT));
1acebad3
YK
636 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
637
479bcc7c 638copy_iv:
1acebad3 639 /* Copy IV to class 1 context */
daebc465
CV
640 append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_OUTFIFO |
641 (ctx1_iv_off << MOVE_OFFSET_SHIFT) |
add86d55 642 (ivsize << MOVE_LEN_SHIFT));
1acebad3
YK
643
644 /* Return to encryption */
645 append_operation(desc, ctx->class2_alg_type |
646 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
647
648 /* ivsize + cryptlen = seqoutlen - authsize */
649 append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize);
650
479bcc7c
HX
651 /* Read and write assoclen bytes */
652 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
653 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
654
655 /* Skip assoc data */
656 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1acebad3
YK
657
658 /* read assoc before reading payload */
659 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG |
660 KEY_VLF);
661
daebc465 662 /* Copy iv from outfifo to class 2 fifo */
1acebad3 663 moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 |
add86d55 664 NFIFOENTRY_DTYPE_MSG | (ivsize << NFIFOENTRY_DLEN_SHIFT);
1acebad3
YK
665 append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB |
666 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
add86d55 667 append_load_imm_u32(desc, ivsize, LDST_CLASS_2_CCB |
1acebad3
YK
668 LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM);
669
daebc465
CV
670 /* Load Counter into CONTEXT1 reg */
671 if (is_rfc3686)
672 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
673 LDST_CLASS_1_CCB |
674 LDST_SRCDST_BYTE_CONTEXT |
675 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
676 LDST_OFFSET_SHIFT));
677
1acebad3
YK
678 /* Class 1 operation */
679 append_operation(desc, ctx->class1_alg_type |
680 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
681
682 /* Will write ivsize + cryptlen */
683 append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
684
685 /* Not need to reload iv */
add86d55 686 append_seq_fifo_load(desc, ivsize,
1acebad3
YK
687 FIFOLD_CLASS_SKIP);
688
689 /* Will read cryptlen */
690 append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
691 aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2);
692
693 /* Write ICV */
694 append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB |
695 LDST_SRCDST_BYTE_CONTEXT);
696
479bcc7c
HX
697 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
698 desc_bytes(desc),
699 DMA_TO_DEVICE);
1acebad3
YK
700 if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
701 dev_err(jrdev, "unable to map shared descriptor\n");
702 return -ENOMEM;
703 }
704#ifdef DEBUG
514df281 705 print_hex_dump(KERN_ERR, "aead givenc shdesc@"__stringify(__LINE__)": ",
1acebad3
YK
706 DUMP_PREFIX_ADDRESS, 16, 4, desc,
707 desc_bytes(desc), 1);
708#endif
709
479bcc7c 710skip_givenc:
1acebad3
YK
711 return 0;
712}
713
0e479300 714static int aead_setauthsize(struct crypto_aead *authenc,
8e8ec596
KP
715 unsigned int authsize)
716{
717 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
718
719 ctx->authsize = authsize;
1acebad3 720 aead_set_sh_desc(authenc);
8e8ec596
KP
721
722 return 0;
723}
724
3ef8d945
TA
725static int gcm_set_sh_desc(struct crypto_aead *aead)
726{
3ef8d945
TA
727 struct caam_ctx *ctx = crypto_aead_ctx(aead);
728 struct device *jrdev = ctx->jrdev;
729 bool keys_fit_inline = false;
730 u32 *key_jump_cmd, *zero_payload_jump_cmd,
731 *zero_assoc_jump_cmd1, *zero_assoc_jump_cmd2;
732 u32 *desc;
733
734 if (!ctx->enckeylen || !ctx->authsize)
735 return 0;
736
737 /*
738 * AES GCM encrypt shared descriptor
739 * Job Descriptor and Shared Descriptor
740 * must fit into the 64-word Descriptor h/w Buffer
741 */
f2147b88 742 if (DESC_GCM_ENC_LEN + GCM_DESC_JOB_IO_LEN +
3ef8d945
TA
743 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
744 keys_fit_inline = true;
745
746 desc = ctx->sh_desc_enc;
747
748 init_sh_desc(desc, HDR_SHARE_SERIAL);
749
750 /* skip key loading if they are loaded due to sharing */
751 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
752 JUMP_COND_SHRD | JUMP_COND_SELF);
753 if (keys_fit_inline)
754 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
755 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
756 else
757 append_key(desc, ctx->key_dma, ctx->enckeylen,
758 CLASS_1 | KEY_DEST_CLASS_REG);
759 set_jump_tgt_here(desc, key_jump_cmd);
760
761 /* class 1 operation */
762 append_operation(desc, ctx->class1_alg_type |
763 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
764
f2147b88
HX
765 /* if assoclen + cryptlen is ZERO, skip to ICV write */
766 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
767 zero_assoc_jump_cmd2 = append_jump(desc, JUMP_TEST_ALL |
768 JUMP_COND_MATH_Z);
3ef8d945 769
f2147b88
HX
770 /* if assoclen is ZERO, skip reading the assoc data */
771 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
772 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
773 JUMP_COND_MATH_Z);
3ef8d945 774
f2147b88
HX
775 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
776
777 /* skip assoc data */
778 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
779
780 /* cryptlen = seqinlen - assoclen */
781 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG3, CAAM_CMD_SZ);
3ef8d945
TA
782
783 /* if cryptlen is ZERO jump to zero-payload commands */
3ef8d945
TA
784 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
785 JUMP_COND_MATH_Z);
3ef8d945
TA
786
787 /* read assoc data */
788 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
789 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
790 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
791
f2147b88 792 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
3ef8d945
TA
793
794 /* write encrypted data */
795 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
796
797 /* read payload data */
798 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
799 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
800
801 /* jump the zero-payload commands */
f2147b88 802 append_jump(desc, JUMP_TEST_ALL | 2);
3ef8d945
TA
803
804 /* zero-payload commands */
805 set_jump_tgt_here(desc, zero_payload_jump_cmd);
806
3ef8d945
TA
807 /* read assoc data */
808 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
809 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST1);
810
f2147b88 811 /* There is no input data */
3ef8d945 812 set_jump_tgt_here(desc, zero_assoc_jump_cmd2);
3ef8d945
TA
813
814 /* write ICV */
815 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
816 LDST_SRCDST_BYTE_CONTEXT);
817
818 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
819 desc_bytes(desc),
820 DMA_TO_DEVICE);
821 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
822 dev_err(jrdev, "unable to map shared descriptor\n");
823 return -ENOMEM;
824 }
825#ifdef DEBUG
826 print_hex_dump(KERN_ERR, "gcm enc shdesc@"__stringify(__LINE__)": ",
827 DUMP_PREFIX_ADDRESS, 16, 4, desc,
828 desc_bytes(desc), 1);
829#endif
830
831 /*
832 * Job Descriptor and Shared Descriptors
833 * must all fit into the 64-word Descriptor h/w Buffer
834 */
835 keys_fit_inline = false;
f2147b88 836 if (DESC_GCM_DEC_LEN + GCM_DESC_JOB_IO_LEN +
3ef8d945
TA
837 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
838 keys_fit_inline = true;
839
840 desc = ctx->sh_desc_dec;
841
842 init_sh_desc(desc, HDR_SHARE_SERIAL);
843
844 /* skip key loading if they are loaded due to sharing */
845 key_jump_cmd = append_jump(desc, JUMP_JSL |
846 JUMP_TEST_ALL | JUMP_COND_SHRD |
847 JUMP_COND_SELF);
848 if (keys_fit_inline)
849 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
850 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
851 else
852 append_key(desc, ctx->key_dma, ctx->enckeylen,
853 CLASS_1 | KEY_DEST_CLASS_REG);
854 set_jump_tgt_here(desc, key_jump_cmd);
855
856 /* class 1 operation */
857 append_operation(desc, ctx->class1_alg_type |
858 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
859
f2147b88
HX
860 /* if assoclen is ZERO, skip reading the assoc data */
861 append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ);
862 zero_assoc_jump_cmd1 = append_jump(desc, JUMP_TEST_ALL |
863 JUMP_COND_MATH_Z);
3ef8d945 864
f2147b88 865 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
3ef8d945 866
f2147b88
HX
867 /* skip assoc data */
868 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
3ef8d945 869
3ef8d945
TA
870 /* read assoc data */
871 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
872 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
f2147b88 873
3ef8d945
TA
874 set_jump_tgt_here(desc, zero_assoc_jump_cmd1);
875
f2147b88
HX
876 /* cryptlen = seqoutlen - assoclen */
877 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
878
879 /* jump to zero-payload command if cryptlen is zero */
880 zero_payload_jump_cmd = append_jump(desc, JUMP_TEST_ALL |
881 JUMP_COND_MATH_Z);
882
883 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
3ef8d945
TA
884
885 /* store encrypted data */
886 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
887
888 /* read payload data */
889 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
890 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
891
3ef8d945
TA
892 /* zero-payload command */
893 set_jump_tgt_here(desc, zero_payload_jump_cmd);
894
3ef8d945
TA
895 /* read ICV */
896 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
897 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
898
899 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
900 desc_bytes(desc),
901 DMA_TO_DEVICE);
902 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
903 dev_err(jrdev, "unable to map shared descriptor\n");
904 return -ENOMEM;
905 }
906#ifdef DEBUG
907 print_hex_dump(KERN_ERR, "gcm dec shdesc@"__stringify(__LINE__)": ",
908 DUMP_PREFIX_ADDRESS, 16, 4, desc,
909 desc_bytes(desc), 1);
910#endif
911
912 return 0;
913}
914
915static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
916{
917 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
918
919 ctx->authsize = authsize;
920 gcm_set_sh_desc(authenc);
921
922 return 0;
923}
924
bac68f2c
TA
925static int rfc4106_set_sh_desc(struct crypto_aead *aead)
926{
bac68f2c
TA
927 struct caam_ctx *ctx = crypto_aead_ctx(aead);
928 struct device *jrdev = ctx->jrdev;
929 bool keys_fit_inline = false;
f2147b88 930 u32 *key_jump_cmd;
bac68f2c 931 u32 *desc;
bac68f2c
TA
932
933 if (!ctx->enckeylen || !ctx->authsize)
934 return 0;
935
936 /*
937 * RFC4106 encrypt shared descriptor
938 * Job Descriptor and Shared Descriptor
939 * must fit into the 64-word Descriptor h/w Buffer
940 */
f2147b88 941 if (DESC_RFC4106_ENC_LEN + GCM_DESC_JOB_IO_LEN +
bac68f2c
TA
942 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
943 keys_fit_inline = true;
944
945 desc = ctx->sh_desc_enc;
946
947 init_sh_desc(desc, HDR_SHARE_SERIAL);
948
949 /* Skip key loading if it is loaded due to sharing */
950 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
951 JUMP_COND_SHRD);
952 if (keys_fit_inline)
953 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
954 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
955 else
956 append_key(desc, ctx->key_dma, ctx->enckeylen,
957 CLASS_1 | KEY_DEST_CLASS_REG);
958 set_jump_tgt_here(desc, key_jump_cmd);
959
960 /* Class 1 operation */
961 append_operation(desc, ctx->class1_alg_type |
962 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
963
46218750 964 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
bac68f2c
TA
965 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
966
bac68f2c
TA
967 /* Read assoc data */
968 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
969 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
970
46218750
HX
971 /* Skip IV */
972 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
f2147b88 973
bac68f2c 974 /* Will read cryptlen bytes */
f2147b88 975 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
bac68f2c 976
4aad0cc5
HG
977 /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
978 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
bac68f2c 979
46218750
HX
980 /* Skip assoc data */
981 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
982
983 /* cryptlen = seqoutlen - assoclen */
4aad0cc5 984 append_math_sub(desc, VARSEQOUTLEN, VARSEQINLEN, REG0, CAAM_CMD_SZ);
46218750
HX
985
986 /* Write encrypted data */
987 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
988
4aad0cc5
HG
989 /* Read payload data */
990 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
991 FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1);
992
bac68f2c
TA
993 /* Write ICV */
994 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
995 LDST_SRCDST_BYTE_CONTEXT);
996
997 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
998 desc_bytes(desc),
999 DMA_TO_DEVICE);
1000 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1001 dev_err(jrdev, "unable to map shared descriptor\n");
1002 return -ENOMEM;
1003 }
1004#ifdef DEBUG
1005 print_hex_dump(KERN_ERR, "rfc4106 enc shdesc@"__stringify(__LINE__)": ",
1006 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1007 desc_bytes(desc), 1);
1008#endif
1009
1010 /*
1011 * Job Descriptor and Shared Descriptors
1012 * must all fit into the 64-word Descriptor h/w Buffer
1013 */
1014 keys_fit_inline = false;
1015 if (DESC_RFC4106_DEC_LEN + DESC_JOB_IO_LEN +
1016 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1017 keys_fit_inline = true;
1018
1019 desc = ctx->sh_desc_dec;
1020
1021 init_sh_desc(desc, HDR_SHARE_SERIAL);
1022
1023 /* Skip key loading if it is loaded due to sharing */
1024 key_jump_cmd = append_jump(desc, JUMP_JSL |
1025 JUMP_TEST_ALL | JUMP_COND_SHRD);
1026 if (keys_fit_inline)
1027 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1028 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1029 else
1030 append_key(desc, ctx->key_dma, ctx->enckeylen,
1031 CLASS_1 | KEY_DEST_CLASS_REG);
1032 set_jump_tgt_here(desc, key_jump_cmd);
1033
1034 /* Class 1 operation */
1035 append_operation(desc, ctx->class1_alg_type |
1036 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1037
46218750 1038 append_math_sub_imm_u32(desc, VARSEQINLEN, REG3, IMM, 8);
f2147b88 1039 append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ);
bac68f2c 1040
bac68f2c
TA
1041 /* Read assoc data */
1042 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1043 FIFOLD_TYPE_AAD | FIFOLD_TYPE_FLUSH1);
1044
46218750
HX
1045 /* Skip IV */
1046 append_seq_fifo_load(desc, 8, FIFOLD_CLASS_SKIP);
f2147b88 1047
bac68f2c 1048 /* Will read cryptlen bytes */
46218750 1049 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG3, CAAM_CMD_SZ);
bac68f2c 1050
4aad0cc5
HG
1051 /* Workaround for erratum A-005473 (simultaneous SEQ FIFO skips) */
1052 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLD_TYPE_MSG);
bac68f2c 1053
46218750
HX
1054 /* Skip assoc data */
1055 append_seq_fifo_store(desc, 0, FIFOST_TYPE_SKIP | FIFOLDST_VLF);
1056
1057 /* Will write cryptlen bytes */
1058 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
1059
1060 /* Store payload data */
1061 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1062
4aad0cc5
HG
1063 /* Read encrypted data */
1064 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | FIFOLDST_VLF |
1065 FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1);
1066
bac68f2c
TA
1067 /* Read ICV */
1068 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
1069 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1070
1071 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1072 desc_bytes(desc),
1073 DMA_TO_DEVICE);
1074 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
1075 dev_err(jrdev, "unable to map shared descriptor\n");
1076 return -ENOMEM;
1077 }
1078#ifdef DEBUG
1079 print_hex_dump(KERN_ERR, "rfc4106 dec shdesc@"__stringify(__LINE__)": ",
1080 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1081 desc_bytes(desc), 1);
1082#endif
1083
bac68f2c
TA
1084 return 0;
1085}
1086
1087static int rfc4106_setauthsize(struct crypto_aead *authenc,
1088 unsigned int authsize)
1089{
1090 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
1091
1092 ctx->authsize = authsize;
1093 rfc4106_set_sh_desc(authenc);
1094
1095 return 0;
1096}
1097
5d0429a3
TA
1098static int rfc4543_set_sh_desc(struct crypto_aead *aead)
1099{
5d0429a3
TA
1100 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1101 struct device *jrdev = ctx->jrdev;
1102 bool keys_fit_inline = false;
f2147b88 1103 u32 *key_jump_cmd;
5d0429a3
TA
1104 u32 *read_move_cmd, *write_move_cmd;
1105 u32 *desc;
5d0429a3
TA
1106
1107 if (!ctx->enckeylen || !ctx->authsize)
1108 return 0;
1109
1110 /*
1111 * RFC4543 encrypt shared descriptor
1112 * Job Descriptor and Shared Descriptor
1113 * must fit into the 64-word Descriptor h/w Buffer
1114 */
f2147b88 1115 if (DESC_RFC4543_ENC_LEN + GCM_DESC_JOB_IO_LEN +
5d0429a3
TA
1116 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1117 keys_fit_inline = true;
1118
1119 desc = ctx->sh_desc_enc;
1120
1121 init_sh_desc(desc, HDR_SHARE_SERIAL);
1122
1123 /* Skip key loading if it is loaded due to sharing */
1124 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1125 JUMP_COND_SHRD);
1126 if (keys_fit_inline)
1127 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1128 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1129 else
1130 append_key(desc, ctx->key_dma, ctx->enckeylen,
1131 CLASS_1 | KEY_DEST_CLASS_REG);
1132 set_jump_tgt_here(desc, key_jump_cmd);
1133
1134 /* Class 1 operation */
1135 append_operation(desc, ctx->class1_alg_type |
1136 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1137
f2147b88
HX
1138 /* assoclen + cryptlen = seqinlen */
1139 append_math_sub(desc, REG3, SEQINLEN, REG0, CAAM_CMD_SZ);
5d0429a3
TA
1140
1141 /*
1142 * MOVE_LEN opcode is not available in all SEC HW revisions,
1143 * thus need to do some magic, i.e. self-patch the descriptor
1144 * buffer.
1145 */
1146 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1147 (0x6 << MOVE_LEN_SHIFT));
1148 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1149 (0x8 << MOVE_LEN_SHIFT));
1150
f2147b88
HX
1151 /* Will read assoclen + cryptlen bytes */
1152 append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
5d0429a3 1153
f2147b88
HX
1154 /* Will write assoclen + cryptlen bytes */
1155 append_math_sub(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
1156
1157 /* Read and write assoclen + cryptlen bytes */
5d0429a3
TA
1158 aead_append_src_dst(desc, FIFOLD_TYPE_AAD);
1159
1160 set_move_tgt_here(desc, read_move_cmd);
1161 set_move_tgt_here(desc, write_move_cmd);
1162 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1163 /* Move payload data to OFIFO */
1164 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1165
1166 /* Write ICV */
1167 append_seq_store(desc, ctx->authsize, LDST_CLASS_1_CCB |
1168 LDST_SRCDST_BYTE_CONTEXT);
1169
1170 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
1171 desc_bytes(desc),
1172 DMA_TO_DEVICE);
1173 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1174 dev_err(jrdev, "unable to map shared descriptor\n");
1175 return -ENOMEM;
1176 }
1177#ifdef DEBUG
1178 print_hex_dump(KERN_ERR, "rfc4543 enc shdesc@"__stringify(__LINE__)": ",
1179 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1180 desc_bytes(desc), 1);
1181#endif
1182
1183 /*
1184 * Job Descriptor and Shared Descriptors
1185 * must all fit into the 64-word Descriptor h/w Buffer
1186 */
1187 keys_fit_inline = false;
f2147b88 1188 if (DESC_RFC4543_DEC_LEN + GCM_DESC_JOB_IO_LEN +
5d0429a3
TA
1189 ctx->enckeylen <= CAAM_DESC_BYTES_MAX)
1190 keys_fit_inline = true;
1191
1192 desc = ctx->sh_desc_dec;
1193
1194 init_sh_desc(desc, HDR_SHARE_SERIAL);
1195
1196 /* Skip key loading if it is loaded due to sharing */
1197 key_jump_cmd = append_jump(desc, JUMP_JSL |
1198 JUMP_TEST_ALL | JUMP_COND_SHRD);
1199 if (keys_fit_inline)
1200 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1201 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
1202 else
1203 append_key(desc, ctx->key_dma, ctx->enckeylen,
1204 CLASS_1 | KEY_DEST_CLASS_REG);
1205 set_jump_tgt_here(desc, key_jump_cmd);
1206
1207 /* Class 1 operation */
1208 append_operation(desc, ctx->class1_alg_type |
1209 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON);
1210
f2147b88
HX
1211 /* assoclen + cryptlen = seqoutlen */
1212 append_math_sub(desc, REG3, SEQOUTLEN, REG0, CAAM_CMD_SZ);
5d0429a3
TA
1213
1214 /*
1215 * MOVE_LEN opcode is not available in all SEC HW revisions,
1216 * thus need to do some magic, i.e. self-patch the descriptor
1217 * buffer.
1218 */
1219 read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | MOVE_DEST_MATH3 |
1220 (0x6 << MOVE_LEN_SHIFT));
1221 write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | MOVE_DEST_DESCBUF |
1222 (0x8 << MOVE_LEN_SHIFT));
1223
f2147b88
HX
1224 /* Will read assoclen + cryptlen bytes */
1225 append_math_sub(desc, VARSEQINLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
5d0429a3 1226
f2147b88
HX
1227 /* Will write assoclen + cryptlen bytes */
1228 append_math_sub(desc, VARSEQOUTLEN, SEQOUTLEN, REG0, CAAM_CMD_SZ);
5d0429a3
TA
1229
1230 /* Store payload data */
1231 append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | FIFOLDST_VLF);
1232
f2147b88 1233 /* In-snoop assoclen + cryptlen data */
5d0429a3
TA
1234 append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | FIFOLDST_VLF |
1235 FIFOLD_TYPE_AAD | FIFOLD_TYPE_LAST2FLUSH1);
1236
1237 set_move_tgt_here(desc, read_move_cmd);
1238 set_move_tgt_here(desc, write_move_cmd);
1239 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1240 /* Move payload data to OFIFO */
1241 append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO);
1242 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
1243
1244 /* Read ICV */
1245 append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS1 |
1246 FIFOLD_TYPE_ICV | FIFOLD_TYPE_LAST1);
1247
1248 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1249 desc_bytes(desc),
1250 DMA_TO_DEVICE);
1251 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
1252 dev_err(jrdev, "unable to map shared descriptor\n");
1253 return -ENOMEM;
1254 }
1255#ifdef DEBUG
1256 print_hex_dump(KERN_ERR, "rfc4543 dec shdesc@"__stringify(__LINE__)": ",
1257 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1258 desc_bytes(desc), 1);
1259#endif
1260
f2147b88
HX
1261 return 0;
1262}
5d0429a3 1263
f2147b88
HX
1264static int rfc4543_setauthsize(struct crypto_aead *authenc,
1265 unsigned int authsize)
1266{
1267 struct caam_ctx *ctx = crypto_aead_ctx(authenc);
5d0429a3 1268
f2147b88
HX
1269 ctx->authsize = authsize;
1270 rfc4543_set_sh_desc(authenc);
5d0429a3 1271
f2147b88
HX
1272 return 0;
1273}
5d0429a3 1274
4c1ec1f9
YK
1275static u32 gen_split_aead_key(struct caam_ctx *ctx, const u8 *key_in,
1276 u32 authkeylen)
8e8ec596 1277{
4c1ec1f9
YK
1278 return gen_split_key(ctx->jrdev, ctx->key, ctx->split_key_len,
1279 ctx->split_key_pad_len, key_in, authkeylen,
1280 ctx->alg_op);
8e8ec596
KP
1281}
1282
0e479300 1283static int aead_setkey(struct crypto_aead *aead,
8e8ec596
KP
1284 const u8 *key, unsigned int keylen)
1285{
1286 /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
1287 static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
1288 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1289 struct device *jrdev = ctx->jrdev;
4e6e0b27 1290 struct crypto_authenc_keys keys;
8e8ec596
KP
1291 int ret = 0;
1292
4e6e0b27 1293 if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
8e8ec596
KP
1294 goto badkey;
1295
1296 /* Pick class 2 key length from algorithm submask */
1297 ctx->split_key_len = mdpadlen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >>
1298 OP_ALG_ALGSEL_SHIFT] * 2;
1299 ctx->split_key_pad_len = ALIGN(ctx->split_key_len, 16);
1300
4e6e0b27
HG
1301 if (ctx->split_key_pad_len + keys.enckeylen > CAAM_MAX_KEY_SIZE)
1302 goto badkey;
1303
8e8ec596
KP
1304#ifdef DEBUG
1305 printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n",
4e6e0b27
HG
1306 keys.authkeylen + keys.enckeylen, keys.enckeylen,
1307 keys.authkeylen);
8e8ec596
KP
1308 printk(KERN_ERR "split_key_len %d split_key_pad_len %d\n",
1309 ctx->split_key_len, ctx->split_key_pad_len);
514df281 1310 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
8e8ec596
KP
1311 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1312#endif
8e8ec596 1313
4e6e0b27 1314 ret = gen_split_aead_key(ctx, keys.authkey, keys.authkeylen);
8e8ec596 1315 if (ret) {
8e8ec596
KP
1316 goto badkey;
1317 }
1318
1319 /* postpend encryption key to auth split key */
4e6e0b27 1320 memcpy(ctx->key + ctx->split_key_pad_len, keys.enckey, keys.enckeylen);
8e8ec596 1321
885e9e2f 1322 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len +
4e6e0b27 1323 keys.enckeylen, DMA_TO_DEVICE);
885e9e2f 1324 if (dma_mapping_error(jrdev, ctx->key_dma)) {
8e8ec596 1325 dev_err(jrdev, "unable to map key i/o memory\n");
8e8ec596
KP
1326 return -ENOMEM;
1327 }
1328#ifdef DEBUG
514df281 1329 print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ",
8e8ec596 1330 DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
4e6e0b27 1331 ctx->split_key_pad_len + keys.enckeylen, 1);
8e8ec596
KP
1332#endif
1333
4e6e0b27 1334 ctx->enckeylen = keys.enckeylen;
8e8ec596 1335
1acebad3 1336 ret = aead_set_sh_desc(aead);
8e8ec596 1337 if (ret) {
885e9e2f 1338 dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len +
4e6e0b27 1339 keys.enckeylen, DMA_TO_DEVICE);
8e8ec596
KP
1340 }
1341
1342 return ret;
1343badkey:
1344 crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN);
1345 return -EINVAL;
1346}
1347
3ef8d945
TA
1348static int gcm_setkey(struct crypto_aead *aead,
1349 const u8 *key, unsigned int keylen)
1350{
1351 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1352 struct device *jrdev = ctx->jrdev;
1353 int ret = 0;
1354
1355#ifdef DEBUG
1356 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1357 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1358#endif
1359
1360 memcpy(ctx->key, key, keylen);
1361 ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
1362 DMA_TO_DEVICE);
1363 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1364 dev_err(jrdev, "unable to map key i/o memory\n");
1365 return -ENOMEM;
1366 }
1367 ctx->enckeylen = keylen;
1368
1369 ret = gcm_set_sh_desc(aead);
1370 if (ret) {
1371 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1372 DMA_TO_DEVICE);
1373 }
1374
1375 return ret;
1376}
1377
bac68f2c
TA
1378static int rfc4106_setkey(struct crypto_aead *aead,
1379 const u8 *key, unsigned int keylen)
1380{
1381 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1382 struct device *jrdev = ctx->jrdev;
1383 int ret = 0;
1384
1385 if (keylen < 4)
1386 return -EINVAL;
1387
1388#ifdef DEBUG
1389 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1390 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1391#endif
1392
1393 memcpy(ctx->key, key, keylen);
1394
1395 /*
1396 * The last four bytes of the key material are used as the salt value
1397 * in the nonce. Update the AES key length.
1398 */
1399 ctx->enckeylen = keylen - 4;
1400
1401 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
1402 DMA_TO_DEVICE);
1403 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1404 dev_err(jrdev, "unable to map key i/o memory\n");
1405 return -ENOMEM;
1406 }
1407
1408 ret = rfc4106_set_sh_desc(aead);
1409 if (ret) {
1410 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1411 DMA_TO_DEVICE);
1412 }
1413
1414 return ret;
1415}
1416
5d0429a3
TA
1417static int rfc4543_setkey(struct crypto_aead *aead,
1418 const u8 *key, unsigned int keylen)
1419{
1420 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1421 struct device *jrdev = ctx->jrdev;
1422 int ret = 0;
1423
1424 if (keylen < 4)
1425 return -EINVAL;
1426
1427#ifdef DEBUG
1428 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
1429 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1430#endif
1431
1432 memcpy(ctx->key, key, keylen);
1433
1434 /*
1435 * The last four bytes of the key material are used as the salt value
1436 * in the nonce. Update the AES key length.
1437 */
1438 ctx->enckeylen = keylen - 4;
1439
1440 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->enckeylen,
1441 DMA_TO_DEVICE);
1442 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1443 dev_err(jrdev, "unable to map key i/o memory\n");
1444 return -ENOMEM;
1445 }
1446
1447 ret = rfc4543_set_sh_desc(aead);
1448 if (ret) {
1449 dma_unmap_single(jrdev, ctx->key_dma, ctx->enckeylen,
1450 DMA_TO_DEVICE);
1451 }
1452
1453 return ret;
1454}
1455
acdca31d
YK
1456static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
1457 const u8 *key, unsigned int keylen)
1458{
1459 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
a5f57cff
CV
1460 struct ablkcipher_tfm *crt = &ablkcipher->base.crt_ablkcipher;
1461 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher);
1462 const char *alg_name = crypto_tfm_alg_name(tfm);
acdca31d
YK
1463 struct device *jrdev = ctx->jrdev;
1464 int ret = 0;
4464a7d4 1465 u32 *key_jump_cmd;
acdca31d 1466 u32 *desc;
a5f57cff 1467 u32 *nonce;
7222d1a3 1468 u32 geniv;
2b22f6c5
CV
1469 u32 ctx1_iv_off = 0;
1470 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
1471 OP_ALG_AAI_CTR_MOD128);
a5f57cff
CV
1472 const bool is_rfc3686 = (ctr_mode &&
1473 (strstr(alg_name, "rfc3686") != NULL));
acdca31d
YK
1474
1475#ifdef DEBUG
514df281 1476 print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ",
acdca31d
YK
1477 DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
1478#endif
2b22f6c5
CV
1479 /*
1480 * AES-CTR needs to load IV in CONTEXT1 reg
1481 * at an offset of 128bits (16bytes)
1482 * CONTEXT1[255:128] = IV
1483 */
1484 if (ctr_mode)
1485 ctx1_iv_off = 16;
acdca31d 1486
a5f57cff
CV
1487 /*
1488 * RFC3686 specific:
1489 * | CONTEXT1[255:128] = {NONCE, IV, COUNTER}
1490 * | *key = {KEY, NONCE}
1491 */
1492 if (is_rfc3686) {
1493 ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
1494 keylen -= CTR_RFC3686_NONCE_SIZE;
1495 }
1496
acdca31d
YK
1497 memcpy(ctx->key, key, keylen);
1498 ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen,
1499 DMA_TO_DEVICE);
1500 if (dma_mapping_error(jrdev, ctx->key_dma)) {
1501 dev_err(jrdev, "unable to map key i/o memory\n");
1502 return -ENOMEM;
1503 }
1504 ctx->enckeylen = keylen;
1505
1506 /* ablkcipher_encrypt shared descriptor */
1507 desc = ctx->sh_desc_enc;
a5f57cff 1508 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
acdca31d
YK
1509 /* Skip if already shared */
1510 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1511 JUMP_COND_SHRD);
1512
1513 /* Load class1 key only */
1514 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1515 ctx->enckeylen, CLASS_1 |
1516 KEY_DEST_CLASS_REG);
1517
a5f57cff
CV
1518 /* Load nonce into CONTEXT1 reg */
1519 if (is_rfc3686) {
1520 nonce = (u32 *)(key + keylen);
1521 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1522 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1523 append_move(desc, MOVE_WAITCOMP |
1524 MOVE_SRC_OUTFIFO |
1525 MOVE_DEST_CLASS1CTX |
1526 (16 << MOVE_OFFSET_SHIFT) |
1527 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1528 }
1529
acdca31d
YK
1530 set_jump_tgt_here(desc, key_jump_cmd);
1531
acdca31d 1532 /* Load iv */
a5f57cff 1533 append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
2b22f6c5 1534 LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
acdca31d 1535
a5f57cff
CV
1536 /* Load counter into CONTEXT1 reg */
1537 if (is_rfc3686)
1538 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
1539 LDST_CLASS_1_CCB |
1540 LDST_SRCDST_BYTE_CONTEXT |
1541 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1542 LDST_OFFSET_SHIFT));
1543
acdca31d
YK
1544 /* Load operation */
1545 append_operation(desc, ctx->class1_alg_type |
1546 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1547
1548 /* Perform operation */
1549 ablkcipher_append_src_dst(desc);
1550
1551 ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc,
1552 desc_bytes(desc),
1553 DMA_TO_DEVICE);
1554 if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) {
1555 dev_err(jrdev, "unable to map shared descriptor\n");
1556 return -ENOMEM;
1557 }
1558#ifdef DEBUG
514df281
AP
1559 print_hex_dump(KERN_ERR,
1560 "ablkcipher enc shdesc@"__stringify(__LINE__)": ",
acdca31d
YK
1561 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1562 desc_bytes(desc), 1);
1563#endif
1564 /* ablkcipher_decrypt shared descriptor */
1565 desc = ctx->sh_desc_dec;
1566
a5f57cff 1567 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
acdca31d
YK
1568 /* Skip if already shared */
1569 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1570 JUMP_COND_SHRD);
1571
1572 /* Load class1 key only */
1573 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1574 ctx->enckeylen, CLASS_1 |
1575 KEY_DEST_CLASS_REG);
1576
a5f57cff
CV
1577 /* Load nonce into CONTEXT1 reg */
1578 if (is_rfc3686) {
1579 nonce = (u32 *)(key + keylen);
1580 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1581 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1582 append_move(desc, MOVE_WAITCOMP |
1583 MOVE_SRC_OUTFIFO |
1584 MOVE_DEST_CLASS1CTX |
1585 (16 << MOVE_OFFSET_SHIFT) |
1586 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1587 }
1588
acdca31d 1589 set_jump_tgt_here(desc, key_jump_cmd);
acdca31d
YK
1590
1591 /* load IV */
a5f57cff 1592 append_seq_load(desc, crt->ivsize, LDST_SRCDST_BYTE_CONTEXT |
2b22f6c5 1593 LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT));
acdca31d 1594
a5f57cff
CV
1595 /* Load counter into CONTEXT1 reg */
1596 if (is_rfc3686)
1597 append_load_imm_u32(desc, be32_to_cpu(1), LDST_IMM |
1598 LDST_CLASS_1_CCB |
1599 LDST_SRCDST_BYTE_CONTEXT |
1600 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1601 LDST_OFFSET_SHIFT));
1602
acdca31d 1603 /* Choose operation */
2b22f6c5
CV
1604 if (ctr_mode)
1605 append_operation(desc, ctx->class1_alg_type |
1606 OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
1607 else
1608 append_dec_op1(desc, ctx->class1_alg_type);
acdca31d
YK
1609
1610 /* Perform operation */
1611 ablkcipher_append_src_dst(desc);
1612
acdca31d
YK
1613 ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc,
1614 desc_bytes(desc),
1615 DMA_TO_DEVICE);
71c65f7c 1616 if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) {
acdca31d
YK
1617 dev_err(jrdev, "unable to map shared descriptor\n");
1618 return -ENOMEM;
1619 }
1620
1621#ifdef DEBUG
514df281
AP
1622 print_hex_dump(KERN_ERR,
1623 "ablkcipher dec shdesc@"__stringify(__LINE__)": ",
acdca31d
YK
1624 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1625 desc_bytes(desc), 1);
1626#endif
7222d1a3
CV
1627 /* ablkcipher_givencrypt shared descriptor */
1628 desc = ctx->sh_desc_givenc;
1629
1630 init_sh_desc(desc, HDR_SHARE_SERIAL | HDR_SAVECTX);
1631 /* Skip if already shared */
1632 key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL |
1633 JUMP_COND_SHRD);
1634
1635 /* Load class1 key only */
1636 append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen,
1637 ctx->enckeylen, CLASS_1 |
1638 KEY_DEST_CLASS_REG);
1639
1640 /* Load Nonce into CONTEXT1 reg */
1641 if (is_rfc3686) {
1642 nonce = (u32 *)(key + keylen);
1643 append_load_imm_u32(desc, *nonce, LDST_CLASS_IND_CCB |
1644 LDST_SRCDST_BYTE_OUTFIFO | LDST_IMM);
1645 append_move(desc, MOVE_WAITCOMP |
1646 MOVE_SRC_OUTFIFO |
1647 MOVE_DEST_CLASS1CTX |
1648 (16 << MOVE_OFFSET_SHIFT) |
1649 (CTR_RFC3686_NONCE_SIZE << MOVE_LEN_SHIFT));
1650 }
1651 set_jump_tgt_here(desc, key_jump_cmd);
1652
1653 /* Generate IV */
1654 geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO |
1655 NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 |
1656 NFIFOENTRY_PTYPE_RND | (crt->ivsize << NFIFOENTRY_DLEN_SHIFT);
1657 append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB |
1658 LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM);
1659 append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO);
1660 append_move(desc, MOVE_WAITCOMP |
1661 MOVE_SRC_INFIFO |
1662 MOVE_DEST_CLASS1CTX |
1663 (crt->ivsize << MOVE_LEN_SHIFT) |
1664 (ctx1_iv_off << MOVE_OFFSET_SHIFT));
1665 append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO);
1666
1667 /* Copy generated IV to memory */
1668 append_seq_store(desc, crt->ivsize,
1669 LDST_SRCDST_BYTE_CONTEXT | LDST_CLASS_1_CCB |
1670 (ctx1_iv_off << LDST_OFFSET_SHIFT));
1671
1672 /* Load Counter into CONTEXT1 reg */
1673 if (is_rfc3686)
1674 append_load_imm_u32(desc, (u32)1, LDST_IMM |
1675 LDST_CLASS_1_CCB |
1676 LDST_SRCDST_BYTE_CONTEXT |
1677 ((ctx1_iv_off + CTR_RFC3686_IV_SIZE) <<
1678 LDST_OFFSET_SHIFT));
1679
1680 if (ctx1_iv_off)
1681 append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | JUMP_COND_NCP |
1682 (1 << JUMP_OFFSET_SHIFT));
1683
1684 /* Load operation */
1685 append_operation(desc, ctx->class1_alg_type |
1686 OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
1687
1688 /* Perform operation */
1689 ablkcipher_append_src_dst(desc);
1690
1691 ctx->sh_desc_givenc_dma = dma_map_single(jrdev, desc,
1692 desc_bytes(desc),
1693 DMA_TO_DEVICE);
1694 if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) {
1695 dev_err(jrdev, "unable to map shared descriptor\n");
1696 return -ENOMEM;
1697 }
1698#ifdef DEBUG
1699 print_hex_dump(KERN_ERR,
1700 "ablkcipher givenc shdesc@" __stringify(__LINE__) ": ",
1701 DUMP_PREFIX_ADDRESS, 16, 4, desc,
1702 desc_bytes(desc), 1);
1703#endif
acdca31d
YK
1704
1705 return ret;
1706}
1707
8e8ec596 1708/*
1acebad3
YK
1709 * aead_edesc - s/w-extended aead descriptor
1710 * @assoc_nents: number of segments in associated data (SPI+Seq) scatterlist
643b39b0 1711 * @assoc_chained: if source is chained
8e8ec596 1712 * @src_nents: number of segments in input scatterlist
643b39b0 1713 * @src_chained: if source is chained
8e8ec596 1714 * @dst_nents: number of segments in output scatterlist
643b39b0 1715 * @dst_chained: if destination is chained
1acebad3 1716 * @iv_dma: dma address of iv for checking continuity and link table
8e8ec596 1717 * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
a299c837
YK
1718 * @sec4_sg_bytes: length of dma mapped sec4_sg space
1719 * @sec4_sg_dma: bus physical mapped address of h/w link table
8e8ec596
KP
1720 * @hw_desc: the h/w job descriptor followed by any referenced link tables
1721 */
0e479300 1722struct aead_edesc {
8e8ec596 1723 int assoc_nents;
643b39b0 1724 bool assoc_chained;
8e8ec596 1725 int src_nents;
643b39b0 1726 bool src_chained;
8e8ec596 1727 int dst_nents;
643b39b0 1728 bool dst_chained;
1acebad3 1729 dma_addr_t iv_dma;
a299c837
YK
1730 int sec4_sg_bytes;
1731 dma_addr_t sec4_sg_dma;
1732 struct sec4_sg_entry *sec4_sg;
f2147b88 1733 u32 hw_desc[];
8e8ec596
KP
1734};
1735
acdca31d
YK
1736/*
1737 * ablkcipher_edesc - s/w-extended ablkcipher descriptor
1738 * @src_nents: number of segments in input scatterlist
643b39b0 1739 * @src_chained: if source is chained
acdca31d 1740 * @dst_nents: number of segments in output scatterlist
643b39b0 1741 * @dst_chained: if destination is chained
acdca31d
YK
1742 * @iv_dma: dma address of iv for checking continuity and link table
1743 * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE)
a299c837
YK
1744 * @sec4_sg_bytes: length of dma mapped sec4_sg space
1745 * @sec4_sg_dma: bus physical mapped address of h/w link table
acdca31d
YK
1746 * @hw_desc: the h/w job descriptor followed by any referenced link tables
1747 */
1748struct ablkcipher_edesc {
1749 int src_nents;
643b39b0 1750 bool src_chained;
acdca31d 1751 int dst_nents;
643b39b0 1752 bool dst_chained;
acdca31d 1753 dma_addr_t iv_dma;
a299c837
YK
1754 int sec4_sg_bytes;
1755 dma_addr_t sec4_sg_dma;
1756 struct sec4_sg_entry *sec4_sg;
acdca31d
YK
1757 u32 hw_desc[0];
1758};
1759
1acebad3 1760static void caam_unmap(struct device *dev, struct scatterlist *src,
643b39b0
YK
1761 struct scatterlist *dst, int src_nents,
1762 bool src_chained, int dst_nents, bool dst_chained,
a299c837
YK
1763 dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
1764 int sec4_sg_bytes)
8e8ec596 1765{
643b39b0
YK
1766 if (dst != src) {
1767 dma_unmap_sg_chained(dev, src, src_nents ? : 1, DMA_TO_DEVICE,
1768 src_chained);
1769 dma_unmap_sg_chained(dev, dst, dst_nents ? : 1, DMA_FROM_DEVICE,
1770 dst_chained);
8e8ec596 1771 } else {
643b39b0
YK
1772 dma_unmap_sg_chained(dev, src, src_nents ? : 1,
1773 DMA_BIDIRECTIONAL, src_chained);
8e8ec596
KP
1774 }
1775
1acebad3
YK
1776 if (iv_dma)
1777 dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE);
a299c837
YK
1778 if (sec4_sg_bytes)
1779 dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes,
8e8ec596
KP
1780 DMA_TO_DEVICE);
1781}
1782
1acebad3
YK
1783static void aead_unmap(struct device *dev,
1784 struct aead_edesc *edesc,
1785 struct aead_request *req)
f2147b88
HX
1786{
1787 caam_unmap(dev, req->src, req->dst,
1788 edesc->src_nents, edesc->src_chained, edesc->dst_nents,
1789 edesc->dst_chained, 0, 0,
1790 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
1791}
1792
acdca31d
YK
1793static void ablkcipher_unmap(struct device *dev,
1794 struct ablkcipher_edesc *edesc,
1795 struct ablkcipher_request *req)
1796{
1797 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1798 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1799
1800 caam_unmap(dev, req->src, req->dst,
643b39b0
YK
1801 edesc->src_nents, edesc->src_chained, edesc->dst_nents,
1802 edesc->dst_chained, edesc->iv_dma, ivsize,
1803 edesc->sec4_sg_dma, edesc->sec4_sg_bytes);
acdca31d
YK
1804}
1805
0e479300 1806static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
8e8ec596
KP
1807 void *context)
1808{
0e479300
YK
1809 struct aead_request *req = context;
1810 struct aead_edesc *edesc;
f2147b88
HX
1811
1812#ifdef DEBUG
1813 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1814#endif
1815
1816 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
1817
1818 if (err)
1819 caam_jr_strstatus(jrdev, err);
1820
1821 aead_unmap(jrdev, edesc, req);
1822
1823 kfree(edesc);
1824
1825 aead_request_complete(req, err);
1826}
1827
0e479300 1828static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
8e8ec596
KP
1829 void *context)
1830{
0e479300
YK
1831 struct aead_request *req = context;
1832 struct aead_edesc *edesc;
f2147b88
HX
1833
1834#ifdef DEBUG
1835 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1836#endif
1837
1838 edesc = container_of(desc, struct aead_edesc, hw_desc[0]);
1839
1840 if (err)
1841 caam_jr_strstatus(jrdev, err);
1842
1843 aead_unmap(jrdev, edesc, req);
1844
1845 /*
1846 * verify hw auth check passed else return -EBADMSG
1847 */
1848 if ((err & JRSTA_CCBERR_ERRID_MASK) == JRSTA_CCBERR_ERRID_ICVCHK)
1849 err = -EBADMSG;
1850
1851 kfree(edesc);
1852
1853 aead_request_complete(req, err);
1854}
1855
acdca31d
YK
1856static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1857 void *context)
1858{
1859 struct ablkcipher_request *req = context;
1860 struct ablkcipher_edesc *edesc;
1861#ifdef DEBUG
1862 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1863 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1864
1865 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1866#endif
1867
1868 edesc = (struct ablkcipher_edesc *)((char *)desc -
1869 offsetof(struct ablkcipher_edesc, hw_desc));
1870
fa9659cd
MV
1871 if (err)
1872 caam_jr_strstatus(jrdev, err);
acdca31d
YK
1873
1874#ifdef DEBUG
514df281 1875 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
acdca31d
YK
1876 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1877 edesc->src_nents > 1 ? 100 : ivsize, 1);
514df281 1878 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
acdca31d
YK
1879 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
1880 edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
1881#endif
1882
1883 ablkcipher_unmap(jrdev, edesc, req);
1884 kfree(edesc);
1885
1886 ablkcipher_request_complete(req, err);
1887}
1888
1889static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err,
1890 void *context)
1891{
1892 struct ablkcipher_request *req = context;
1893 struct ablkcipher_edesc *edesc;
1894#ifdef DEBUG
1895 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1896 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1897
1898 dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err);
1899#endif
1900
1901 edesc = (struct ablkcipher_edesc *)((char *)desc -
1902 offsetof(struct ablkcipher_edesc, hw_desc));
fa9659cd
MV
1903 if (err)
1904 caam_jr_strstatus(jrdev, err);
acdca31d
YK
1905
1906#ifdef DEBUG
514df281 1907 print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ",
acdca31d
YK
1908 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
1909 ivsize, 1);
514df281 1910 print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ",
acdca31d
YK
1911 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
1912 edesc->dst_nents > 1 ? 100 : req->nbytes, 1);
1913#endif
1914
1915 ablkcipher_unmap(jrdev, edesc, req);
1916 kfree(edesc);
1917
1918 ablkcipher_request_complete(req, err);
1919}
1920
f2147b88
HX
1921/*
1922 * Fill in aead job descriptor
1923 */
1924static void init_aead_job(struct aead_request *req,
1925 struct aead_edesc *edesc,
1926 bool all_contig, bool encrypt)
1927{
1928 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1929 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1930 int authsize = ctx->authsize;
1931 u32 *desc = edesc->hw_desc;
1932 u32 out_options, in_options;
1933 dma_addr_t dst_dma, src_dma;
1934 int len, sec4_sg_index = 0;
1935 dma_addr_t ptr;
1936 u32 *sh_desc;
1937
1938 sh_desc = encrypt ? ctx->sh_desc_enc : ctx->sh_desc_dec;
1939 ptr = encrypt ? ctx->sh_desc_enc_dma : ctx->sh_desc_dec_dma;
1940
1941 len = desc_len(sh_desc);
1942 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
1943
1944 if (all_contig) {
1945 src_dma = sg_dma_address(req->src);
1946 in_options = 0;
1947 } else {
1948 src_dma = edesc->sec4_sg_dma;
1949 sec4_sg_index += edesc->src_nents;
1950 in_options = LDST_SGF;
1951 }
1952
1953 append_seq_in_ptr(desc, src_dma, req->assoclen + req->cryptlen,
1954 in_options);
1955
1956 dst_dma = src_dma;
1957 out_options = in_options;
1958
1959 if (unlikely(req->src != req->dst)) {
1960 if (!edesc->dst_nents) {
1961 dst_dma = sg_dma_address(req->dst);
1962 } else {
1963 dst_dma = edesc->sec4_sg_dma +
1964 sec4_sg_index *
1965 sizeof(struct sec4_sg_entry);
1966 out_options = LDST_SGF;
1967 }
1968 }
1969
1970 if (encrypt)
1971 append_seq_out_ptr(desc, dst_dma,
1972 req->assoclen + req->cryptlen + authsize,
1973 out_options);
1974 else
1975 append_seq_out_ptr(desc, dst_dma,
1976 req->assoclen + req->cryptlen - authsize,
1977 out_options);
1978
1979 /* REG3 = assoclen */
1980 append_math_add_imm_u32(desc, REG3, ZERO, IMM, req->assoclen);
1981}
1982
1983static void init_gcm_job(struct aead_request *req,
1984 struct aead_edesc *edesc,
1985 bool all_contig, bool encrypt)
1986{
1987 struct crypto_aead *aead = crypto_aead_reqtfm(req);
1988 struct caam_ctx *ctx = crypto_aead_ctx(aead);
1989 unsigned int ivsize = crypto_aead_ivsize(aead);
1990 u32 *desc = edesc->hw_desc;
1991 bool generic_gcm = (ivsize == 12);
1992 unsigned int last;
1993
1994 init_aead_job(req, edesc, all_contig, encrypt);
1995
1996 /* BUG This should not be specific to generic GCM. */
1997 last = 0;
1998 if (encrypt && generic_gcm && !(req->assoclen + req->cryptlen))
1999 last = FIFOLD_TYPE_LAST1;
2000
2001 /* Read GCM IV */
2002 append_cmd(desc, CMD_FIFO_LOAD | FIFOLD_CLASS_CLASS1 | IMMEDIATE |
2003 FIFOLD_TYPE_IV | FIFOLD_TYPE_FLUSH1 | 12 | last);
2004 /* Append Salt */
2005 if (!generic_gcm)
2006 append_data(desc, ctx->key + ctx->enckeylen, 4);
2007 /* Append IV */
2008 append_data(desc, req->iv, ivsize);
2009 /* End of blank commands */
2010}
2011
479bcc7c
HX
2012static void init_authenc_job(struct aead_request *req,
2013 struct aead_edesc *edesc,
2014 bool all_contig, bool encrypt)
1acebad3
YK
2015{
2016 struct crypto_aead *aead = crypto_aead_reqtfm(req);
479bcc7c
HX
2017 struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
2018 struct caam_aead_alg, aead);
2019 unsigned int ivsize = crypto_aead_ivsize(aead);
1acebad3 2020 struct caam_ctx *ctx = crypto_aead_ctx(aead);
479bcc7c
HX
2021 const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) ==
2022 OP_ALG_AAI_CTR_MOD128);
2023 const bool is_rfc3686 = alg->caam.rfc3686;
1acebad3 2024 u32 *desc = edesc->hw_desc;
479bcc7c 2025 u32 ivoffset = 0;
8e8ec596 2026
479bcc7c
HX
2027 /*
2028 * AES-CTR needs to load IV in CONTEXT1 reg
2029 * at an offset of 128bits (16bytes)
2030 * CONTEXT1[255:128] = IV
2031 */
2032 if (ctr_mode)
2033 ivoffset = 16;
1acebad3 2034
479bcc7c
HX
2035 /*
2036 * RFC3686 specific:
2037 * CONTEXT1[255:128] = {NONCE, IV, COUNTER}
2038 */
2039 if (is_rfc3686)
2040 ivoffset = 16 + CTR_RFC3686_NONCE_SIZE;
8e8ec596 2041
479bcc7c 2042 init_aead_job(req, edesc, all_contig, encrypt);
1acebad3 2043
479bcc7c
HX
2044 if (ivsize && (is_rfc3686 || !(alg->caam.geniv && encrypt)))
2045 append_load_as_imm(desc, req->iv, ivsize,
2046 LDST_CLASS_1_CCB |
2047 LDST_SRCDST_BYTE_CONTEXT |
2048 (ivoffset << LDST_OFFSET_SHIFT));
8e8ec596
KP
2049}
2050
acdca31d
YK
2051/*
2052 * Fill in ablkcipher job descriptor
2053 */
2054static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr,
2055 struct ablkcipher_edesc *edesc,
2056 struct ablkcipher_request *req,
2057 bool iv_contig)
2058{
2059 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2060 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2061 u32 *desc = edesc->hw_desc;
2062 u32 out_options = 0, in_options;
2063 dma_addr_t dst_dma, src_dma;
a299c837 2064 int len, sec4_sg_index = 0;
acdca31d
YK
2065
2066#ifdef DEBUG
514df281 2067 print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ",
acdca31d
YK
2068 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2069 ivsize, 1);
514df281 2070 print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ",
acdca31d
YK
2071 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2072 edesc->src_nents ? 100 : req->nbytes, 1);
2073#endif
2074
2075 len = desc_len(sh_desc);
2076 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
2077
2078 if (iv_contig) {
2079 src_dma = edesc->iv_dma;
2080 in_options = 0;
2081 } else {
a299c837 2082 src_dma = edesc->sec4_sg_dma;
35b82e55 2083 sec4_sg_index += edesc->src_nents + 1;
acdca31d
YK
2084 in_options = LDST_SGF;
2085 }
2086 append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options);
2087
2088 if (likely(req->src == req->dst)) {
2089 if (!edesc->src_nents && iv_contig) {
2090 dst_dma = sg_dma_address(req->src);
2091 } else {
a299c837
YK
2092 dst_dma = edesc->sec4_sg_dma +
2093 sizeof(struct sec4_sg_entry);
acdca31d
YK
2094 out_options = LDST_SGF;
2095 }
2096 } else {
2097 if (!edesc->dst_nents) {
2098 dst_dma = sg_dma_address(req->dst);
2099 } else {
a299c837
YK
2100 dst_dma = edesc->sec4_sg_dma +
2101 sec4_sg_index * sizeof(struct sec4_sg_entry);
acdca31d
YK
2102 out_options = LDST_SGF;
2103 }
2104 }
2105 append_seq_out_ptr(desc, dst_dma, req->nbytes, out_options);
2106}
2107
7222d1a3
CV
2108/*
2109 * Fill in ablkcipher givencrypt job descriptor
2110 */
2111static void init_ablkcipher_giv_job(u32 *sh_desc, dma_addr_t ptr,
2112 struct ablkcipher_edesc *edesc,
2113 struct ablkcipher_request *req,
2114 bool iv_contig)
2115{
2116 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2117 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2118 u32 *desc = edesc->hw_desc;
2119 u32 out_options, in_options;
2120 dma_addr_t dst_dma, src_dma;
2121 int len, sec4_sg_index = 0;
2122
2123#ifdef DEBUG
2124 print_hex_dump(KERN_ERR, "presciv@" __stringify(__LINE__) ": ",
2125 DUMP_PREFIX_ADDRESS, 16, 4, req->info,
2126 ivsize, 1);
2127 print_hex_dump(KERN_ERR, "src @" __stringify(__LINE__) ": ",
2128 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
2129 edesc->src_nents ? 100 : req->nbytes, 1);
2130#endif
2131
2132 len = desc_len(sh_desc);
2133 init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE);
2134
2135 if (!edesc->src_nents) {
2136 src_dma = sg_dma_address(req->src);
2137 in_options = 0;
2138 } else {
2139 src_dma = edesc->sec4_sg_dma;
2140 sec4_sg_index += edesc->src_nents;
2141 in_options = LDST_SGF;
2142 }
2143 append_seq_in_ptr(desc, src_dma, req->nbytes, in_options);
2144
2145 if (iv_contig) {
2146 dst_dma = edesc->iv_dma;
2147 out_options = 0;
2148 } else {
2149 dst_dma = edesc->sec4_sg_dma +
2150 sec4_sg_index * sizeof(struct sec4_sg_entry);
2151 out_options = LDST_SGF;
2152 }
2153 append_seq_out_ptr(desc, dst_dma, req->nbytes + ivsize, out_options);
2154}
2155
8e8ec596 2156/*
1acebad3 2157 * allocate and map the aead extended descriptor
8e8ec596 2158 */
479bcc7c
HX
2159static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
2160 int desc_bytes, bool *all_contig_ptr,
2161 bool encrypt)
8e8ec596 2162{
0e479300 2163 struct crypto_aead *aead = crypto_aead_reqtfm(req);
8e8ec596
KP
2164 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2165 struct device *jrdev = ctx->jrdev;
1acebad3
YK
2166 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2167 CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC;
479bcc7c 2168 int src_nents, dst_nents = 0;
0e479300 2169 struct aead_edesc *edesc;
1acebad3
YK
2170 int sgc;
2171 bool all_contig = true;
479bcc7c 2172 bool src_chained = false, dst_chained = false;
a299c837 2173 int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes;
bbf9c893 2174 unsigned int authsize = ctx->authsize;
1acebad3 2175
bbf9c893 2176 if (unlikely(req->dst != req->src)) {
479bcc7c
HX
2177 src_nents = sg_count(req->src, req->assoclen + req->cryptlen,
2178 &src_chained);
bbf9c893 2179 dst_nents = sg_count(req->dst,
479bcc7c 2180 req->assoclen + req->cryptlen +
bbf9c893
HG
2181 (encrypt ? authsize : (-authsize)),
2182 &dst_chained);
2183 } else {
2184 src_nents = sg_count(req->src,
479bcc7c 2185 req->assoclen + req->cryptlen +
f2147b88
HX
2186 (encrypt ? authsize : 0),
2187 &src_chained);
2188 }
3ef8d945 2189
f2147b88
HX
2190 /* Check if data are contiguous. */
2191 all_contig = !src_nents;
3ef8d945 2192 if (!all_contig) {
1acebad3 2193 src_nents = src_nents ? : 1;
f2147b88 2194 sec4_sg_len = src_nents;
8e8ec596 2195 }
3ef8d945 2196
a299c837 2197 sec4_sg_len += dst_nents;
8e8ec596 2198
a299c837 2199 sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry);
8e8ec596
KP
2200
2201 /* allocate space for base edesc and hw desc commands, link tables */
dde20ae9
VM
2202 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2203 GFP_DMA | flags);
8e8ec596
KP
2204 if (!edesc) {
2205 dev_err(jrdev, "could not allocate extended descriptor\n");
2206 return ERR_PTR(-ENOMEM);
2207 }
2208
f2147b88
HX
2209 if (likely(req->src == req->dst)) {
2210 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2211 DMA_BIDIRECTIONAL, src_chained);
2212 if (unlikely(!sgc)) {
2213 dev_err(jrdev, "unable to map source\n");
2214 kfree(edesc);
2215 return ERR_PTR(-ENOMEM);
2216 }
2217 } else {
2218 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2219 DMA_TO_DEVICE, src_chained);
2220 if (unlikely(!sgc)) {
2221 dev_err(jrdev, "unable to map source\n");
2222 kfree(edesc);
2223 return ERR_PTR(-ENOMEM);
2224 }
2225
2226 sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1,
2227 DMA_FROM_DEVICE, dst_chained);
2228 if (unlikely(!sgc)) {
2229 dev_err(jrdev, "unable to map destination\n");
2230 dma_unmap_sg_chained(jrdev, req->src, src_nents ? : 1,
2231 DMA_TO_DEVICE, src_chained);
2232 kfree(edesc);
2233 return ERR_PTR(-ENOMEM);
2234 }
2235 }
2236
8e8ec596 2237 edesc->src_nents = src_nents;
643b39b0 2238 edesc->src_chained = src_chained;
8e8ec596 2239 edesc->dst_nents = dst_nents;
643b39b0 2240 edesc->dst_chained = dst_chained;
a299c837
YK
2241 edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) +
2242 desc_bytes;
1acebad3
YK
2243 *all_contig_ptr = all_contig;
2244
a299c837 2245 sec4_sg_index = 0;
1acebad3 2246 if (!all_contig) {
7793bda8 2247 sg_to_sec4_sg_last(req->src, src_nents,
f2147b88 2248 edesc->sec4_sg + sec4_sg_index, 0);
35b82e55 2249 sec4_sg_index += src_nents;
1acebad3
YK
2250 }
2251 if (dst_nents) {
a299c837
YK
2252 sg_to_sec4_sg_last(req->dst, dst_nents,
2253 edesc->sec4_sg + sec4_sg_index, 0);
1acebad3 2254 }
f2147b88
HX
2255
2256 if (!sec4_sg_bytes)
2257 return edesc;
2258
1da2be33
RG
2259 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2260 sec4_sg_bytes, DMA_TO_DEVICE);
ce572085
HG
2261 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2262 dev_err(jrdev, "unable to map S/G table\n");
f2147b88
HX
2263 aead_unmap(jrdev, edesc, req);
2264 kfree(edesc);
ce572085
HG
2265 return ERR_PTR(-ENOMEM);
2266 }
8e8ec596 2267
f2147b88
HX
2268 edesc->sec4_sg_bytes = sec4_sg_bytes;
2269
8e8ec596
KP
2270 return edesc;
2271}
2272
f2147b88 2273static int gcm_encrypt(struct aead_request *req)
8e8ec596 2274{
0e479300
YK
2275 struct aead_edesc *edesc;
2276 struct crypto_aead *aead = crypto_aead_reqtfm(req);
8e8ec596
KP
2277 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2278 struct device *jrdev = ctx->jrdev;
1acebad3 2279 bool all_contig;
8e8ec596 2280 u32 *desc;
1acebad3
YK
2281 int ret = 0;
2282
8e8ec596 2283 /* allocate extended descriptor */
f2147b88 2284 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, true);
8e8ec596
KP
2285 if (IS_ERR(edesc))
2286 return PTR_ERR(edesc);
2287
1acebad3 2288 /* Create and submit job descriptor */
f2147b88 2289 init_gcm_job(req, edesc, all_contig, true);
1acebad3 2290#ifdef DEBUG
514df281 2291 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1acebad3
YK
2292 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2293 desc_bytes(edesc->hw_desc), 1);
2294#endif
8e8ec596 2295
1acebad3
YK
2296 desc = edesc->hw_desc;
2297 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
2298 if (!ret) {
2299 ret = -EINPROGRESS;
2300 } else {
2301 aead_unmap(jrdev, edesc, req);
2302 kfree(edesc);
2303 }
8e8ec596 2304
1acebad3 2305 return ret;
8e8ec596
KP
2306}
2307
46218750
HX
2308static int ipsec_gcm_encrypt(struct aead_request *req)
2309{
2310 if (req->assoclen < 8)
2311 return -EINVAL;
2312
2313 return gcm_encrypt(req);
2314}
2315
479bcc7c 2316static int aead_encrypt(struct aead_request *req)
f2147b88
HX
2317{
2318 struct aead_edesc *edesc;
2319 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2320 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2321 struct device *jrdev = ctx->jrdev;
2322 bool all_contig;
2323 u32 *desc;
2324 int ret = 0;
2325
2326 /* allocate extended descriptor */
479bcc7c
HX
2327 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
2328 &all_contig, true);
f2147b88
HX
2329 if (IS_ERR(edesc))
2330 return PTR_ERR(edesc);
2331
2332 /* Create and submit job descriptor */
479bcc7c 2333 init_authenc_job(req, edesc, all_contig, true);
f2147b88
HX
2334#ifdef DEBUG
2335 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2336 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2337 desc_bytes(edesc->hw_desc), 1);
2338#endif
2339
2340 desc = edesc->hw_desc;
479bcc7c 2341 ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req);
f2147b88
HX
2342 if (!ret) {
2343 ret = -EINPROGRESS;
2344 } else {
479bcc7c 2345 aead_unmap(jrdev, edesc, req);
f2147b88
HX
2346 kfree(edesc);
2347 }
2348
2349 return ret;
2350}
2351
2352static int gcm_decrypt(struct aead_request *req)
2353{
2354 struct aead_edesc *edesc;
2355 struct crypto_aead *aead = crypto_aead_reqtfm(req);
2356 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2357 struct device *jrdev = ctx->jrdev;
2358 bool all_contig;
2359 u32 *desc;
2360 int ret = 0;
2361
2362 /* allocate extended descriptor */
2363 edesc = aead_edesc_alloc(req, GCM_DESC_JOB_IO_LEN, &all_contig, false);
2364 if (IS_ERR(edesc))
2365 return PTR_ERR(edesc);
2366
2367 /* Create and submit job descriptor*/
2368 init_gcm_job(req, edesc, all_contig, false);
2369#ifdef DEBUG
2370 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
2371 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2372 desc_bytes(edesc->hw_desc), 1);
2373#endif
2374
2375 desc = edesc->hw_desc;
2376 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
2377 if (!ret) {
2378 ret = -EINPROGRESS;
2379 } else {
2380 aead_unmap(jrdev, edesc, req);
2381 kfree(edesc);
2382 }
2383
2384 return ret;
2385}
2386
46218750
HX
2387static int ipsec_gcm_decrypt(struct aead_request *req)
2388{
2389 if (req->assoclen < 8)
2390 return -EINVAL;
2391
2392 return gcm_decrypt(req);
2393}
2394
479bcc7c 2395static int aead_decrypt(struct aead_request *req)
8e8ec596 2396{
1acebad3 2397 struct aead_edesc *edesc;
8e8ec596 2398 struct crypto_aead *aead = crypto_aead_reqtfm(req);
8e8ec596
KP
2399 struct caam_ctx *ctx = crypto_aead_ctx(aead);
2400 struct device *jrdev = ctx->jrdev;
1acebad3 2401 bool all_contig;
8e8ec596 2402 u32 *desc;
1acebad3 2403 int ret = 0;
8e8ec596
KP
2404
2405 /* allocate extended descriptor */
479bcc7c
HX
2406 edesc = aead_edesc_alloc(req, AUTHENC_DESC_JOB_IO_LEN,
2407 &all_contig, false);
8e8ec596
KP
2408 if (IS_ERR(edesc))
2409 return PTR_ERR(edesc);
2410
1acebad3 2411#ifdef DEBUG
514df281 2412 print_hex_dump(KERN_ERR, "dec src@"__stringify(__LINE__)": ",
1acebad3 2413 DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src),
479bcc7c 2414 req->assoclen + req->cryptlen, 1);
1acebad3
YK
2415#endif
2416
2417 /* Create and submit job descriptor*/
479bcc7c 2418 init_authenc_job(req, edesc, all_contig, false);
1acebad3 2419#ifdef DEBUG
514df281 2420 print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ",
1acebad3
YK
2421 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2422 desc_bytes(edesc->hw_desc), 1);
2423#endif
2424
8e8ec596 2425 desc = edesc->hw_desc;
479bcc7c 2426 ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req);
1acebad3
YK
2427 if (!ret) {
2428 ret = -EINPROGRESS;
2429 } else {
479bcc7c 2430 aead_unmap(jrdev, edesc, req);
1acebad3
YK
2431 kfree(edesc);
2432 }
8e8ec596 2433
1acebad3
YK
2434 return ret;
2435}
8e8ec596 2436
479bcc7c 2437static int aead_givdecrypt(struct aead_request *req)
8e8ec596 2438{
0e479300 2439 struct crypto_aead *aead = crypto_aead_reqtfm(req);
479bcc7c 2440 unsigned int ivsize = crypto_aead_ivsize(aead);
8e8ec596 2441
479bcc7c
HX
2442 if (req->cryptlen < ivsize)
2443 return -EINVAL;
8e8ec596 2444
479bcc7c
HX
2445 req->cryptlen -= ivsize;
2446 req->assoclen += ivsize;
8e8ec596 2447
479bcc7c 2448 return aead_decrypt(req);
ae4a825f
HG
2449}
2450
acdca31d
YK
2451/*
2452 * allocate and map the ablkcipher extended descriptor for ablkcipher
2453 */
2454static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
2455 *req, int desc_bytes,
2456 bool *iv_contig_out)
2457{
2458 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2459 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2460 struct device *jrdev = ctx->jrdev;
2461 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2462 CRYPTO_TFM_REQ_MAY_SLEEP)) ?
2463 GFP_KERNEL : GFP_ATOMIC;
a299c837 2464 int src_nents, dst_nents = 0, sec4_sg_bytes;
acdca31d
YK
2465 struct ablkcipher_edesc *edesc;
2466 dma_addr_t iv_dma = 0;
2467 bool iv_contig = false;
2468 int sgc;
2469 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
643b39b0 2470 bool src_chained = false, dst_chained = false;
a299c837 2471 int sec4_sg_index;
acdca31d 2472
643b39b0 2473 src_nents = sg_count(req->src, req->nbytes, &src_chained);
acdca31d 2474
643b39b0
YK
2475 if (req->dst != req->src)
2476 dst_nents = sg_count(req->dst, req->nbytes, &dst_chained);
acdca31d
YK
2477
2478 if (likely(req->src == req->dst)) {
643b39b0
YK
2479 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2480 DMA_BIDIRECTIONAL, src_chained);
acdca31d 2481 } else {
643b39b0
YK
2482 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2483 DMA_TO_DEVICE, src_chained);
2484 sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1,
2485 DMA_FROM_DEVICE, dst_chained);
acdca31d
YK
2486 }
2487
ce572085
HG
2488 iv_dma = dma_map_single(jrdev, req->info, ivsize, DMA_TO_DEVICE);
2489 if (dma_mapping_error(jrdev, iv_dma)) {
2490 dev_err(jrdev, "unable to map IV\n");
2491 return ERR_PTR(-ENOMEM);
2492 }
2493
acdca31d
YK
2494 /*
2495 * Check if iv can be contiguous with source and destination.
2496 * If so, include it. If not, create scatterlist.
2497 */
acdca31d
YK
2498 if (!src_nents && iv_dma + ivsize == sg_dma_address(req->src))
2499 iv_contig = true;
2500 else
2501 src_nents = src_nents ? : 1;
a299c837
YK
2502 sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
2503 sizeof(struct sec4_sg_entry);
acdca31d
YK
2504
2505 /* allocate space for base edesc and hw desc commands, link tables */
dde20ae9
VM
2506 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2507 GFP_DMA | flags);
acdca31d
YK
2508 if (!edesc) {
2509 dev_err(jrdev, "could not allocate extended descriptor\n");
2510 return ERR_PTR(-ENOMEM);
2511 }
2512
2513 edesc->src_nents = src_nents;
643b39b0 2514 edesc->src_chained = src_chained;
acdca31d 2515 edesc->dst_nents = dst_nents;
643b39b0 2516 edesc->dst_chained = dst_chained;
a299c837
YK
2517 edesc->sec4_sg_bytes = sec4_sg_bytes;
2518 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
2519 desc_bytes;
acdca31d 2520
a299c837 2521 sec4_sg_index = 0;
acdca31d 2522 if (!iv_contig) {
a299c837
YK
2523 dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0);
2524 sg_to_sec4_sg_last(req->src, src_nents,
2525 edesc->sec4_sg + 1, 0);
2526 sec4_sg_index += 1 + src_nents;
acdca31d
YK
2527 }
2528
643b39b0 2529 if (dst_nents) {
a299c837
YK
2530 sg_to_sec4_sg_last(req->dst, dst_nents,
2531 edesc->sec4_sg + sec4_sg_index, 0);
acdca31d
YK
2532 }
2533
a299c837
YK
2534 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2535 sec4_sg_bytes, DMA_TO_DEVICE);
ce572085
HG
2536 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2537 dev_err(jrdev, "unable to map S/G table\n");
2538 return ERR_PTR(-ENOMEM);
2539 }
2540
acdca31d
YK
2541 edesc->iv_dma = iv_dma;
2542
2543#ifdef DEBUG
514df281 2544 print_hex_dump(KERN_ERR, "ablkcipher sec4_sg@"__stringify(__LINE__)": ",
a299c837
YK
2545 DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
2546 sec4_sg_bytes, 1);
acdca31d
YK
2547#endif
2548
2549 *iv_contig_out = iv_contig;
2550 return edesc;
2551}
2552
2553static int ablkcipher_encrypt(struct ablkcipher_request *req)
2554{
2555 struct ablkcipher_edesc *edesc;
2556 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2557 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2558 struct device *jrdev = ctx->jrdev;
2559 bool iv_contig;
2560 u32 *desc;
2561 int ret = 0;
2562
2563 /* allocate extended descriptor */
2564 edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
2565 CAAM_CMD_SZ, &iv_contig);
2566 if (IS_ERR(edesc))
2567 return PTR_ERR(edesc);
2568
2569 /* Create and submit job descriptor*/
2570 init_ablkcipher_job(ctx->sh_desc_enc,
2571 ctx->sh_desc_enc_dma, edesc, req, iv_contig);
2572#ifdef DEBUG
514df281 2573 print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
acdca31d
YK
2574 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2575 desc_bytes(edesc->hw_desc), 1);
2576#endif
2577 desc = edesc->hw_desc;
2578 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
2579
2580 if (!ret) {
2581 ret = -EINPROGRESS;
2582 } else {
2583 ablkcipher_unmap(jrdev, edesc, req);
2584 kfree(edesc);
2585 }
2586
2587 return ret;
2588}
2589
2590static int ablkcipher_decrypt(struct ablkcipher_request *req)
2591{
2592 struct ablkcipher_edesc *edesc;
2593 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2594 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2595 struct device *jrdev = ctx->jrdev;
2596 bool iv_contig;
2597 u32 *desc;
2598 int ret = 0;
2599
2600 /* allocate extended descriptor */
2601 edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN *
2602 CAAM_CMD_SZ, &iv_contig);
2603 if (IS_ERR(edesc))
2604 return PTR_ERR(edesc);
2605
2606 /* Create and submit job descriptor*/
2607 init_ablkcipher_job(ctx->sh_desc_dec,
2608 ctx->sh_desc_dec_dma, edesc, req, iv_contig);
2609 desc = edesc->hw_desc;
2610#ifdef DEBUG
514df281 2611 print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ",
acdca31d
YK
2612 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2613 desc_bytes(edesc->hw_desc), 1);
2614#endif
2615
2616 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_decrypt_done, req);
2617 if (!ret) {
2618 ret = -EINPROGRESS;
2619 } else {
2620 ablkcipher_unmap(jrdev, edesc, req);
2621 kfree(edesc);
2622 }
2623
2624 return ret;
2625}
2626
7222d1a3
CV
2627/*
2628 * allocate and map the ablkcipher extended descriptor
2629 * for ablkcipher givencrypt
2630 */
2631static struct ablkcipher_edesc *ablkcipher_giv_edesc_alloc(
2632 struct skcipher_givcrypt_request *greq,
2633 int desc_bytes,
2634 bool *iv_contig_out)
2635{
2636 struct ablkcipher_request *req = &greq->creq;
2637 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2638 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2639 struct device *jrdev = ctx->jrdev;
2640 gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG |
2641 CRYPTO_TFM_REQ_MAY_SLEEP)) ?
2642 GFP_KERNEL : GFP_ATOMIC;
2643 int src_nents, dst_nents = 0, sec4_sg_bytes;
2644 struct ablkcipher_edesc *edesc;
2645 dma_addr_t iv_dma = 0;
2646 bool iv_contig = false;
2647 int sgc;
2648 int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
2649 bool src_chained = false, dst_chained = false;
2650 int sec4_sg_index;
2651
2652 src_nents = sg_count(req->src, req->nbytes, &src_chained);
2653
2654 if (unlikely(req->dst != req->src))
2655 dst_nents = sg_count(req->dst, req->nbytes, &dst_chained);
2656
2657 if (likely(req->src == req->dst)) {
2658 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2659 DMA_BIDIRECTIONAL, src_chained);
2660 } else {
2661 sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1,
2662 DMA_TO_DEVICE, src_chained);
2663 sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1,
2664 DMA_FROM_DEVICE, dst_chained);
2665 }
2666
2667 /*
2668 * Check if iv can be contiguous with source and destination.
2669 * If so, include it. If not, create scatterlist.
2670 */
2671 iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE);
2672 if (dma_mapping_error(jrdev, iv_dma)) {
2673 dev_err(jrdev, "unable to map IV\n");
2674 return ERR_PTR(-ENOMEM);
2675 }
2676
2677 if (!dst_nents && iv_dma + ivsize == sg_dma_address(req->dst))
2678 iv_contig = true;
2679 else
2680 dst_nents = dst_nents ? : 1;
2681 sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) *
2682 sizeof(struct sec4_sg_entry);
2683
2684 /* allocate space for base edesc and hw desc commands, link tables */
dde20ae9
VM
2685 edesc = kzalloc(sizeof(*edesc) + desc_bytes + sec4_sg_bytes,
2686 GFP_DMA | flags);
7222d1a3
CV
2687 if (!edesc) {
2688 dev_err(jrdev, "could not allocate extended descriptor\n");
2689 return ERR_PTR(-ENOMEM);
2690 }
2691
2692 edesc->src_nents = src_nents;
2693 edesc->src_chained = src_chained;
2694 edesc->dst_nents = dst_nents;
2695 edesc->dst_chained = dst_chained;
2696 edesc->sec4_sg_bytes = sec4_sg_bytes;
2697 edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) +
2698 desc_bytes;
2699
2700 sec4_sg_index = 0;
2701 if (src_nents) {
2702 sg_to_sec4_sg_last(req->src, src_nents, edesc->sec4_sg, 0);
2703 sec4_sg_index += src_nents;
2704 }
2705
2706 if (!iv_contig) {
2707 dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index,
2708 iv_dma, ivsize, 0);
2709 sec4_sg_index += 1;
2710 sg_to_sec4_sg_last(req->dst, dst_nents,
2711 edesc->sec4_sg + sec4_sg_index, 0);
2712 }
2713
2714 edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg,
2715 sec4_sg_bytes, DMA_TO_DEVICE);
2716 if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) {
2717 dev_err(jrdev, "unable to map S/G table\n");
2718 return ERR_PTR(-ENOMEM);
2719 }
2720 edesc->iv_dma = iv_dma;
2721
2722#ifdef DEBUG
2723 print_hex_dump(KERN_ERR,
2724 "ablkcipher sec4_sg@" __stringify(__LINE__) ": ",
2725 DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg,
2726 sec4_sg_bytes, 1);
2727#endif
2728
2729 *iv_contig_out = iv_contig;
2730 return edesc;
2731}
2732
2733static int ablkcipher_givencrypt(struct skcipher_givcrypt_request *creq)
2734{
2735 struct ablkcipher_request *req = &creq->creq;
2736 struct ablkcipher_edesc *edesc;
2737 struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
2738 struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
2739 struct device *jrdev = ctx->jrdev;
2740 bool iv_contig;
2741 u32 *desc;
2742 int ret = 0;
2743
2744 /* allocate extended descriptor */
2745 edesc = ablkcipher_giv_edesc_alloc(creq, DESC_JOB_IO_LEN *
2746 CAAM_CMD_SZ, &iv_contig);
2747 if (IS_ERR(edesc))
2748 return PTR_ERR(edesc);
2749
2750 /* Create and submit job descriptor*/
2751 init_ablkcipher_giv_job(ctx->sh_desc_givenc, ctx->sh_desc_givenc_dma,
2752 edesc, req, iv_contig);
2753#ifdef DEBUG
2754 print_hex_dump(KERN_ERR,
2755 "ablkcipher jobdesc@" __stringify(__LINE__) ": ",
2756 DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc,
2757 desc_bytes(edesc->hw_desc), 1);
2758#endif
2759 desc = edesc->hw_desc;
2760 ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req);
2761
2762 if (!ret) {
2763 ret = -EINPROGRESS;
2764 } else {
2765 ablkcipher_unmap(jrdev, edesc, req);
2766 kfree(edesc);
2767 }
2768
2769 return ret;
2770}
2771
885e9e2f 2772#define template_aead template_u.aead
acdca31d 2773#define template_ablkcipher template_u.ablkcipher
8e8ec596
KP
2774struct caam_alg_template {
2775 char name[CRYPTO_MAX_ALG_NAME];
2776 char driver_name[CRYPTO_MAX_ALG_NAME];
2777 unsigned int blocksize;
885e9e2f
YK
2778 u32 type;
2779 union {
2780 struct ablkcipher_alg ablkcipher;
885e9e2f 2781 } template_u;
8e8ec596
KP
2782 u32 class1_alg_type;
2783 u32 class2_alg_type;
2784 u32 alg_op;
2785};
2786
2787static struct caam_alg_template driver_algs[] = {
479bcc7c 2788 /* ablkcipher descriptor */
ae4a825f 2789 {
479bcc7c
HX
2790 .name = "cbc(aes)",
2791 .driver_name = "cbc-aes-caam",
2792 .blocksize = AES_BLOCK_SIZE,
2793 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2794 .template_ablkcipher = {
2795 .setkey = ablkcipher_setkey,
2796 .encrypt = ablkcipher_encrypt,
2797 .decrypt = ablkcipher_decrypt,
2798 .givencrypt = ablkcipher_givencrypt,
2799 .geniv = "<built-in>",
2800 .min_keysize = AES_MIN_KEY_SIZE,
2801 .max_keysize = AES_MAX_KEY_SIZE,
2802 .ivsize = AES_BLOCK_SIZE,
2803 },
2804 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
2805 },
2806 {
2807 .name = "cbc(des3_ede)",
2808 .driver_name = "cbc-3des-caam",
2809 .blocksize = DES3_EDE_BLOCK_SIZE,
2810 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2811 .template_ablkcipher = {
2812 .setkey = ablkcipher_setkey,
2813 .encrypt = ablkcipher_encrypt,
2814 .decrypt = ablkcipher_decrypt,
2815 .givencrypt = ablkcipher_givencrypt,
2816 .geniv = "<built-in>",
2817 .min_keysize = DES3_EDE_KEY_SIZE,
2818 .max_keysize = DES3_EDE_KEY_SIZE,
2819 .ivsize = DES3_EDE_BLOCK_SIZE,
2820 },
2821 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
2822 },
2823 {
2824 .name = "cbc(des)",
2825 .driver_name = "cbc-des-caam",
2826 .blocksize = DES_BLOCK_SIZE,
2827 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2828 .template_ablkcipher = {
2829 .setkey = ablkcipher_setkey,
2830 .encrypt = ablkcipher_encrypt,
2831 .decrypt = ablkcipher_decrypt,
2832 .givencrypt = ablkcipher_givencrypt,
2833 .geniv = "<built-in>",
2834 .min_keysize = DES_KEY_SIZE,
2835 .max_keysize = DES_KEY_SIZE,
2836 .ivsize = DES_BLOCK_SIZE,
2837 },
2838 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
2839 },
2840 {
2841 .name = "ctr(aes)",
2842 .driver_name = "ctr-aes-caam",
2843 .blocksize = 1,
2844 .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
2845 .template_ablkcipher = {
2846 .setkey = ablkcipher_setkey,
2847 .encrypt = ablkcipher_encrypt,
2848 .decrypt = ablkcipher_decrypt,
2849 .geniv = "chainiv",
2850 .min_keysize = AES_MIN_KEY_SIZE,
2851 .max_keysize = AES_MAX_KEY_SIZE,
2852 .ivsize = AES_BLOCK_SIZE,
2853 },
2854 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
2855 },
2856 {
2857 .name = "rfc3686(ctr(aes))",
2858 .driver_name = "rfc3686-ctr-aes-caam",
2859 .blocksize = 1,
2860 .type = CRYPTO_ALG_TYPE_GIVCIPHER,
2861 .template_ablkcipher = {
2862 .setkey = ablkcipher_setkey,
2863 .encrypt = ablkcipher_encrypt,
2864 .decrypt = ablkcipher_decrypt,
2865 .givencrypt = ablkcipher_givencrypt,
ae4a825f 2866 .geniv = "<built-in>",
479bcc7c
HX
2867 .min_keysize = AES_MIN_KEY_SIZE +
2868 CTR_RFC3686_NONCE_SIZE,
2869 .max_keysize = AES_MAX_KEY_SIZE +
2870 CTR_RFC3686_NONCE_SIZE,
2871 .ivsize = CTR_RFC3686_IV_SIZE,
2872 },
2873 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
2874 }
2875};
2876
2877static struct caam_aead_alg driver_aeads[] = {
2878 {
2879 .aead = {
2880 .base = {
2881 .cra_name = "rfc4106(gcm(aes))",
2882 .cra_driver_name = "rfc4106-gcm-aes-caam",
2883 .cra_blocksize = 1,
2884 },
2885 .setkey = rfc4106_setkey,
2886 .setauthsize = rfc4106_setauthsize,
2887 .encrypt = ipsec_gcm_encrypt,
2888 .decrypt = ipsec_gcm_decrypt,
2889 .ivsize = 8,
2890 .maxauthsize = AES_BLOCK_SIZE,
2891 },
2892 .caam = {
2893 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2894 },
2895 },
2896 {
2897 .aead = {
2898 .base = {
2899 .cra_name = "rfc4543(gcm(aes))",
2900 .cra_driver_name = "rfc4543-gcm-aes-caam",
2901 .cra_blocksize = 1,
2902 },
2903 .setkey = rfc4543_setkey,
2904 .setauthsize = rfc4543_setauthsize,
2905 .encrypt = ipsec_gcm_encrypt,
2906 .decrypt = ipsec_gcm_decrypt,
2907 .ivsize = 8,
2908 .maxauthsize = AES_BLOCK_SIZE,
2909 },
2910 .caam = {
2911 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2912 },
2913 },
2914 /* Galois Counter Mode */
2915 {
2916 .aead = {
2917 .base = {
2918 .cra_name = "gcm(aes)",
2919 .cra_driver_name = "gcm-aes-caam",
2920 .cra_blocksize = 1,
2921 },
2922 .setkey = gcm_setkey,
2923 .setauthsize = gcm_setauthsize,
2924 .encrypt = gcm_encrypt,
2925 .decrypt = gcm_decrypt,
2926 .ivsize = 12,
2927 .maxauthsize = AES_BLOCK_SIZE,
2928 },
2929 .caam = {
2930 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_GCM,
2931 },
2932 },
2933 /* single-pass ipsec_esp descriptor */
2934 {
2935 .aead = {
2936 .base = {
2937 .cra_name = "authenc(hmac(md5),"
2938 "ecb(cipher_null))",
2939 .cra_driver_name = "authenc-hmac-md5-"
2940 "ecb-cipher_null-caam",
2941 .cra_blocksize = NULL_BLOCK_SIZE,
2942 },
2943 .setkey = aead_setkey,
2944 .setauthsize = aead_setauthsize,
2945 .encrypt = aead_encrypt,
2946 .decrypt = aead_decrypt,
ae4a825f 2947 .ivsize = NULL_IV_SIZE,
479bcc7c
HX
2948 .maxauthsize = MD5_DIGEST_SIZE,
2949 },
2950 .caam = {
2951 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
2952 OP_ALG_AAI_HMAC_PRECOMP,
2953 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
2954 },
2955 },
2956 {
2957 .aead = {
2958 .base = {
2959 .cra_name = "authenc(hmac(sha1),"
2960 "ecb(cipher_null))",
2961 .cra_driver_name = "authenc-hmac-sha1-"
2962 "ecb-cipher_null-caam",
2963 .cra_blocksize = NULL_BLOCK_SIZE,
ae4a825f 2964 },
479bcc7c
HX
2965 .setkey = aead_setkey,
2966 .setauthsize = aead_setauthsize,
2967 .encrypt = aead_encrypt,
2968 .decrypt = aead_decrypt,
2969 .ivsize = NULL_IV_SIZE,
2970 .maxauthsize = SHA1_DIGEST_SIZE,
2971 },
2972 .caam = {
2973 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
2974 OP_ALG_AAI_HMAC_PRECOMP,
2975 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
2976 },
ae4a825f
HG
2977 },
2978 {
479bcc7c
HX
2979 .aead = {
2980 .base = {
2981 .cra_name = "authenc(hmac(sha224),"
2982 "ecb(cipher_null))",
2983 .cra_driver_name = "authenc-hmac-sha224-"
2984 "ecb-cipher_null-caam",
2985 .cra_blocksize = NULL_BLOCK_SIZE,
2986 },
ae4a825f
HG
2987 .setkey = aead_setkey,
2988 .setauthsize = aead_setauthsize,
479bcc7c
HX
2989 .encrypt = aead_encrypt,
2990 .decrypt = aead_decrypt,
ae4a825f
HG
2991 .ivsize = NULL_IV_SIZE,
2992 .maxauthsize = SHA224_DIGEST_SIZE,
479bcc7c
HX
2993 },
2994 .caam = {
2995 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
2996 OP_ALG_AAI_HMAC_PRECOMP,
2997 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
2998 },
ae4a825f
HG
2999 },
3000 {
479bcc7c
HX
3001 .aead = {
3002 .base = {
3003 .cra_name = "authenc(hmac(sha256),"
3004 "ecb(cipher_null))",
3005 .cra_driver_name = "authenc-hmac-sha256-"
3006 "ecb-cipher_null-caam",
3007 .cra_blocksize = NULL_BLOCK_SIZE,
3008 },
ae4a825f
HG
3009 .setkey = aead_setkey,
3010 .setauthsize = aead_setauthsize,
479bcc7c
HX
3011 .encrypt = aead_encrypt,
3012 .decrypt = aead_decrypt,
ae4a825f
HG
3013 .ivsize = NULL_IV_SIZE,
3014 .maxauthsize = SHA256_DIGEST_SIZE,
479bcc7c
HX
3015 },
3016 .caam = {
3017 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3018 OP_ALG_AAI_HMAC_PRECOMP,
3019 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3020 },
ae4a825f
HG
3021 },
3022 {
479bcc7c
HX
3023 .aead = {
3024 .base = {
3025 .cra_name = "authenc(hmac(sha384),"
3026 "ecb(cipher_null))",
3027 .cra_driver_name = "authenc-hmac-sha384-"
3028 "ecb-cipher_null-caam",
3029 .cra_blocksize = NULL_BLOCK_SIZE,
3030 },
ae4a825f
HG
3031 .setkey = aead_setkey,
3032 .setauthsize = aead_setauthsize,
479bcc7c
HX
3033 .encrypt = aead_encrypt,
3034 .decrypt = aead_decrypt,
ae4a825f
HG
3035 .ivsize = NULL_IV_SIZE,
3036 .maxauthsize = SHA384_DIGEST_SIZE,
479bcc7c
HX
3037 },
3038 .caam = {
3039 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3040 OP_ALG_AAI_HMAC_PRECOMP,
3041 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3042 },
ae4a825f
HG
3043 },
3044 {
479bcc7c
HX
3045 .aead = {
3046 .base = {
3047 .cra_name = "authenc(hmac(sha512),"
3048 "ecb(cipher_null))",
3049 .cra_driver_name = "authenc-hmac-sha512-"
3050 "ecb-cipher_null-caam",
3051 .cra_blocksize = NULL_BLOCK_SIZE,
3052 },
ae4a825f
HG
3053 .setkey = aead_setkey,
3054 .setauthsize = aead_setauthsize,
479bcc7c
HX
3055 .encrypt = aead_encrypt,
3056 .decrypt = aead_decrypt,
ae4a825f
HG
3057 .ivsize = NULL_IV_SIZE,
3058 .maxauthsize = SHA512_DIGEST_SIZE,
479bcc7c
HX
3059 },
3060 .caam = {
3061 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3062 OP_ALG_AAI_HMAC_PRECOMP,
3063 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3064 },
3065 },
3066 {
3067 .aead = {
3068 .base = {
3069 .cra_name = "authenc(hmac(md5),cbc(aes))",
3070 .cra_driver_name = "authenc-hmac-md5-"
3071 "cbc-aes-caam",
3072 .cra_blocksize = AES_BLOCK_SIZE,
ae4a825f 3073 },
479bcc7c
HX
3074 .setkey = aead_setkey,
3075 .setauthsize = aead_setauthsize,
3076 .encrypt = aead_encrypt,
3077 .decrypt = aead_decrypt,
3078 .ivsize = AES_BLOCK_SIZE,
3079 .maxauthsize = MD5_DIGEST_SIZE,
3080 },
3081 .caam = {
3082 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3083 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3084 OP_ALG_AAI_HMAC_PRECOMP,
3085 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3086 },
ae4a825f 3087 },
8b4d43a4 3088 {
479bcc7c
HX
3089 .aead = {
3090 .base = {
3091 .cra_name = "echainiv(authenc(hmac(md5),"
3092 "cbc(aes)))",
3093 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3094 "cbc-aes-caam",
3095 .cra_blocksize = AES_BLOCK_SIZE,
3096 },
8b4d43a4
KP
3097 .setkey = aead_setkey,
3098 .setauthsize = aead_setauthsize,
479bcc7c
HX
3099 .encrypt = aead_encrypt,
3100 .decrypt = aead_givdecrypt,
8b4d43a4
KP
3101 .ivsize = AES_BLOCK_SIZE,
3102 .maxauthsize = MD5_DIGEST_SIZE,
479bcc7c
HX
3103 },
3104 .caam = {
3105 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3106 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3107 OP_ALG_AAI_HMAC_PRECOMP,
3108 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3109 .geniv = true,
3110 },
3111 },
3112 {
3113 .aead = {
3114 .base = {
3115 .cra_name = "authenc(hmac(sha1),cbc(aes))",
3116 .cra_driver_name = "authenc-hmac-sha1-"
3117 "cbc-aes-caam",
3118 .cra_blocksize = AES_BLOCK_SIZE,
8b4d43a4 3119 },
479bcc7c
HX
3120 .setkey = aead_setkey,
3121 .setauthsize = aead_setauthsize,
3122 .encrypt = aead_encrypt,
3123 .decrypt = aead_decrypt,
3124 .ivsize = AES_BLOCK_SIZE,
3125 .maxauthsize = SHA1_DIGEST_SIZE,
3126 },
3127 .caam = {
3128 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3129 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3130 OP_ALG_AAI_HMAC_PRECOMP,
3131 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3132 },
8b4d43a4 3133 },
8e8ec596 3134 {
479bcc7c
HX
3135 .aead = {
3136 .base = {
3137 .cra_name = "echainiv(authenc(hmac(sha1),"
3138 "cbc(aes)))",
3139 .cra_driver_name = "echainiv-authenc-"
3140 "hmac-sha1-cbc-aes-caam",
3141 .cra_blocksize = AES_BLOCK_SIZE,
3142 },
0e479300
YK
3143 .setkey = aead_setkey,
3144 .setauthsize = aead_setauthsize,
479bcc7c
HX
3145 .encrypt = aead_encrypt,
3146 .decrypt = aead_givdecrypt,
8e8ec596
KP
3147 .ivsize = AES_BLOCK_SIZE,
3148 .maxauthsize = SHA1_DIGEST_SIZE,
479bcc7c
HX
3149 },
3150 .caam = {
3151 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3152 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3153 OP_ALG_AAI_HMAC_PRECOMP,
3154 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3155 .geniv = true,
3156 },
3157 },
3158 {
3159 .aead = {
3160 .base = {
3161 .cra_name = "authenc(hmac(sha224),cbc(aes))",
3162 .cra_driver_name = "authenc-hmac-sha224-"
3163 "cbc-aes-caam",
3164 .cra_blocksize = AES_BLOCK_SIZE,
8e8ec596 3165 },
479bcc7c
HX
3166 .setkey = aead_setkey,
3167 .setauthsize = aead_setauthsize,
3168 .encrypt = aead_encrypt,
3169 .decrypt = aead_decrypt,
3170 .ivsize = AES_BLOCK_SIZE,
3171 .maxauthsize = SHA224_DIGEST_SIZE,
3172 },
3173 .caam = {
3174 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3175 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3176 OP_ALG_AAI_HMAC_PRECOMP,
3177 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3178 },
8e8ec596 3179 },
e863f9cc 3180 {
479bcc7c
HX
3181 .aead = {
3182 .base = {
3183 .cra_name = "echainiv(authenc(hmac(sha224),"
3184 "cbc(aes)))",
3185 .cra_driver_name = "echainiv-authenc-"
3186 "hmac-sha224-cbc-aes-caam",
3187 .cra_blocksize = AES_BLOCK_SIZE,
3188 },
e863f9cc
HA
3189 .setkey = aead_setkey,
3190 .setauthsize = aead_setauthsize,
479bcc7c
HX
3191 .encrypt = aead_encrypt,
3192 .decrypt = aead_givdecrypt,
e863f9cc
HA
3193 .ivsize = AES_BLOCK_SIZE,
3194 .maxauthsize = SHA224_DIGEST_SIZE,
479bcc7c
HX
3195 },
3196 .caam = {
3197 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3198 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3199 OP_ALG_AAI_HMAC_PRECOMP,
3200 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3201 .geniv = true,
3202 },
3203 },
3204 {
3205 .aead = {
3206 .base = {
3207 .cra_name = "authenc(hmac(sha256),cbc(aes))",
3208 .cra_driver_name = "authenc-hmac-sha256-"
3209 "cbc-aes-caam",
3210 .cra_blocksize = AES_BLOCK_SIZE,
e863f9cc 3211 },
479bcc7c
HX
3212 .setkey = aead_setkey,
3213 .setauthsize = aead_setauthsize,
3214 .encrypt = aead_encrypt,
3215 .decrypt = aead_decrypt,
3216 .ivsize = AES_BLOCK_SIZE,
3217 .maxauthsize = SHA256_DIGEST_SIZE,
3218 },
3219 .caam = {
3220 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3221 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3222 OP_ALG_AAI_HMAC_PRECOMP,
3223 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3224 },
e863f9cc 3225 },
8e8ec596 3226 {
479bcc7c
HX
3227 .aead = {
3228 .base = {
3229 .cra_name = "echainiv(authenc(hmac(sha256),"
3230 "cbc(aes)))",
3231 .cra_driver_name = "echainiv-authenc-"
3232 "hmac-sha256-cbc-aes-caam",
3233 .cra_blocksize = AES_BLOCK_SIZE,
3234 },
3235 .setkey = aead_setkey,
3236 .setauthsize = aead_setauthsize,
3237 .encrypt = aead_encrypt,
3238 .decrypt = aead_givdecrypt,
3239 .ivsize = AES_BLOCK_SIZE,
3240 .maxauthsize = SHA256_DIGEST_SIZE,
3241 },
3242 .caam = {
3243 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3244 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3245 OP_ALG_AAI_HMAC_PRECOMP,
3246 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3247 .geniv = true,
3248 },
3249 },
3250 {
3251 .aead = {
3252 .base = {
3253 .cra_name = "authenc(hmac(sha384),cbc(aes))",
3254 .cra_driver_name = "authenc-hmac-sha384-"
3255 "cbc-aes-caam",
3256 .cra_blocksize = AES_BLOCK_SIZE,
3257 },
3258 .setkey = aead_setkey,
3259 .setauthsize = aead_setauthsize,
3260 .encrypt = aead_encrypt,
3261 .decrypt = aead_decrypt,
3262 .ivsize = AES_BLOCK_SIZE,
3263 .maxauthsize = SHA384_DIGEST_SIZE,
3264 },
3265 .caam = {
3266 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3267 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3268 OP_ALG_AAI_HMAC_PRECOMP,
3269 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3270 },
3271 },
3272 {
3273 .aead = {
3274 .base = {
3275 .cra_name = "echainiv(authenc(hmac(sha384),"
3276 "cbc(aes)))",
3277 .cra_driver_name = "echainiv-authenc-"
3278 "hmac-sha384-cbc-aes-caam",
3279 .cra_blocksize = AES_BLOCK_SIZE,
3280 },
0e479300
YK
3281 .setkey = aead_setkey,
3282 .setauthsize = aead_setauthsize,
479bcc7c
HX
3283 .encrypt = aead_encrypt,
3284 .decrypt = aead_givdecrypt,
8e8ec596 3285 .ivsize = AES_BLOCK_SIZE,
479bcc7c
HX
3286 .maxauthsize = SHA384_DIGEST_SIZE,
3287 },
3288 .caam = {
3289 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3290 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3291 OP_ALG_AAI_HMAC_PRECOMP,
3292 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3293 .geniv = true,
3294 },
8e8ec596 3295 },
e863f9cc 3296 {
479bcc7c
HX
3297 .aead = {
3298 .base = {
3299 .cra_name = "authenc(hmac(sha512),cbc(aes))",
3300 .cra_driver_name = "authenc-hmac-sha512-"
3301 "cbc-aes-caam",
3302 .cra_blocksize = AES_BLOCK_SIZE,
3303 },
e863f9cc
HA
3304 .setkey = aead_setkey,
3305 .setauthsize = aead_setauthsize,
479bcc7c
HX
3306 .encrypt = aead_encrypt,
3307 .decrypt = aead_decrypt,
e863f9cc 3308 .ivsize = AES_BLOCK_SIZE,
479bcc7c
HX
3309 .maxauthsize = SHA512_DIGEST_SIZE,
3310 },
3311 .caam = {
3312 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3313 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3314 OP_ALG_AAI_HMAC_PRECOMP,
3315 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3316 },
e863f9cc 3317 },
4427b1b4 3318 {
479bcc7c
HX
3319 .aead = {
3320 .base = {
3321 .cra_name = "echainiv(authenc(hmac(sha512),"
3322 "cbc(aes)))",
3323 .cra_driver_name = "echainiv-authenc-"
3324 "hmac-sha512-cbc-aes-caam",
3325 .cra_blocksize = AES_BLOCK_SIZE,
3326 },
0e479300
YK
3327 .setkey = aead_setkey,
3328 .setauthsize = aead_setauthsize,
479bcc7c
HX
3329 .encrypt = aead_encrypt,
3330 .decrypt = aead_givdecrypt,
4427b1b4
KP
3331 .ivsize = AES_BLOCK_SIZE,
3332 .maxauthsize = SHA512_DIGEST_SIZE,
479bcc7c
HX
3333 },
3334 .caam = {
3335 .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
3336 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3337 OP_ALG_AAI_HMAC_PRECOMP,
3338 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3339 .geniv = true,
3340 },
3341 },
3342 {
3343 .aead = {
3344 .base = {
3345 .cra_name = "authenc(hmac(md5),cbc(des3_ede))",
3346 .cra_driver_name = "authenc-hmac-md5-"
3347 "cbc-des3_ede-caam",
3348 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
4427b1b4 3349 },
479bcc7c
HX
3350 .setkey = aead_setkey,
3351 .setauthsize = aead_setauthsize,
3352 .encrypt = aead_encrypt,
3353 .decrypt = aead_decrypt,
3354 .ivsize = DES3_EDE_BLOCK_SIZE,
3355 .maxauthsize = MD5_DIGEST_SIZE,
3356 },
3357 .caam = {
3358 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3359 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3360 OP_ALG_AAI_HMAC_PRECOMP,
3361 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3362 }
4427b1b4 3363 },
8b4d43a4 3364 {
479bcc7c
HX
3365 .aead = {
3366 .base = {
3367 .cra_name = "echainiv(authenc(hmac(md5),"
3368 "cbc(des3_ede)))",
3369 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3370 "cbc-des3_ede-caam",
3371 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3372 },
8b4d43a4
KP
3373 .setkey = aead_setkey,
3374 .setauthsize = aead_setauthsize,
479bcc7c
HX
3375 .encrypt = aead_encrypt,
3376 .decrypt = aead_givdecrypt,
8b4d43a4
KP
3377 .ivsize = DES3_EDE_BLOCK_SIZE,
3378 .maxauthsize = MD5_DIGEST_SIZE,
479bcc7c
HX
3379 },
3380 .caam = {
3381 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3382 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3383 OP_ALG_AAI_HMAC_PRECOMP,
3384 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3385 .geniv = true,
3386 }
3387 },
3388 {
3389 .aead = {
3390 .base = {
3391 .cra_name = "authenc(hmac(sha1),"
3392 "cbc(des3_ede))",
3393 .cra_driver_name = "authenc-hmac-sha1-"
3394 "cbc-des3_ede-caam",
3395 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
8b4d43a4 3396 },
479bcc7c
HX
3397 .setkey = aead_setkey,
3398 .setauthsize = aead_setauthsize,
3399 .encrypt = aead_encrypt,
3400 .decrypt = aead_decrypt,
3401 .ivsize = DES3_EDE_BLOCK_SIZE,
3402 .maxauthsize = SHA1_DIGEST_SIZE,
3403 },
3404 .caam = {
3405 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3406 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3407 OP_ALG_AAI_HMAC_PRECOMP,
3408 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3409 },
8b4d43a4 3410 },
8e8ec596 3411 {
479bcc7c
HX
3412 .aead = {
3413 .base = {
3414 .cra_name = "echainiv(authenc(hmac(sha1),"
3415 "cbc(des3_ede)))",
3416 .cra_driver_name = "echainiv-authenc-"
3417 "hmac-sha1-"
3418 "cbc-des3_ede-caam",
3419 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3420 },
0e479300
YK
3421 .setkey = aead_setkey,
3422 .setauthsize = aead_setauthsize,
479bcc7c
HX
3423 .encrypt = aead_encrypt,
3424 .decrypt = aead_givdecrypt,
8e8ec596
KP
3425 .ivsize = DES3_EDE_BLOCK_SIZE,
3426 .maxauthsize = SHA1_DIGEST_SIZE,
479bcc7c
HX
3427 },
3428 .caam = {
3429 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3430 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3431 OP_ALG_AAI_HMAC_PRECOMP,
3432 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3433 .geniv = true,
3434 },
3435 },
3436 {
3437 .aead = {
3438 .base = {
3439 .cra_name = "authenc(hmac(sha224),"
3440 "cbc(des3_ede))",
3441 .cra_driver_name = "authenc-hmac-sha224-"
3442 "cbc-des3_ede-caam",
3443 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
8e8ec596 3444 },
479bcc7c
HX
3445 .setkey = aead_setkey,
3446 .setauthsize = aead_setauthsize,
3447 .encrypt = aead_encrypt,
3448 .decrypt = aead_decrypt,
3449 .ivsize = DES3_EDE_BLOCK_SIZE,
3450 .maxauthsize = SHA224_DIGEST_SIZE,
3451 },
3452 .caam = {
3453 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3454 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3455 OP_ALG_AAI_HMAC_PRECOMP,
3456 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3457 },
8e8ec596 3458 },
e863f9cc 3459 {
479bcc7c
HX
3460 .aead = {
3461 .base = {
3462 .cra_name = "echainiv(authenc(hmac(sha224),"
3463 "cbc(des3_ede)))",
3464 .cra_driver_name = "echainiv-authenc-"
3465 "hmac-sha224-"
3466 "cbc-des3_ede-caam",
3467 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3468 },
e863f9cc
HA
3469 .setkey = aead_setkey,
3470 .setauthsize = aead_setauthsize,
479bcc7c
HX
3471 .encrypt = aead_encrypt,
3472 .decrypt = aead_givdecrypt,
e863f9cc
HA
3473 .ivsize = DES3_EDE_BLOCK_SIZE,
3474 .maxauthsize = SHA224_DIGEST_SIZE,
479bcc7c
HX
3475 },
3476 .caam = {
3477 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3478 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3479 OP_ALG_AAI_HMAC_PRECOMP,
3480 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3481 .geniv = true,
3482 },
3483 },
3484 {
3485 .aead = {
3486 .base = {
3487 .cra_name = "authenc(hmac(sha256),"
3488 "cbc(des3_ede))",
3489 .cra_driver_name = "authenc-hmac-sha256-"
3490 "cbc-des3_ede-caam",
3491 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
e863f9cc 3492 },
479bcc7c
HX
3493 .setkey = aead_setkey,
3494 .setauthsize = aead_setauthsize,
3495 .encrypt = aead_encrypt,
3496 .decrypt = aead_decrypt,
3497 .ivsize = DES3_EDE_BLOCK_SIZE,
3498 .maxauthsize = SHA256_DIGEST_SIZE,
3499 },
3500 .caam = {
3501 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3502 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3503 OP_ALG_AAI_HMAC_PRECOMP,
3504 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3505 },
e863f9cc 3506 },
8e8ec596 3507 {
479bcc7c
HX
3508 .aead = {
3509 .base = {
3510 .cra_name = "echainiv(authenc(hmac(sha256),"
3511 "cbc(des3_ede)))",
3512 .cra_driver_name = "echainiv-authenc-"
3513 "hmac-sha256-"
3514 "cbc-des3_ede-caam",
3515 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3516 },
0e479300
YK
3517 .setkey = aead_setkey,
3518 .setauthsize = aead_setauthsize,
479bcc7c
HX
3519 .encrypt = aead_encrypt,
3520 .decrypt = aead_givdecrypt,
8e8ec596
KP
3521 .ivsize = DES3_EDE_BLOCK_SIZE,
3522 .maxauthsize = SHA256_DIGEST_SIZE,
479bcc7c
HX
3523 },
3524 .caam = {
3525 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3526 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3527 OP_ALG_AAI_HMAC_PRECOMP,
3528 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3529 .geniv = true,
3530 },
3531 },
3532 {
3533 .aead = {
3534 .base = {
3535 .cra_name = "authenc(hmac(sha384),"
3536 "cbc(des3_ede))",
3537 .cra_driver_name = "authenc-hmac-sha384-"
3538 "cbc-des3_ede-caam",
3539 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
8e8ec596 3540 },
479bcc7c
HX
3541 .setkey = aead_setkey,
3542 .setauthsize = aead_setauthsize,
3543 .encrypt = aead_encrypt,
3544 .decrypt = aead_decrypt,
3545 .ivsize = DES3_EDE_BLOCK_SIZE,
3546 .maxauthsize = SHA384_DIGEST_SIZE,
3547 },
3548 .caam = {
3549 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3550 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3551 OP_ALG_AAI_HMAC_PRECOMP,
3552 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3553 },
8e8ec596 3554 },
e863f9cc 3555 {
479bcc7c
HX
3556 .aead = {
3557 .base = {
3558 .cra_name = "echainiv(authenc(hmac(sha384),"
3559 "cbc(des3_ede)))",
3560 .cra_driver_name = "echainiv-authenc-"
3561 "hmac-sha384-"
3562 "cbc-des3_ede-caam",
3563 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3564 },
e863f9cc
HA
3565 .setkey = aead_setkey,
3566 .setauthsize = aead_setauthsize,
479bcc7c
HX
3567 .encrypt = aead_encrypt,
3568 .decrypt = aead_givdecrypt,
e863f9cc
HA
3569 .ivsize = DES3_EDE_BLOCK_SIZE,
3570 .maxauthsize = SHA384_DIGEST_SIZE,
479bcc7c
HX
3571 },
3572 .caam = {
3573 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3574 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3575 OP_ALG_AAI_HMAC_PRECOMP,
3576 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3577 .geniv = true,
3578 },
3579 },
3580 {
3581 .aead = {
3582 .base = {
3583 .cra_name = "authenc(hmac(sha512),"
3584 "cbc(des3_ede))",
3585 .cra_driver_name = "authenc-hmac-sha512-"
3586 "cbc-des3_ede-caam",
3587 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
e863f9cc 3588 },
479bcc7c
HX
3589 .setkey = aead_setkey,
3590 .setauthsize = aead_setauthsize,
3591 .encrypt = aead_encrypt,
3592 .decrypt = aead_decrypt,
3593 .ivsize = DES3_EDE_BLOCK_SIZE,
3594 .maxauthsize = SHA512_DIGEST_SIZE,
3595 },
3596 .caam = {
3597 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3598 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3599 OP_ALG_AAI_HMAC_PRECOMP,
3600 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3601 },
e863f9cc 3602 },
4427b1b4 3603 {
479bcc7c
HX
3604 .aead = {
3605 .base = {
3606 .cra_name = "echainiv(authenc(hmac(sha512),"
3607 "cbc(des3_ede)))",
3608 .cra_driver_name = "echainiv-authenc-"
3609 "hmac-sha512-"
3610 "cbc-des3_ede-caam",
3611 .cra_blocksize = DES3_EDE_BLOCK_SIZE,
3612 },
0e479300
YK
3613 .setkey = aead_setkey,
3614 .setauthsize = aead_setauthsize,
479bcc7c
HX
3615 .encrypt = aead_encrypt,
3616 .decrypt = aead_givdecrypt,
4427b1b4
KP
3617 .ivsize = DES3_EDE_BLOCK_SIZE,
3618 .maxauthsize = SHA512_DIGEST_SIZE,
479bcc7c
HX
3619 },
3620 .caam = {
3621 .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
3622 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3623 OP_ALG_AAI_HMAC_PRECOMP,
3624 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3625 .geniv = true,
3626 },
3627 },
3628 {
3629 .aead = {
3630 .base = {
3631 .cra_name = "authenc(hmac(md5),cbc(des))",
3632 .cra_driver_name = "authenc-hmac-md5-"
3633 "cbc-des-caam",
3634 .cra_blocksize = DES_BLOCK_SIZE,
4427b1b4 3635 },
479bcc7c
HX
3636 .setkey = aead_setkey,
3637 .setauthsize = aead_setauthsize,
3638 .encrypt = aead_encrypt,
3639 .decrypt = aead_decrypt,
3640 .ivsize = DES_BLOCK_SIZE,
3641 .maxauthsize = MD5_DIGEST_SIZE,
3642 },
3643 .caam = {
3644 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3645 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3646 OP_ALG_AAI_HMAC_PRECOMP,
3647 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3648 },
4427b1b4 3649 },
8b4d43a4 3650 {
479bcc7c
HX
3651 .aead = {
3652 .base = {
3653 .cra_name = "echainiv(authenc(hmac(md5),"
3654 "cbc(des)))",
3655 .cra_driver_name = "echainiv-authenc-hmac-md5-"
3656 "cbc-des-caam",
3657 .cra_blocksize = DES_BLOCK_SIZE,
3658 },
8b4d43a4
KP
3659 .setkey = aead_setkey,
3660 .setauthsize = aead_setauthsize,
479bcc7c
HX
3661 .encrypt = aead_encrypt,
3662 .decrypt = aead_givdecrypt,
8b4d43a4
KP
3663 .ivsize = DES_BLOCK_SIZE,
3664 .maxauthsize = MD5_DIGEST_SIZE,
479bcc7c
HX
3665 },
3666 .caam = {
3667 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3668 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3669 OP_ALG_AAI_HMAC_PRECOMP,
3670 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3671 .geniv = true,
3672 },
3673 },
3674 {
3675 .aead = {
3676 .base = {
3677 .cra_name = "authenc(hmac(sha1),cbc(des))",
3678 .cra_driver_name = "authenc-hmac-sha1-"
3679 "cbc-des-caam",
3680 .cra_blocksize = DES_BLOCK_SIZE,
8b4d43a4 3681 },
479bcc7c
HX
3682 .setkey = aead_setkey,
3683 .setauthsize = aead_setauthsize,
3684 .encrypt = aead_encrypt,
3685 .decrypt = aead_decrypt,
3686 .ivsize = DES_BLOCK_SIZE,
3687 .maxauthsize = SHA1_DIGEST_SIZE,
3688 },
3689 .caam = {
3690 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3691 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3692 OP_ALG_AAI_HMAC_PRECOMP,
3693 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3694 },
8b4d43a4 3695 },
8e8ec596 3696 {
479bcc7c
HX
3697 .aead = {
3698 .base = {
3699 .cra_name = "echainiv(authenc(hmac(sha1),"
3700 "cbc(des)))",
3701 .cra_driver_name = "echainiv-authenc-"
3702 "hmac-sha1-cbc-des-caam",
3703 .cra_blocksize = DES_BLOCK_SIZE,
3704 },
0e479300
YK
3705 .setkey = aead_setkey,
3706 .setauthsize = aead_setauthsize,
479bcc7c
HX
3707 .encrypt = aead_encrypt,
3708 .decrypt = aead_givdecrypt,
8e8ec596
KP
3709 .ivsize = DES_BLOCK_SIZE,
3710 .maxauthsize = SHA1_DIGEST_SIZE,
479bcc7c
HX
3711 },
3712 .caam = {
3713 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3714 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3715 OP_ALG_AAI_HMAC_PRECOMP,
3716 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3717 .geniv = true,
3718 },
3719 },
3720 {
3721 .aead = {
3722 .base = {
3723 .cra_name = "authenc(hmac(sha224),cbc(des))",
3724 .cra_driver_name = "authenc-hmac-sha224-"
3725 "cbc-des-caam",
3726 .cra_blocksize = DES_BLOCK_SIZE,
8e8ec596 3727 },
479bcc7c
HX
3728 .setkey = aead_setkey,
3729 .setauthsize = aead_setauthsize,
3730 .encrypt = aead_encrypt,
3731 .decrypt = aead_decrypt,
3732 .ivsize = DES_BLOCK_SIZE,
3733 .maxauthsize = SHA224_DIGEST_SIZE,
3734 },
3735 .caam = {
3736 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3737 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3738 OP_ALG_AAI_HMAC_PRECOMP,
3739 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3740 },
8e8ec596 3741 },
e863f9cc 3742 {
479bcc7c
HX
3743 .aead = {
3744 .base = {
3745 .cra_name = "echainiv(authenc(hmac(sha224),"
3746 "cbc(des)))",
3747 .cra_driver_name = "echainiv-authenc-"
3748 "hmac-sha224-cbc-des-caam",
3749 .cra_blocksize = DES_BLOCK_SIZE,
3750 },
e863f9cc
HA
3751 .setkey = aead_setkey,
3752 .setauthsize = aead_setauthsize,
479bcc7c
HX
3753 .encrypt = aead_encrypt,
3754 .decrypt = aead_givdecrypt,
e863f9cc
HA
3755 .ivsize = DES_BLOCK_SIZE,
3756 .maxauthsize = SHA224_DIGEST_SIZE,
479bcc7c
HX
3757 },
3758 .caam = {
3759 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3760 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
3761 OP_ALG_AAI_HMAC_PRECOMP,
3762 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
3763 .geniv = true,
3764 },
3765 },
3766 {
3767 .aead = {
3768 .base = {
3769 .cra_name = "authenc(hmac(sha256),cbc(des))",
3770 .cra_driver_name = "authenc-hmac-sha256-"
3771 "cbc-des-caam",
3772 .cra_blocksize = DES_BLOCK_SIZE,
e863f9cc 3773 },
479bcc7c
HX
3774 .setkey = aead_setkey,
3775 .setauthsize = aead_setauthsize,
3776 .encrypt = aead_encrypt,
3777 .decrypt = aead_decrypt,
3778 .ivsize = DES_BLOCK_SIZE,
3779 .maxauthsize = SHA256_DIGEST_SIZE,
3780 },
3781 .caam = {
3782 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3783 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3784 OP_ALG_AAI_HMAC_PRECOMP,
3785 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3786 },
e863f9cc 3787 },
8e8ec596 3788 {
479bcc7c
HX
3789 .aead = {
3790 .base = {
3791 .cra_name = "echainiv(authenc(hmac(sha256),"
3792 "cbc(des)))",
3793 .cra_driver_name = "echainiv-authenc-"
3794 "hmac-sha256-cbc-des-caam",
3795 .cra_blocksize = DES_BLOCK_SIZE,
3796 },
0e479300
YK
3797 .setkey = aead_setkey,
3798 .setauthsize = aead_setauthsize,
479bcc7c
HX
3799 .encrypt = aead_encrypt,
3800 .decrypt = aead_givdecrypt,
8e8ec596
KP
3801 .ivsize = DES_BLOCK_SIZE,
3802 .maxauthsize = SHA256_DIGEST_SIZE,
479bcc7c
HX
3803 },
3804 .caam = {
3805 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3806 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
3807 OP_ALG_AAI_HMAC_PRECOMP,
3808 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
3809 .geniv = true,
3810 },
3811 },
3812 {
3813 .aead = {
3814 .base = {
3815 .cra_name = "authenc(hmac(sha384),cbc(des))",
3816 .cra_driver_name = "authenc-hmac-sha384-"
3817 "cbc-des-caam",
3818 .cra_blocksize = DES_BLOCK_SIZE,
8e8ec596 3819 },
479bcc7c
HX
3820 .setkey = aead_setkey,
3821 .setauthsize = aead_setauthsize,
3822 .encrypt = aead_encrypt,
3823 .decrypt = aead_decrypt,
3824 .ivsize = DES_BLOCK_SIZE,
3825 .maxauthsize = SHA384_DIGEST_SIZE,
3826 },
3827 .caam = {
3828 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3829 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3830 OP_ALG_AAI_HMAC_PRECOMP,
3831 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3832 },
8e8ec596 3833 },
e863f9cc 3834 {
479bcc7c
HX
3835 .aead = {
3836 .base = {
3837 .cra_name = "echainiv(authenc(hmac(sha384),"
3838 "cbc(des)))",
3839 .cra_driver_name = "echainiv-authenc-"
3840 "hmac-sha384-cbc-des-caam",
3841 .cra_blocksize = DES_BLOCK_SIZE,
3842 },
e863f9cc
HA
3843 .setkey = aead_setkey,
3844 .setauthsize = aead_setauthsize,
479bcc7c
HX
3845 .encrypt = aead_encrypt,
3846 .decrypt = aead_givdecrypt,
e863f9cc
HA
3847 .ivsize = DES_BLOCK_SIZE,
3848 .maxauthsize = SHA384_DIGEST_SIZE,
479bcc7c
HX
3849 },
3850 .caam = {
3851 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3852 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
3853 OP_ALG_AAI_HMAC_PRECOMP,
3854 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
3855 .geniv = true,
3856 },
3857 },
3858 {
3859 .aead = {
3860 .base = {
3861 .cra_name = "authenc(hmac(sha512),cbc(des))",
3862 .cra_driver_name = "authenc-hmac-sha512-"
3863 "cbc-des-caam",
3864 .cra_blocksize = DES_BLOCK_SIZE,
e863f9cc 3865 },
479bcc7c
HX
3866 .setkey = aead_setkey,
3867 .setauthsize = aead_setauthsize,
3868 .encrypt = aead_encrypt,
3869 .decrypt = aead_decrypt,
3870 .ivsize = DES_BLOCK_SIZE,
3871 .maxauthsize = SHA512_DIGEST_SIZE,
3872 },
3873 .caam = {
3874 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3875 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3876 OP_ALG_AAI_HMAC_PRECOMP,
3877 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3878 },
e863f9cc 3879 },
4427b1b4 3880 {
479bcc7c
HX
3881 .aead = {
3882 .base = {
3883 .cra_name = "echainiv(authenc(hmac(sha512),"
3884 "cbc(des)))",
3885 .cra_driver_name = "echainiv-authenc-"
3886 "hmac-sha512-cbc-des-caam",
3887 .cra_blocksize = DES_BLOCK_SIZE,
3888 },
0e479300
YK
3889 .setkey = aead_setkey,
3890 .setauthsize = aead_setauthsize,
479bcc7c
HX
3891 .encrypt = aead_encrypt,
3892 .decrypt = aead_givdecrypt,
4427b1b4
KP
3893 .ivsize = DES_BLOCK_SIZE,
3894 .maxauthsize = SHA512_DIGEST_SIZE,
479bcc7c
HX
3895 },
3896 .caam = {
3897 .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
3898 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
3899 OP_ALG_AAI_HMAC_PRECOMP,
3900 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
3901 .geniv = true,
3902 },
4427b1b4 3903 },
daebc465 3904 {
479bcc7c
HX
3905 .aead = {
3906 .base = {
3907 .cra_name = "authenc(hmac(md5),"
3908 "rfc3686(ctr(aes)))",
3909 .cra_driver_name = "authenc-hmac-md5-"
3910 "rfc3686-ctr-aes-caam",
3911 .cra_blocksize = 1,
3912 },
daebc465
CV
3913 .setkey = aead_setkey,
3914 .setauthsize = aead_setauthsize,
479bcc7c
HX
3915 .encrypt = aead_encrypt,
3916 .decrypt = aead_decrypt,
daebc465
CV
3917 .ivsize = CTR_RFC3686_IV_SIZE,
3918 .maxauthsize = MD5_DIGEST_SIZE,
479bcc7c
HX
3919 },
3920 .caam = {
3921 .class1_alg_type = OP_ALG_ALGSEL_AES |
3922 OP_ALG_AAI_CTR_MOD128,
3923 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3924 OP_ALG_AAI_HMAC_PRECOMP,
3925 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3926 .rfc3686 = true,
3927 },
daebc465
CV
3928 },
3929 {
479bcc7c
HX
3930 .aead = {
3931 .base = {
3932 .cra_name = "seqiv(authenc("
3933 "hmac(md5),rfc3686(ctr(aes))))",
3934 .cra_driver_name = "seqiv-authenc-hmac-md5-"
3935 "rfc3686-ctr-aes-caam",
3936 .cra_blocksize = 1,
3937 },
daebc465
CV
3938 .setkey = aead_setkey,
3939 .setauthsize = aead_setauthsize,
479bcc7c
HX
3940 .encrypt = aead_encrypt,
3941 .decrypt = aead_givdecrypt,
daebc465 3942 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
3943 .maxauthsize = MD5_DIGEST_SIZE,
3944 },
3945 .caam = {
3946 .class1_alg_type = OP_ALG_ALGSEL_AES |
3947 OP_ALG_AAI_CTR_MOD128,
3948 .class2_alg_type = OP_ALG_ALGSEL_MD5 |
3949 OP_ALG_AAI_HMAC_PRECOMP,
3950 .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC,
3951 .rfc3686 = true,
3952 .geniv = true,
3953 },
daebc465
CV
3954 },
3955 {
479bcc7c
HX
3956 .aead = {
3957 .base = {
3958 .cra_name = "authenc(hmac(sha1),"
3959 "rfc3686(ctr(aes)))",
3960 .cra_driver_name = "authenc-hmac-sha1-"
3961 "rfc3686-ctr-aes-caam",
3962 .cra_blocksize = 1,
3963 },
daebc465
CV
3964 .setkey = aead_setkey,
3965 .setauthsize = aead_setauthsize,
479bcc7c
HX
3966 .encrypt = aead_encrypt,
3967 .decrypt = aead_decrypt,
daebc465 3968 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
3969 .maxauthsize = SHA1_DIGEST_SIZE,
3970 },
3971 .caam = {
3972 .class1_alg_type = OP_ALG_ALGSEL_AES |
3973 OP_ALG_AAI_CTR_MOD128,
3974 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
3975 OP_ALG_AAI_HMAC_PRECOMP,
3976 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
3977 .rfc3686 = true,
3978 },
daebc465
CV
3979 },
3980 {
479bcc7c
HX
3981 .aead = {
3982 .base = {
3983 .cra_name = "seqiv(authenc("
3984 "hmac(sha1),rfc3686(ctr(aes))))",
3985 .cra_driver_name = "seqiv-authenc-hmac-sha1-"
3986 "rfc3686-ctr-aes-caam",
3987 .cra_blocksize = 1,
3988 },
daebc465
CV
3989 .setkey = aead_setkey,
3990 .setauthsize = aead_setauthsize,
479bcc7c
HX
3991 .encrypt = aead_encrypt,
3992 .decrypt = aead_givdecrypt,
daebc465 3993 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
3994 .maxauthsize = SHA1_DIGEST_SIZE,
3995 },
3996 .caam = {
3997 .class1_alg_type = OP_ALG_ALGSEL_AES |
3998 OP_ALG_AAI_CTR_MOD128,
3999 .class2_alg_type = OP_ALG_ALGSEL_SHA1 |
4000 OP_ALG_AAI_HMAC_PRECOMP,
4001 .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC,
4002 .rfc3686 = true,
4003 .geniv = true,
4004 },
daebc465
CV
4005 },
4006 {
479bcc7c
HX
4007 .aead = {
4008 .base = {
4009 .cra_name = "authenc(hmac(sha224),"
4010 "rfc3686(ctr(aes)))",
4011 .cra_driver_name = "authenc-hmac-sha224-"
4012 "rfc3686-ctr-aes-caam",
4013 .cra_blocksize = 1,
4014 },
daebc465
CV
4015 .setkey = aead_setkey,
4016 .setauthsize = aead_setauthsize,
479bcc7c
HX
4017 .encrypt = aead_encrypt,
4018 .decrypt = aead_decrypt,
daebc465 4019 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
4020 .maxauthsize = SHA224_DIGEST_SIZE,
4021 },
4022 .caam = {
4023 .class1_alg_type = OP_ALG_ALGSEL_AES |
4024 OP_ALG_AAI_CTR_MOD128,
4025 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
4026 OP_ALG_AAI_HMAC_PRECOMP,
4027 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
4028 .rfc3686 = true,
4029 },
daebc465
CV
4030 },
4031 {
479bcc7c
HX
4032 .aead = {
4033 .base = {
4034 .cra_name = "seqiv(authenc("
4035 "hmac(sha224),rfc3686(ctr(aes))))",
4036 .cra_driver_name = "seqiv-authenc-hmac-sha224-"
4037 "rfc3686-ctr-aes-caam",
4038 .cra_blocksize = 1,
4039 },
daebc465
CV
4040 .setkey = aead_setkey,
4041 .setauthsize = aead_setauthsize,
479bcc7c
HX
4042 .encrypt = aead_encrypt,
4043 .decrypt = aead_givdecrypt,
daebc465 4044 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
4045 .maxauthsize = SHA224_DIGEST_SIZE,
4046 },
4047 .caam = {
4048 .class1_alg_type = OP_ALG_ALGSEL_AES |
4049 OP_ALG_AAI_CTR_MOD128,
4050 .class2_alg_type = OP_ALG_ALGSEL_SHA224 |
4051 OP_ALG_AAI_HMAC_PRECOMP,
4052 .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC,
4053 .rfc3686 = true,
4054 .geniv = true,
4055 },
acdca31d
YK
4056 },
4057 {
479bcc7c
HX
4058 .aead = {
4059 .base = {
4060 .cra_name = "authenc(hmac(sha256),"
4061 "rfc3686(ctr(aes)))",
4062 .cra_driver_name = "authenc-hmac-sha256-"
4063 "rfc3686-ctr-aes-caam",
4064 .cra_blocksize = 1,
acdca31d 4065 },
479bcc7c
HX
4066 .setkey = aead_setkey,
4067 .setauthsize = aead_setauthsize,
4068 .encrypt = aead_encrypt,
4069 .decrypt = aead_decrypt,
4070 .ivsize = CTR_RFC3686_IV_SIZE,
4071 .maxauthsize = SHA256_DIGEST_SIZE,
4072 },
4073 .caam = {
4074 .class1_alg_type = OP_ALG_ALGSEL_AES |
4075 OP_ALG_AAI_CTR_MOD128,
4076 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
4077 OP_ALG_AAI_HMAC_PRECOMP,
4078 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
4079 .rfc3686 = true,
4080 },
acdca31d
YK
4081 },
4082 {
479bcc7c
HX
4083 .aead = {
4084 .base = {
4085 .cra_name = "seqiv(authenc(hmac(sha256),"
4086 "rfc3686(ctr(aes))))",
4087 .cra_driver_name = "seqiv-authenc-hmac-sha256-"
4088 "rfc3686-ctr-aes-caam",
4089 .cra_blocksize = 1,
acdca31d 4090 },
479bcc7c
HX
4091 .setkey = aead_setkey,
4092 .setauthsize = aead_setauthsize,
4093 .encrypt = aead_encrypt,
4094 .decrypt = aead_givdecrypt,
4095 .ivsize = CTR_RFC3686_IV_SIZE,
4096 .maxauthsize = SHA256_DIGEST_SIZE,
4097 },
4098 .caam = {
4099 .class1_alg_type = OP_ALG_ALGSEL_AES |
4100 OP_ALG_AAI_CTR_MOD128,
4101 .class2_alg_type = OP_ALG_ALGSEL_SHA256 |
4102 OP_ALG_AAI_HMAC_PRECOMP,
4103 .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC,
4104 .rfc3686 = true,
4105 .geniv = true,
4106 },
2b22f6c5
CV
4107 },
4108 {
479bcc7c
HX
4109 .aead = {
4110 .base = {
4111 .cra_name = "authenc(hmac(sha384),"
4112 "rfc3686(ctr(aes)))",
4113 .cra_driver_name = "authenc-hmac-sha384-"
4114 "rfc3686-ctr-aes-caam",
4115 .cra_blocksize = 1,
2b22f6c5 4116 },
479bcc7c
HX
4117 .setkey = aead_setkey,
4118 .setauthsize = aead_setauthsize,
4119 .encrypt = aead_encrypt,
4120 .decrypt = aead_decrypt,
a5f57cff 4121 .ivsize = CTR_RFC3686_IV_SIZE,
479bcc7c
HX
4122 .maxauthsize = SHA384_DIGEST_SIZE,
4123 },
4124 .caam = {
4125 .class1_alg_type = OP_ALG_ALGSEL_AES |
4126 OP_ALG_AAI_CTR_MOD128,
4127 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
4128 OP_ALG_AAI_HMAC_PRECOMP,
4129 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
4130 .rfc3686 = true,
4131 },
4132 },
f2147b88
HX
4133 {
4134 .aead = {
4135 .base = {
479bcc7c
HX
4136 .cra_name = "seqiv(authenc(hmac(sha384),"
4137 "rfc3686(ctr(aes))))",
4138 .cra_driver_name = "seqiv-authenc-hmac-sha384-"
4139 "rfc3686-ctr-aes-caam",
f2147b88
HX
4140 .cra_blocksize = 1,
4141 },
479bcc7c
HX
4142 .setkey = aead_setkey,
4143 .setauthsize = aead_setauthsize,
4144 .encrypt = aead_encrypt,
4145 .decrypt = aead_givdecrypt,
4146 .ivsize = CTR_RFC3686_IV_SIZE,
4147 .maxauthsize = SHA384_DIGEST_SIZE,
f2147b88
HX
4148 },
4149 .caam = {
479bcc7c
HX
4150 .class1_alg_type = OP_ALG_ALGSEL_AES |
4151 OP_ALG_AAI_CTR_MOD128,
4152 .class2_alg_type = OP_ALG_ALGSEL_SHA384 |
4153 OP_ALG_AAI_HMAC_PRECOMP,
4154 .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC,
4155 .rfc3686 = true,
4156 .geniv = true,
f2147b88
HX
4157 },
4158 },
4159 {
4160 .aead = {
4161 .base = {
479bcc7c
HX
4162 .cra_name = "authenc(hmac(sha512),"
4163 "rfc3686(ctr(aes)))",
4164 .cra_driver_name = "authenc-hmac-sha512-"
4165 "rfc3686-ctr-aes-caam",
f2147b88
HX
4166 .cra_blocksize = 1,
4167 },
479bcc7c
HX
4168 .setkey = aead_setkey,
4169 .setauthsize = aead_setauthsize,
4170 .encrypt = aead_encrypt,
4171 .decrypt = aead_decrypt,
4172 .ivsize = CTR_RFC3686_IV_SIZE,
4173 .maxauthsize = SHA512_DIGEST_SIZE,
f2147b88
HX
4174 },
4175 .caam = {
479bcc7c
HX
4176 .class1_alg_type = OP_ALG_ALGSEL_AES |
4177 OP_ALG_AAI_CTR_MOD128,
4178 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
4179 OP_ALG_AAI_HMAC_PRECOMP,
4180 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
4181 .rfc3686 = true,
f2147b88
HX
4182 },
4183 },
f2147b88
HX
4184 {
4185 .aead = {
4186 .base = {
479bcc7c
HX
4187 .cra_name = "seqiv(authenc(hmac(sha512),"
4188 "rfc3686(ctr(aes))))",
4189 .cra_driver_name = "seqiv-authenc-hmac-sha512-"
4190 "rfc3686-ctr-aes-caam",
f2147b88
HX
4191 .cra_blocksize = 1,
4192 },
479bcc7c
HX
4193 .setkey = aead_setkey,
4194 .setauthsize = aead_setauthsize,
4195 .encrypt = aead_encrypt,
4196 .decrypt = aead_givdecrypt,
4197 .ivsize = CTR_RFC3686_IV_SIZE,
4198 .maxauthsize = SHA512_DIGEST_SIZE,
f2147b88
HX
4199 },
4200 .caam = {
479bcc7c
HX
4201 .class1_alg_type = OP_ALG_ALGSEL_AES |
4202 OP_ALG_AAI_CTR_MOD128,
4203 .class2_alg_type = OP_ALG_ALGSEL_SHA512 |
4204 OP_ALG_AAI_HMAC_PRECOMP,
4205 .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC,
4206 .rfc3686 = true,
4207 .geniv = true,
f2147b88
HX
4208 },
4209 },
4210};
4211
4212struct caam_crypto_alg {
8e8ec596 4213 struct crypto_alg crypto_alg;
f2147b88
HX
4214 struct list_head entry;
4215 struct caam_alg_entry caam;
8e8ec596
KP
4216};
4217
f2147b88 4218static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam)
8e8ec596 4219{
cfc6f11b
RG
4220 ctx->jrdev = caam_jr_alloc();
4221 if (IS_ERR(ctx->jrdev)) {
4222 pr_err("Job Ring Device allocation for transform failed\n");
4223 return PTR_ERR(ctx->jrdev);
4224 }
8e8ec596
KP
4225
4226 /* copy descriptor header template value */
f2147b88
HX
4227 ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam->class1_alg_type;
4228 ctx->class2_alg_type = OP_TYPE_CLASS2_ALG | caam->class2_alg_type;
4229 ctx->alg_op = OP_TYPE_CLASS2_ALG | caam->alg_op;
8e8ec596
KP
4230
4231 return 0;
4232}
4233
f2147b88 4234static int caam_cra_init(struct crypto_tfm *tfm)
8e8ec596 4235{
f2147b88
HX
4236 struct crypto_alg *alg = tfm->__crt_alg;
4237 struct caam_crypto_alg *caam_alg =
4238 container_of(alg, struct caam_crypto_alg, crypto_alg);
8e8ec596
KP
4239 struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
4240
f2147b88
HX
4241 return caam_init_common(ctx, &caam_alg->caam);
4242}
4243
4244static int caam_aead_init(struct crypto_aead *tfm)
4245{
4246 struct aead_alg *alg = crypto_aead_alg(tfm);
4247 struct caam_aead_alg *caam_alg =
4248 container_of(alg, struct caam_aead_alg, aead);
4249 struct caam_ctx *ctx = crypto_aead_ctx(tfm);
4250
4251 return caam_init_common(ctx, &caam_alg->caam);
4252}
4253
4254static void caam_exit_common(struct caam_ctx *ctx)
4255{
1acebad3
YK
4256 if (ctx->sh_desc_enc_dma &&
4257 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_enc_dma))
4258 dma_unmap_single(ctx->jrdev, ctx->sh_desc_enc_dma,
4259 desc_bytes(ctx->sh_desc_enc), DMA_TO_DEVICE);
4260 if (ctx->sh_desc_dec_dma &&
4261 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_dec_dma))
4262 dma_unmap_single(ctx->jrdev, ctx->sh_desc_dec_dma,
4263 desc_bytes(ctx->sh_desc_dec), DMA_TO_DEVICE);
4264 if (ctx->sh_desc_givenc_dma &&
4265 !dma_mapping_error(ctx->jrdev, ctx->sh_desc_givenc_dma))
4266 dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma,
4267 desc_bytes(ctx->sh_desc_givenc),
4427b1b4 4268 DMA_TO_DEVICE);
ec31eed7
HG
4269 if (ctx->key_dma &&
4270 !dma_mapping_error(ctx->jrdev, ctx->key_dma))
4271 dma_unmap_single(ctx->jrdev, ctx->key_dma,
4272 ctx->enckeylen + ctx->split_key_pad_len,
4273 DMA_TO_DEVICE);
cfc6f11b
RG
4274
4275 caam_jr_free(ctx->jrdev);
8e8ec596
KP
4276}
4277
f2147b88
HX
4278static void caam_cra_exit(struct crypto_tfm *tfm)
4279{
4280 caam_exit_common(crypto_tfm_ctx(tfm));
4281}
4282
4283static void caam_aead_exit(struct crypto_aead *tfm)
4284{
4285 caam_exit_common(crypto_aead_ctx(tfm));
4286}
4287
8e8ec596
KP
4288static void __exit caam_algapi_exit(void)
4289{
4290
8e8ec596 4291 struct caam_crypto_alg *t_alg, *n;
f2147b88
HX
4292 int i;
4293
4294 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
4295 struct caam_aead_alg *t_alg = driver_aeads + i;
4296
4297 if (t_alg->registered)
4298 crypto_unregister_aead(&t_alg->aead);
4299 }
8e8ec596 4300
cfc6f11b 4301 if (!alg_list.next)
8e8ec596
KP
4302 return;
4303
cfc6f11b 4304 list_for_each_entry_safe(t_alg, n, &alg_list, entry) {
8e8ec596
KP
4305 crypto_unregister_alg(&t_alg->crypto_alg);
4306 list_del(&t_alg->entry);
4307 kfree(t_alg);
4308 }
8e8ec596
KP
4309}
4310
cfc6f11b 4311static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template
8e8ec596
KP
4312 *template)
4313{
4314 struct caam_crypto_alg *t_alg;
4315 struct crypto_alg *alg;
4316
9c4f9733 4317 t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL);
8e8ec596 4318 if (!t_alg) {
cfc6f11b 4319 pr_err("failed to allocate t_alg\n");
8e8ec596
KP
4320 return ERR_PTR(-ENOMEM);
4321 }
4322
4323 alg = &t_alg->crypto_alg;
4324
4325 snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
4326 snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
4327 template->driver_name);
4328 alg->cra_module = THIS_MODULE;
4329 alg->cra_init = caam_cra_init;
4330 alg->cra_exit = caam_cra_exit;
4331 alg->cra_priority = CAAM_CRA_PRIORITY;
8e8ec596
KP
4332 alg->cra_blocksize = template->blocksize;
4333 alg->cra_alignmask = 0;
8e8ec596 4334 alg->cra_ctxsize = sizeof(struct caam_ctx);
d912bb76
NM
4335 alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
4336 template->type;
885e9e2f 4337 switch (template->type) {
7222d1a3
CV
4338 case CRYPTO_ALG_TYPE_GIVCIPHER:
4339 alg->cra_type = &crypto_givcipher_type;
4340 alg->cra_ablkcipher = template->template_ablkcipher;
4341 break;
acdca31d
YK
4342 case CRYPTO_ALG_TYPE_ABLKCIPHER:
4343 alg->cra_type = &crypto_ablkcipher_type;
4344 alg->cra_ablkcipher = template->template_ablkcipher;
4345 break;
885e9e2f 4346 }
8e8ec596 4347
f2147b88
HX
4348 t_alg->caam.class1_alg_type = template->class1_alg_type;
4349 t_alg->caam.class2_alg_type = template->class2_alg_type;
4350 t_alg->caam.alg_op = template->alg_op;
8e8ec596
KP
4351
4352 return t_alg;
4353}
4354
f2147b88
HX
4355static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
4356{
4357 struct aead_alg *alg = &t_alg->aead;
4358
4359 alg->base.cra_module = THIS_MODULE;
4360 alg->base.cra_priority = CAAM_CRA_PRIORITY;
4361 alg->base.cra_ctxsize = sizeof(struct caam_ctx);
5e4b8c1f 4362 alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
f2147b88
HX
4363
4364 alg->init = caam_aead_init;
4365 alg->exit = caam_aead_exit;
4366}
4367
8e8ec596
KP
4368static int __init caam_algapi_init(void)
4369{
35af6403
RG
4370 struct device_node *dev_node;
4371 struct platform_device *pdev;
4372 struct device *ctrldev;
bf83490e 4373 struct caam_drv_private *priv;
8e8ec596 4374 int i = 0, err = 0;
bf83490e
VM
4375 u32 cha_vid, cha_inst, des_inst, aes_inst, md_inst;
4376 unsigned int md_limit = SHA512_DIGEST_SIZE;
f2147b88 4377 bool registered = false;
8e8ec596 4378
35af6403
RG
4379 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
4380 if (!dev_node) {
4381 dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
4382 if (!dev_node)
4383 return -ENODEV;
4384 }
4385
4386 pdev = of_find_device_by_node(dev_node);
4387 if (!pdev) {
4388 of_node_put(dev_node);
4389 return -ENODEV;
4390 }
4391
4392 ctrldev = &pdev->dev;
4393 priv = dev_get_drvdata(ctrldev);
4394 of_node_put(dev_node);
4395
4396 /*
4397 * If priv is NULL, it's probably because the caam driver wasn't
4398 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
4399 */
4400 if (!priv)
4401 return -ENODEV;
4402
4403
cfc6f11b 4404 INIT_LIST_HEAD(&alg_list);
8e8ec596 4405
bf83490e
VM
4406 /*
4407 * Register crypto algorithms the device supports.
4408 * First, detect presence and attributes of DES, AES, and MD blocks.
4409 */
4410 cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
4411 cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
4412 des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >> CHA_ID_LS_DES_SHIFT;
4413 aes_inst = (cha_inst & CHA_ID_LS_AES_MASK) >> CHA_ID_LS_AES_SHIFT;
4414 md_inst = (cha_inst & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
4415
4416 /* If MD is present, limit digest size based on LP256 */
4417 if (md_inst && ((cha_vid & CHA_ID_LS_MD_MASK) == CHA_ID_LS_MD_LP256))
4418 md_limit = SHA256_DIGEST_SIZE;
4419
8e8ec596 4420 for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
8e8ec596 4421 struct caam_crypto_alg *t_alg;
bf83490e
VM
4422 struct caam_alg_template *alg = driver_algs + i;
4423 u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
4424
4425 /* Skip DES algorithms if not supported by device */
4426 if (!des_inst &&
4427 ((alg_sel == OP_ALG_ALGSEL_3DES) ||
4428 (alg_sel == OP_ALG_ALGSEL_DES)))
4429 continue;
4430
4431 /* Skip AES algorithms if not supported by device */
4432 if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
4433 continue;
8e8ec596 4434
bf83490e 4435 t_alg = caam_alg_alloc(alg);
8e8ec596
KP
4436 if (IS_ERR(t_alg)) {
4437 err = PTR_ERR(t_alg);
bf83490e 4438 pr_warn("%s alg allocation failed\n", alg->driver_name);
8e8ec596
KP
4439 continue;
4440 }
4441
4442 err = crypto_register_alg(&t_alg->crypto_alg);
4443 if (err) {
cfc6f11b 4444 pr_warn("%s alg registration failed\n",
8e8ec596
KP
4445 t_alg->crypto_alg.cra_driver_name);
4446 kfree(t_alg);
f2147b88
HX
4447 continue;
4448 }
4449
4450 list_add_tail(&t_alg->entry, &alg_list);
4451 registered = true;
4452 }
4453
4454 for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
4455 struct caam_aead_alg *t_alg = driver_aeads + i;
bf83490e
VM
4456 u32 c1_alg_sel = t_alg->caam.class1_alg_type &
4457 OP_ALG_ALGSEL_MASK;
4458 u32 c2_alg_sel = t_alg->caam.class2_alg_type &
4459 OP_ALG_ALGSEL_MASK;
4460 u32 alg_aai = t_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
4461
4462 /* Skip DES algorithms if not supported by device */
4463 if (!des_inst &&
4464 ((c1_alg_sel == OP_ALG_ALGSEL_3DES) ||
4465 (c1_alg_sel == OP_ALG_ALGSEL_DES)))
4466 continue;
4467
4468 /* Skip AES algorithms if not supported by device */
4469 if (!aes_inst && (c1_alg_sel == OP_ALG_ALGSEL_AES))
4470 continue;
4471
4472 /*
4473 * Check support for AES algorithms not available
4474 * on LP devices.
4475 */
4476 if ((cha_vid & CHA_ID_LS_AES_MASK) == CHA_ID_LS_AES_LP)
4477 if (alg_aai == OP_ALG_AAI_GCM)
4478 continue;
4479
4480 /*
4481 * Skip algorithms requiring message digests
4482 * if MD or MD size is not supported by device.
4483 */
4484 if (c2_alg_sel &&
4485 (!md_inst || (t_alg->aead.maxauthsize > md_limit)))
4486 continue;
f2147b88
HX
4487
4488 caam_aead_alg_init(t_alg);
4489
4490 err = crypto_register_aead(&t_alg->aead);
4491 if (err) {
4492 pr_warn("%s alg registration failed\n",
4493 t_alg->aead.base.cra_driver_name);
4494 continue;
4495 }
4496
4497 t_alg->registered = true;
4498 registered = true;
8e8ec596 4499 }
f2147b88
HX
4500
4501 if (registered)
cfc6f11b 4502 pr_info("caam algorithms registered in /proc/crypto\n");
8e8ec596
KP
4503
4504 return err;
4505}
4506
4507module_init(caam_algapi_init);
4508module_exit(caam_algapi_exit);
4509
4510MODULE_LICENSE("GPL");
4511MODULE_DESCRIPTION("FSL CAAM support for crypto API");
4512MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");