Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 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) | |
Yuan Kang | 6ec4733 | 2012-06-22 19:48:43 -0500 | [diff] [blame] | 40 | * | (output length) | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 41 | * | SEQ_IN_PTR | |
| 42 | * | (input buffer) | |
Yuan Kang | 6ec4733 | 2012-06-22 19:48:43 -0500 | [diff] [blame] | 43 | * | (input length) | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 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" |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 54 | #include "sg_sw_sec4.h" |
Yuan Kang | 4c1ec1f | 2012-06-22 19:48:45 -0500 | [diff] [blame] | 55 | #include "key_gen.h" |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 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 + \ |
| 63 | SHA512_DIGEST_SIZE * 2) |
| 64 | /* max IV is max of AES_BLOCK_SIZE, DES3_EDE_BLOCK_SIZE */ |
| 65 | #define CAAM_MAX_IV_LENGTH 16 |
| 66 | |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 67 | /* length of descriptors text */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 68 | #define DESC_AEAD_BASE (4 * CAAM_CMD_SZ) |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 69 | #define DESC_AEAD_ENC_LEN (DESC_AEAD_BASE + 15 * CAAM_CMD_SZ) |
| 70 | #define DESC_AEAD_DEC_LEN (DESC_AEAD_BASE + 18 * CAAM_CMD_SZ) |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 71 | #define DESC_AEAD_GIVENC_LEN (DESC_AEAD_ENC_LEN + 7 * CAAM_CMD_SZ) |
| 72 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 73 | #define DESC_AEAD_NULL_BASE (3 * CAAM_CMD_SZ) |
| 74 | #define DESC_AEAD_NULL_ENC_LEN (DESC_AEAD_NULL_BASE + 14 * CAAM_CMD_SZ) |
| 75 | #define DESC_AEAD_NULL_DEC_LEN (DESC_AEAD_NULL_BASE + 17 * CAAM_CMD_SZ) |
| 76 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 77 | #define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ) |
| 78 | #define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \ |
| 79 | 20 * CAAM_CMD_SZ) |
| 80 | #define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \ |
| 81 | 15 * CAAM_CMD_SZ) |
| 82 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 83 | #define DESC_MAX_USED_BYTES (DESC_AEAD_GIVENC_LEN + \ |
| 84 | CAAM_MAX_KEY_SIZE) |
| 85 | #define DESC_MAX_USED_LEN (DESC_MAX_USED_BYTES / CAAM_CMD_SZ) |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 86 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 87 | #ifdef DEBUG |
| 88 | /* for print_hex_dumps with line references */ |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 89 | #define debug(format, arg...) printk(format, arg) |
| 90 | #else |
| 91 | #define debug(format, arg...) |
| 92 | #endif |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 93 | static struct list_head alg_list; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 94 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 95 | /* Set DK bit in class 1 operation if shared */ |
| 96 | static inline void append_dec_op1(u32 *desc, u32 type) |
| 97 | { |
| 98 | u32 *jump_cmd, *uncond_jump_cmd; |
| 99 | |
| 100 | jump_cmd = append_jump(desc, JUMP_TEST_ALL | JUMP_COND_SHRD); |
| 101 | append_operation(desc, type | OP_ALG_AS_INITFINAL | |
| 102 | OP_ALG_DECRYPT); |
| 103 | uncond_jump_cmd = append_jump(desc, JUMP_TEST_ALL); |
| 104 | set_jump_tgt_here(desc, jump_cmd); |
| 105 | append_operation(desc, type | OP_ALG_AS_INITFINAL | |
| 106 | OP_ALG_DECRYPT | OP_ALG_AAI_DK); |
| 107 | set_jump_tgt_here(desc, uncond_jump_cmd); |
| 108 | } |
| 109 | |
| 110 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 111 | * For aead functions, read payload and write payload, |
| 112 | * both of which are specified in req->src and req->dst |
| 113 | */ |
| 114 | static inline void aead_append_src_dst(u32 *desc, u32 msg_type) |
| 115 | { |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 116 | append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 117 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_BOTH | |
| 118 | KEY_VLF | msg_type | FIFOLD_TYPE_LASTBOTH); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /* |
| 122 | * For aead encrypt and decrypt, read iv for both classes |
| 123 | */ |
| 124 | static inline void aead_append_ld_iv(u32 *desc, int ivsize) |
| 125 | { |
| 126 | append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT | |
| 127 | LDST_CLASS_1_CCB | ivsize); |
| 128 | append_move(desc, MOVE_SRC_CLASS1CTX | MOVE_DEST_CLASS2INFIFO | ivsize); |
| 129 | } |
| 130 | |
| 131 | /* |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 132 | * For ablkcipher encrypt and decrypt, read from req->src and |
| 133 | * write to req->dst |
| 134 | */ |
| 135 | static inline void ablkcipher_append_src_dst(u32 *desc) |
| 136 | { |
Kim Phillips | 70d793c | 2012-06-22 19:42:35 -0500 | [diff] [blame] | 137 | append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
| 138 | append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
| 139 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS1 | |
| 140 | KEY_VLF | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST1); |
| 141 | append_seq_fifo_store(desc, 0, FIFOST_TYPE_MESSAGE_DATA | KEY_VLF); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 145 | * If all data, including src (with assoc and iv) or dst (with iv only) are |
| 146 | * contiguous |
| 147 | */ |
| 148 | #define GIV_SRC_CONTIG 1 |
| 149 | #define GIV_DST_CONTIG (1 << 1) |
| 150 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 151 | /* |
| 152 | * per-session context |
| 153 | */ |
| 154 | struct caam_ctx { |
| 155 | struct device *jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 156 | u32 sh_desc_enc[DESC_MAX_USED_LEN]; |
| 157 | u32 sh_desc_dec[DESC_MAX_USED_LEN]; |
| 158 | u32 sh_desc_givenc[DESC_MAX_USED_LEN]; |
| 159 | dma_addr_t sh_desc_enc_dma; |
| 160 | dma_addr_t sh_desc_dec_dma; |
| 161 | dma_addr_t sh_desc_givenc_dma; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 162 | u32 class1_alg_type; |
| 163 | u32 class2_alg_type; |
| 164 | u32 alg_op; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 165 | u8 key[CAAM_MAX_KEY_SIZE]; |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 166 | dma_addr_t key_dma; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 167 | unsigned int enckeylen; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 168 | unsigned int split_key_len; |
| 169 | unsigned int split_key_pad_len; |
| 170 | unsigned int authsize; |
| 171 | }; |
| 172 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 173 | static void append_key_aead(u32 *desc, struct caam_ctx *ctx, |
| 174 | int keys_fit_inline) |
| 175 | { |
| 176 | if (keys_fit_inline) { |
| 177 | append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len, |
| 178 | ctx->split_key_len, CLASS_2 | |
| 179 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 180 | append_key_as_imm(desc, (void *)ctx->key + |
| 181 | ctx->split_key_pad_len, ctx->enckeylen, |
| 182 | ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG); |
| 183 | } else { |
| 184 | append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 | |
| 185 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 186 | append_key(desc, ctx->key_dma + ctx->split_key_pad_len, |
| 187 | ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static void init_sh_desc_key_aead(u32 *desc, struct caam_ctx *ctx, |
| 192 | int keys_fit_inline) |
| 193 | { |
| 194 | u32 *key_jump_cmd; |
| 195 | |
Kim Phillips | 61bb86b | 2012-07-13 17:49:28 -0500 | [diff] [blame] | 196 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 197 | |
| 198 | /* Skip if already shared */ |
| 199 | key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
| 200 | JUMP_COND_SHRD); |
| 201 | |
| 202 | append_key_aead(desc, ctx, keys_fit_inline); |
| 203 | |
| 204 | set_jump_tgt_here(desc, key_jump_cmd); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 205 | } |
| 206 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 207 | static int aead_null_set_sh_desc(struct crypto_aead *aead) |
| 208 | { |
| 209 | struct aead_tfm *tfm = &aead->base.crt_aead; |
| 210 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 211 | struct device *jrdev = ctx->jrdev; |
| 212 | bool keys_fit_inline = false; |
| 213 | u32 *key_jump_cmd, *jump_cmd, *read_move_cmd, *write_move_cmd; |
| 214 | u32 *desc; |
| 215 | |
| 216 | /* |
| 217 | * Job Descriptor and Shared Descriptors |
| 218 | * must all fit into the 64-word Descriptor h/w Buffer |
| 219 | */ |
| 220 | if (DESC_AEAD_NULL_ENC_LEN + DESC_JOB_IO_LEN + |
| 221 | ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX) |
| 222 | keys_fit_inline = true; |
| 223 | |
| 224 | /* aead_encrypt shared descriptor */ |
| 225 | desc = ctx->sh_desc_enc; |
| 226 | |
| 227 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
| 228 | |
| 229 | /* Skip if already shared */ |
| 230 | key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
| 231 | JUMP_COND_SHRD); |
| 232 | if (keys_fit_inline) |
| 233 | append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len, |
| 234 | ctx->split_key_len, CLASS_2 | |
| 235 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 236 | else |
| 237 | append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 | |
| 238 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 239 | set_jump_tgt_here(desc, key_jump_cmd); |
| 240 | |
| 241 | /* cryptlen = seqoutlen - authsize */ |
| 242 | append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize); |
| 243 | |
| 244 | /* |
| 245 | * NULL encryption; IV is zero |
| 246 | * assoclen = (assoclen + cryptlen) - cryptlen |
| 247 | */ |
| 248 | append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG3, CAAM_CMD_SZ); |
| 249 | |
| 250 | /* read assoc before reading payload */ |
| 251 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG | |
| 252 | KEY_VLF); |
| 253 | |
| 254 | /* Prepare to read and write cryptlen bytes */ |
| 255 | append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ); |
| 256 | append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); |
| 257 | |
| 258 | /* |
| 259 | * MOVE_LEN opcode is not available in all SEC HW revisions, |
| 260 | * thus need to do some magic, i.e. self-patch the descriptor |
| 261 | * buffer. |
| 262 | */ |
| 263 | read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | |
| 264 | MOVE_DEST_MATH3 | |
| 265 | (0x6 << MOVE_LEN_SHIFT)); |
| 266 | write_move_cmd = append_move(desc, MOVE_SRC_MATH3 | |
| 267 | MOVE_DEST_DESCBUF | |
| 268 | MOVE_WAITCOMP | |
| 269 | (0x8 << MOVE_LEN_SHIFT)); |
| 270 | |
| 271 | /* Class 2 operation */ |
| 272 | append_operation(desc, ctx->class2_alg_type | |
| 273 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 274 | |
| 275 | /* Read and write cryptlen bytes */ |
| 276 | aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1); |
| 277 | |
| 278 | set_move_tgt_here(desc, read_move_cmd); |
| 279 | set_move_tgt_here(desc, write_move_cmd); |
| 280 | append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO); |
| 281 | append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO | |
| 282 | MOVE_AUX_LS); |
| 283 | |
| 284 | /* Write ICV */ |
| 285 | append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB | |
| 286 | LDST_SRCDST_BYTE_CONTEXT); |
| 287 | |
| 288 | ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, |
| 289 | desc_bytes(desc), |
| 290 | DMA_TO_DEVICE); |
| 291 | if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) { |
| 292 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 293 | return -ENOMEM; |
| 294 | } |
| 295 | #ifdef DEBUG |
| 296 | print_hex_dump(KERN_ERR, |
| 297 | "aead null enc shdesc@"__stringify(__LINE__)": ", |
| 298 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 299 | desc_bytes(desc), 1); |
| 300 | #endif |
| 301 | |
| 302 | /* |
| 303 | * Job Descriptor and Shared Descriptors |
| 304 | * must all fit into the 64-word Descriptor h/w Buffer |
| 305 | */ |
Vakul Garg | 80cd88f | 2014-05-09 20:34:40 -0500 | [diff] [blame] | 306 | keys_fit_inline = false; |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 307 | if (DESC_AEAD_NULL_DEC_LEN + DESC_JOB_IO_LEN + |
| 308 | ctx->split_key_pad_len <= CAAM_DESC_BYTES_MAX) |
| 309 | keys_fit_inline = true; |
| 310 | |
| 311 | desc = ctx->sh_desc_dec; |
| 312 | |
| 313 | /* aead_decrypt shared descriptor */ |
| 314 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
| 315 | |
| 316 | /* Skip if already shared */ |
| 317 | key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
| 318 | JUMP_COND_SHRD); |
| 319 | if (keys_fit_inline) |
| 320 | append_key_as_imm(desc, ctx->key, ctx->split_key_pad_len, |
| 321 | ctx->split_key_len, CLASS_2 | |
| 322 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 323 | else |
| 324 | append_key(desc, ctx->key_dma, ctx->split_key_len, CLASS_2 | |
| 325 | KEY_DEST_MDHA_SPLIT | KEY_ENC); |
| 326 | set_jump_tgt_here(desc, key_jump_cmd); |
| 327 | |
| 328 | /* Class 2 operation */ |
| 329 | append_operation(desc, ctx->class2_alg_type | |
| 330 | OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON); |
| 331 | |
| 332 | /* assoclen + cryptlen = seqinlen - ivsize - authsize */ |
| 333 | append_math_sub_imm_u32(desc, REG3, SEQINLEN, IMM, |
| 334 | ctx->authsize + tfm->ivsize); |
| 335 | /* assoclen = (assoclen + cryptlen) - cryptlen */ |
| 336 | append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ); |
| 337 | append_math_sub(desc, VARSEQINLEN, REG3, REG2, CAAM_CMD_SZ); |
| 338 | |
| 339 | /* read assoc before reading payload */ |
| 340 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG | |
| 341 | KEY_VLF); |
| 342 | |
| 343 | /* Prepare to read and write cryptlen bytes */ |
| 344 | append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ); |
| 345 | append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ); |
| 346 | |
| 347 | /* |
| 348 | * MOVE_LEN opcode is not available in all SEC HW revisions, |
| 349 | * thus need to do some magic, i.e. self-patch the descriptor |
| 350 | * buffer. |
| 351 | */ |
| 352 | read_move_cmd = append_move(desc, MOVE_SRC_DESCBUF | |
| 353 | MOVE_DEST_MATH2 | |
| 354 | (0x6 << MOVE_LEN_SHIFT)); |
| 355 | write_move_cmd = append_move(desc, MOVE_SRC_MATH2 | |
| 356 | MOVE_DEST_DESCBUF | |
| 357 | MOVE_WAITCOMP | |
| 358 | (0x8 << MOVE_LEN_SHIFT)); |
| 359 | |
| 360 | /* Read and write cryptlen bytes */ |
| 361 | aead_append_src_dst(desc, FIFOLD_TYPE_MSG | FIFOLD_TYPE_FLUSH1); |
| 362 | |
| 363 | /* |
| 364 | * Insert a NOP here, since we need at least 4 instructions between |
| 365 | * code patching the descriptor buffer and the location being patched. |
| 366 | */ |
| 367 | jump_cmd = append_jump(desc, JUMP_TEST_ALL); |
| 368 | set_jump_tgt_here(desc, jump_cmd); |
| 369 | |
| 370 | set_move_tgt_here(desc, read_move_cmd); |
| 371 | set_move_tgt_here(desc, write_move_cmd); |
| 372 | append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO); |
| 373 | append_move(desc, MOVE_SRC_INFIFO_CL | MOVE_DEST_OUTFIFO | |
| 374 | MOVE_AUX_LS); |
| 375 | append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO); |
| 376 | |
| 377 | /* Load ICV */ |
| 378 | append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 | |
| 379 | FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV); |
| 380 | |
| 381 | ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc, |
| 382 | desc_bytes(desc), |
| 383 | DMA_TO_DEVICE); |
| 384 | if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) { |
| 385 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 386 | return -ENOMEM; |
| 387 | } |
| 388 | #ifdef DEBUG |
| 389 | print_hex_dump(KERN_ERR, |
| 390 | "aead null dec shdesc@"__stringify(__LINE__)": ", |
| 391 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 392 | desc_bytes(desc), 1); |
| 393 | #endif |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 398 | static int aead_set_sh_desc(struct crypto_aead *aead) |
| 399 | { |
| 400 | struct aead_tfm *tfm = &aead->base.crt_aead; |
| 401 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 402 | struct device *jrdev = ctx->jrdev; |
Kim Phillips | 2af8f4a | 2012-09-07 04:17:03 +0800 | [diff] [blame] | 403 | bool keys_fit_inline = false; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 404 | u32 geniv, moveiv; |
| 405 | u32 *desc; |
| 406 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 407 | if (!ctx->authsize) |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 408 | return 0; |
| 409 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 410 | /* NULL encryption / decryption */ |
| 411 | if (!ctx->enckeylen) |
| 412 | return aead_null_set_sh_desc(aead); |
| 413 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 414 | /* |
| 415 | * Job Descriptor and Shared Descriptors |
| 416 | * must all fit into the 64-word Descriptor h/w Buffer |
| 417 | */ |
| 418 | if (DESC_AEAD_ENC_LEN + DESC_JOB_IO_LEN + |
| 419 | ctx->split_key_pad_len + ctx->enckeylen <= |
| 420 | CAAM_DESC_BYTES_MAX) |
Kim Phillips | 2af8f4a | 2012-09-07 04:17:03 +0800 | [diff] [blame] | 421 | keys_fit_inline = true; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 422 | |
| 423 | /* aead_encrypt shared descriptor */ |
| 424 | desc = ctx->sh_desc_enc; |
| 425 | |
| 426 | init_sh_desc_key_aead(desc, ctx, keys_fit_inline); |
| 427 | |
| 428 | /* Class 2 operation */ |
| 429 | append_operation(desc, ctx->class2_alg_type | |
| 430 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 431 | |
| 432 | /* cryptlen = seqoutlen - authsize */ |
| 433 | append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize); |
| 434 | |
| 435 | /* assoclen + cryptlen = seqinlen - ivsize */ |
| 436 | append_math_sub_imm_u32(desc, REG2, SEQINLEN, IMM, tfm->ivsize); |
| 437 | |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 438 | /* assoclen = (assoclen + cryptlen) - cryptlen */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 439 | append_math_sub(desc, VARSEQINLEN, REG2, REG3, CAAM_CMD_SZ); |
| 440 | |
| 441 | /* read assoc before reading payload */ |
| 442 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG | |
| 443 | KEY_VLF); |
| 444 | aead_append_ld_iv(desc, tfm->ivsize); |
| 445 | |
| 446 | /* Class 1 operation */ |
| 447 | append_operation(desc, ctx->class1_alg_type | |
| 448 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 449 | |
| 450 | /* Read and write cryptlen bytes */ |
| 451 | append_math_add(desc, VARSEQINLEN, ZERO, REG3, CAAM_CMD_SZ); |
| 452 | append_math_add(desc, VARSEQOUTLEN, ZERO, REG3, CAAM_CMD_SZ); |
| 453 | aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2); |
| 454 | |
| 455 | /* Write ICV */ |
| 456 | append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB | |
| 457 | LDST_SRCDST_BYTE_CONTEXT); |
| 458 | |
| 459 | ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, |
| 460 | desc_bytes(desc), |
| 461 | DMA_TO_DEVICE); |
| 462 | if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) { |
| 463 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 464 | return -ENOMEM; |
| 465 | } |
| 466 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 467 | print_hex_dump(KERN_ERR, "aead enc shdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 468 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 469 | desc_bytes(desc), 1); |
| 470 | #endif |
| 471 | |
| 472 | /* |
| 473 | * Job Descriptor and Shared Descriptors |
| 474 | * must all fit into the 64-word Descriptor h/w Buffer |
| 475 | */ |
Vakul Garg | 80cd88f | 2014-05-09 20:34:40 -0500 | [diff] [blame] | 476 | keys_fit_inline = false; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 477 | if (DESC_AEAD_DEC_LEN + DESC_JOB_IO_LEN + |
| 478 | ctx->split_key_pad_len + ctx->enckeylen <= |
| 479 | CAAM_DESC_BYTES_MAX) |
Kim Phillips | 2af8f4a | 2012-09-07 04:17:03 +0800 | [diff] [blame] | 480 | keys_fit_inline = true; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 481 | |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 482 | /* aead_decrypt shared descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 483 | desc = ctx->sh_desc_dec; |
| 484 | |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 485 | init_sh_desc_key_aead(desc, ctx, keys_fit_inline); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 486 | |
| 487 | /* Class 2 operation */ |
| 488 | append_operation(desc, ctx->class2_alg_type | |
| 489 | OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT | OP_ALG_ICV_ON); |
| 490 | |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 491 | /* assoclen + cryptlen = seqinlen - ivsize - authsize */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 492 | append_math_sub_imm_u32(desc, REG3, SEQINLEN, IMM, |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 493 | ctx->authsize + tfm->ivsize); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 494 | /* assoclen = (assoclen + cryptlen) - cryptlen */ |
| 495 | append_math_sub(desc, REG2, SEQOUTLEN, REG0, CAAM_CMD_SZ); |
| 496 | append_math_sub(desc, VARSEQINLEN, REG3, REG2, CAAM_CMD_SZ); |
| 497 | |
| 498 | /* read assoc before reading payload */ |
| 499 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG | |
| 500 | KEY_VLF); |
| 501 | |
| 502 | aead_append_ld_iv(desc, tfm->ivsize); |
| 503 | |
| 504 | append_dec_op1(desc, ctx->class1_alg_type); |
| 505 | |
| 506 | /* Read and write cryptlen bytes */ |
| 507 | append_math_add(desc, VARSEQINLEN, ZERO, REG2, CAAM_CMD_SZ); |
| 508 | append_math_add(desc, VARSEQOUTLEN, ZERO, REG2, CAAM_CMD_SZ); |
| 509 | aead_append_src_dst(desc, FIFOLD_TYPE_MSG); |
| 510 | |
| 511 | /* Load ICV */ |
| 512 | append_seq_fifo_load(desc, ctx->authsize, FIFOLD_CLASS_CLASS2 | |
| 513 | FIFOLD_TYPE_LAST2 | FIFOLD_TYPE_ICV); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 514 | |
| 515 | ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc, |
| 516 | desc_bytes(desc), |
| 517 | DMA_TO_DEVICE); |
| 518 | if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) { |
| 519 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 520 | return -ENOMEM; |
| 521 | } |
| 522 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 523 | print_hex_dump(KERN_ERR, "aead dec shdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 524 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 525 | desc_bytes(desc), 1); |
| 526 | #endif |
| 527 | |
| 528 | /* |
| 529 | * Job Descriptor and Shared Descriptors |
| 530 | * must all fit into the 64-word Descriptor h/w Buffer |
| 531 | */ |
Vakul Garg | 80cd88f | 2014-05-09 20:34:40 -0500 | [diff] [blame] | 532 | keys_fit_inline = false; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 533 | if (DESC_AEAD_GIVENC_LEN + DESC_JOB_IO_LEN + |
| 534 | ctx->split_key_pad_len + ctx->enckeylen <= |
| 535 | CAAM_DESC_BYTES_MAX) |
Kim Phillips | 2af8f4a | 2012-09-07 04:17:03 +0800 | [diff] [blame] | 536 | keys_fit_inline = true; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 537 | |
| 538 | /* aead_givencrypt shared descriptor */ |
| 539 | desc = ctx->sh_desc_givenc; |
| 540 | |
| 541 | init_sh_desc_key_aead(desc, ctx, keys_fit_inline); |
| 542 | |
| 543 | /* Generate IV */ |
| 544 | geniv = NFIFOENTRY_STYPE_PAD | NFIFOENTRY_DEST_DECO | |
| 545 | NFIFOENTRY_DTYPE_MSG | NFIFOENTRY_LC1 | |
| 546 | NFIFOENTRY_PTYPE_RND | (tfm->ivsize << NFIFOENTRY_DLEN_SHIFT); |
| 547 | append_load_imm_u32(desc, geniv, LDST_CLASS_IND_CCB | |
| 548 | LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM); |
| 549 | append_cmd(desc, CMD_LOAD | DISABLE_AUTO_INFO_FIFO); |
| 550 | append_move(desc, MOVE_SRC_INFIFO | |
| 551 | MOVE_DEST_CLASS1CTX | (tfm->ivsize << MOVE_LEN_SHIFT)); |
| 552 | append_cmd(desc, CMD_LOAD | ENABLE_AUTO_INFO_FIFO); |
| 553 | |
| 554 | /* Copy IV to class 1 context */ |
| 555 | append_move(desc, MOVE_SRC_CLASS1CTX | |
| 556 | MOVE_DEST_OUTFIFO | (tfm->ivsize << MOVE_LEN_SHIFT)); |
| 557 | |
| 558 | /* Return to encryption */ |
| 559 | append_operation(desc, ctx->class2_alg_type | |
| 560 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 561 | |
| 562 | /* ivsize + cryptlen = seqoutlen - authsize */ |
| 563 | append_math_sub_imm_u32(desc, REG3, SEQOUTLEN, IMM, ctx->authsize); |
| 564 | |
| 565 | /* assoclen = seqinlen - (ivsize + cryptlen) */ |
| 566 | append_math_sub(desc, VARSEQINLEN, SEQINLEN, REG3, CAAM_CMD_SZ); |
| 567 | |
| 568 | /* read assoc before reading payload */ |
| 569 | append_seq_fifo_load(desc, 0, FIFOLD_CLASS_CLASS2 | FIFOLD_TYPE_MSG | |
| 570 | KEY_VLF); |
| 571 | |
| 572 | /* Copy iv from class 1 ctx to class 2 fifo*/ |
| 573 | moveiv = NFIFOENTRY_STYPE_OFIFO | NFIFOENTRY_DEST_CLASS2 | |
| 574 | NFIFOENTRY_DTYPE_MSG | (tfm->ivsize << NFIFOENTRY_DLEN_SHIFT); |
| 575 | append_load_imm_u32(desc, moveiv, LDST_CLASS_IND_CCB | |
| 576 | LDST_SRCDST_WORD_INFO_FIFO | LDST_IMM); |
| 577 | append_load_imm_u32(desc, tfm->ivsize, LDST_CLASS_2_CCB | |
| 578 | LDST_SRCDST_WORD_DATASZ_REG | LDST_IMM); |
| 579 | |
| 580 | /* Class 1 operation */ |
| 581 | append_operation(desc, ctx->class1_alg_type | |
| 582 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 583 | |
| 584 | /* Will write ivsize + cryptlen */ |
| 585 | append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
| 586 | |
| 587 | /* Not need to reload iv */ |
| 588 | append_seq_fifo_load(desc, tfm->ivsize, |
| 589 | FIFOLD_CLASS_SKIP); |
| 590 | |
| 591 | /* Will read cryptlen */ |
| 592 | append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); |
| 593 | aead_append_src_dst(desc, FIFOLD_TYPE_MSG1OUT2); |
| 594 | |
| 595 | /* Write ICV */ |
| 596 | append_seq_store(desc, ctx->authsize, LDST_CLASS_2_CCB | |
| 597 | LDST_SRCDST_BYTE_CONTEXT); |
| 598 | |
| 599 | ctx->sh_desc_givenc_dma = dma_map_single(jrdev, desc, |
| 600 | desc_bytes(desc), |
| 601 | DMA_TO_DEVICE); |
| 602 | if (dma_mapping_error(jrdev, ctx->sh_desc_givenc_dma)) { |
| 603 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 604 | return -ENOMEM; |
| 605 | } |
| 606 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 607 | print_hex_dump(KERN_ERR, "aead givenc shdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 608 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 609 | desc_bytes(desc), 1); |
| 610 | #endif |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 615 | static int aead_setauthsize(struct crypto_aead *authenc, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 616 | unsigned int authsize) |
| 617 | { |
| 618 | struct caam_ctx *ctx = crypto_aead_ctx(authenc); |
| 619 | |
| 620 | ctx->authsize = authsize; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 621 | aead_set_sh_desc(authenc); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
Yuan Kang | 4c1ec1f | 2012-06-22 19:48:45 -0500 | [diff] [blame] | 626 | static u32 gen_split_aead_key(struct caam_ctx *ctx, const u8 *key_in, |
| 627 | u32 authkeylen) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 628 | { |
Yuan Kang | 4c1ec1f | 2012-06-22 19:48:45 -0500 | [diff] [blame] | 629 | return gen_split_key(ctx->jrdev, ctx->key, ctx->split_key_len, |
| 630 | ctx->split_key_pad_len, key_in, authkeylen, |
| 631 | ctx->alg_op); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 632 | } |
| 633 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 634 | static int aead_setkey(struct crypto_aead *aead, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 635 | const u8 *key, unsigned int keylen) |
| 636 | { |
| 637 | /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */ |
| 638 | static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 }; |
| 639 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 640 | struct device *jrdev = ctx->jrdev; |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 641 | struct crypto_authenc_keys keys; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 642 | int ret = 0; |
| 643 | |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 644 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 645 | goto badkey; |
| 646 | |
| 647 | /* Pick class 2 key length from algorithm submask */ |
| 648 | ctx->split_key_len = mdpadlen[(ctx->alg_op & OP_ALG_ALGSEL_SUBMASK) >> |
| 649 | OP_ALG_ALGSEL_SHIFT] * 2; |
| 650 | ctx->split_key_pad_len = ALIGN(ctx->split_key_len, 16); |
| 651 | |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 652 | if (ctx->split_key_pad_len + keys.enckeylen > CAAM_MAX_KEY_SIZE) |
| 653 | goto badkey; |
| 654 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 655 | #ifdef DEBUG |
| 656 | printk(KERN_ERR "keylen %d enckeylen %d authkeylen %d\n", |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 657 | keys.authkeylen + keys.enckeylen, keys.enckeylen, |
| 658 | keys.authkeylen); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 659 | printk(KERN_ERR "split_key_len %d split_key_pad_len %d\n", |
| 660 | ctx->split_key_len, ctx->split_key_pad_len); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 661 | print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 662 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
| 663 | #endif |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 664 | |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 665 | ret = gen_split_aead_key(ctx, keys.authkey, keys.authkeylen); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 666 | if (ret) { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 667 | goto badkey; |
| 668 | } |
| 669 | |
| 670 | /* postpend encryption key to auth split key */ |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 671 | memcpy(ctx->key + ctx->split_key_pad_len, keys.enckey, keys.enckeylen); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 672 | |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 673 | ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len + |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 674 | keys.enckeylen, DMA_TO_DEVICE); |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 675 | if (dma_mapping_error(jrdev, ctx->key_dma)) { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 676 | dev_err(jrdev, "unable to map key i/o memory\n"); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 677 | return -ENOMEM; |
| 678 | } |
| 679 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 680 | print_hex_dump(KERN_ERR, "ctx.key@"__stringify(__LINE__)": ", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 681 | DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 682 | ctx->split_key_pad_len + keys.enckeylen, 1); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 683 | #endif |
| 684 | |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 685 | ctx->enckeylen = keys.enckeylen; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 686 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 687 | ret = aead_set_sh_desc(aead); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 688 | if (ret) { |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 689 | dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len + |
Horia Geanta | 4e6e0b2 | 2013-12-19 17:27:35 +0200 | [diff] [blame] | 690 | keys.enckeylen, DMA_TO_DEVICE); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | return ret; |
| 694 | badkey: |
| 695 | crypto_aead_set_flags(aead, CRYPTO_TFM_RES_BAD_KEY_LEN); |
| 696 | return -EINVAL; |
| 697 | } |
| 698 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 699 | static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, |
| 700 | const u8 *key, unsigned int keylen) |
| 701 | { |
| 702 | struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); |
| 703 | struct ablkcipher_tfm *tfm = &ablkcipher->base.crt_ablkcipher; |
| 704 | struct device *jrdev = ctx->jrdev; |
| 705 | int ret = 0; |
Horia Geanta | 4464a7d | 2014-03-14 17:46:49 +0200 | [diff] [blame] | 706 | u32 *key_jump_cmd; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 707 | u32 *desc; |
| 708 | |
| 709 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 710 | print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 711 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
| 712 | #endif |
| 713 | |
| 714 | memcpy(ctx->key, key, keylen); |
| 715 | ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen, |
| 716 | DMA_TO_DEVICE); |
| 717 | if (dma_mapping_error(jrdev, ctx->key_dma)) { |
| 718 | dev_err(jrdev, "unable to map key i/o memory\n"); |
| 719 | return -ENOMEM; |
| 720 | } |
| 721 | ctx->enckeylen = keylen; |
| 722 | |
| 723 | /* ablkcipher_encrypt shared descriptor */ |
| 724 | desc = ctx->sh_desc_enc; |
Kim Phillips | 61bb86b | 2012-07-13 17:49:28 -0500 | [diff] [blame] | 725 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 726 | /* Skip if already shared */ |
| 727 | key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
| 728 | JUMP_COND_SHRD); |
| 729 | |
| 730 | /* Load class1 key only */ |
| 731 | append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen, |
| 732 | ctx->enckeylen, CLASS_1 | |
| 733 | KEY_DEST_CLASS_REG); |
| 734 | |
| 735 | set_jump_tgt_here(desc, key_jump_cmd); |
| 736 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 737 | /* Load iv */ |
| 738 | append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT | |
| 739 | LDST_CLASS_1_CCB | tfm->ivsize); |
| 740 | |
| 741 | /* Load operation */ |
| 742 | append_operation(desc, ctx->class1_alg_type | |
| 743 | OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT); |
| 744 | |
| 745 | /* Perform operation */ |
| 746 | ablkcipher_append_src_dst(desc); |
| 747 | |
| 748 | ctx->sh_desc_enc_dma = dma_map_single(jrdev, desc, |
| 749 | desc_bytes(desc), |
| 750 | DMA_TO_DEVICE); |
| 751 | if (dma_mapping_error(jrdev, ctx->sh_desc_enc_dma)) { |
| 752 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 753 | return -ENOMEM; |
| 754 | } |
| 755 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 756 | print_hex_dump(KERN_ERR, |
| 757 | "ablkcipher enc shdesc@"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 758 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 759 | desc_bytes(desc), 1); |
| 760 | #endif |
| 761 | /* ablkcipher_decrypt shared descriptor */ |
| 762 | desc = ctx->sh_desc_dec; |
| 763 | |
Kim Phillips | 61bb86b | 2012-07-13 17:49:28 -0500 | [diff] [blame] | 764 | init_sh_desc(desc, HDR_SHARE_SERIAL); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 765 | /* Skip if already shared */ |
| 766 | key_jump_cmd = append_jump(desc, JUMP_JSL | JUMP_TEST_ALL | |
| 767 | JUMP_COND_SHRD); |
| 768 | |
| 769 | /* Load class1 key only */ |
| 770 | append_key_as_imm(desc, (void *)ctx->key, ctx->enckeylen, |
| 771 | ctx->enckeylen, CLASS_1 | |
| 772 | KEY_DEST_CLASS_REG); |
| 773 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 774 | set_jump_tgt_here(desc, key_jump_cmd); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 775 | |
| 776 | /* load IV */ |
| 777 | append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT | |
| 778 | LDST_CLASS_1_CCB | tfm->ivsize); |
| 779 | |
| 780 | /* Choose operation */ |
| 781 | append_dec_op1(desc, ctx->class1_alg_type); |
| 782 | |
| 783 | /* Perform operation */ |
| 784 | ablkcipher_append_src_dst(desc); |
| 785 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 786 | ctx->sh_desc_dec_dma = dma_map_single(jrdev, desc, |
| 787 | desc_bytes(desc), |
| 788 | DMA_TO_DEVICE); |
Horia Geanta | 71c65f7 | 2014-07-11 15:34:48 +0300 | [diff] [blame] | 789 | if (dma_mapping_error(jrdev, ctx->sh_desc_dec_dma)) { |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 790 | dev_err(jrdev, "unable to map shared descriptor\n"); |
| 791 | return -ENOMEM; |
| 792 | } |
| 793 | |
| 794 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 795 | print_hex_dump(KERN_ERR, |
| 796 | "ablkcipher dec shdesc@"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 797 | DUMP_PREFIX_ADDRESS, 16, 4, desc, |
| 798 | desc_bytes(desc), 1); |
| 799 | #endif |
| 800 | |
| 801 | return ret; |
| 802 | } |
| 803 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 804 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 805 | * aead_edesc - s/w-extended aead descriptor |
| 806 | * @assoc_nents: number of segments in associated data (SPI+Seq) scatterlist |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 807 | * @assoc_chained: if source is chained |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 808 | * @src_nents: number of segments in input scatterlist |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 809 | * @src_chained: if source is chained |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 810 | * @dst_nents: number of segments in output scatterlist |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 811 | * @dst_chained: if destination is chained |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 812 | * @iv_dma: dma address of iv for checking continuity and link table |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 813 | * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE) |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 814 | * @sec4_sg_bytes: length of dma mapped sec4_sg space |
| 815 | * @sec4_sg_dma: bus physical mapped address of h/w link table |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 816 | * @hw_desc: the h/w job descriptor followed by any referenced link tables |
| 817 | */ |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 818 | struct aead_edesc { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 819 | int assoc_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 820 | bool assoc_chained; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 821 | int src_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 822 | bool src_chained; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 823 | int dst_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 824 | bool dst_chained; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 825 | dma_addr_t iv_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 826 | int sec4_sg_bytes; |
| 827 | dma_addr_t sec4_sg_dma; |
| 828 | struct sec4_sg_entry *sec4_sg; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 829 | u32 hw_desc[0]; |
| 830 | }; |
| 831 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 832 | /* |
| 833 | * ablkcipher_edesc - s/w-extended ablkcipher descriptor |
| 834 | * @src_nents: number of segments in input scatterlist |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 835 | * @src_chained: if source is chained |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 836 | * @dst_nents: number of segments in output scatterlist |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 837 | * @dst_chained: if destination is chained |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 838 | * @iv_dma: dma address of iv for checking continuity and link table |
| 839 | * @desc: h/w descriptor (variable length; must not exceed MAX_CAAM_DESCSIZE) |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 840 | * @sec4_sg_bytes: length of dma mapped sec4_sg space |
| 841 | * @sec4_sg_dma: bus physical mapped address of h/w link table |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 842 | * @hw_desc: the h/w job descriptor followed by any referenced link tables |
| 843 | */ |
| 844 | struct ablkcipher_edesc { |
| 845 | int src_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 846 | bool src_chained; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 847 | int dst_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 848 | bool dst_chained; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 849 | dma_addr_t iv_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 850 | int sec4_sg_bytes; |
| 851 | dma_addr_t sec4_sg_dma; |
| 852 | struct sec4_sg_entry *sec4_sg; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 853 | u32 hw_desc[0]; |
| 854 | }; |
| 855 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 856 | static void caam_unmap(struct device *dev, struct scatterlist *src, |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 857 | struct scatterlist *dst, int src_nents, |
| 858 | bool src_chained, int dst_nents, bool dst_chained, |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 859 | dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma, |
| 860 | int sec4_sg_bytes) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 861 | { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 862 | if (dst != src) { |
| 863 | dma_unmap_sg_chained(dev, src, src_nents ? : 1, DMA_TO_DEVICE, |
| 864 | src_chained); |
| 865 | dma_unmap_sg_chained(dev, dst, dst_nents ? : 1, DMA_FROM_DEVICE, |
| 866 | dst_chained); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 867 | } else { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 868 | dma_unmap_sg_chained(dev, src, src_nents ? : 1, |
| 869 | DMA_BIDIRECTIONAL, src_chained); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 870 | } |
| 871 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 872 | if (iv_dma) |
| 873 | dma_unmap_single(dev, iv_dma, ivsize, DMA_TO_DEVICE); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 874 | if (sec4_sg_bytes) |
| 875 | dma_unmap_single(dev, sec4_sg_dma, sec4_sg_bytes, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 876 | DMA_TO_DEVICE); |
| 877 | } |
| 878 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 879 | static void aead_unmap(struct device *dev, |
| 880 | struct aead_edesc *edesc, |
| 881 | struct aead_request *req) |
| 882 | { |
| 883 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 884 | int ivsize = crypto_aead_ivsize(aead); |
| 885 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 886 | dma_unmap_sg_chained(dev, req->assoc, edesc->assoc_nents, |
| 887 | DMA_TO_DEVICE, edesc->assoc_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 888 | |
| 889 | caam_unmap(dev, req->src, req->dst, |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 890 | edesc->src_nents, edesc->src_chained, edesc->dst_nents, |
| 891 | edesc->dst_chained, edesc->iv_dma, ivsize, |
| 892 | edesc->sec4_sg_dma, edesc->sec4_sg_bytes); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 893 | } |
| 894 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 895 | static void ablkcipher_unmap(struct device *dev, |
| 896 | struct ablkcipher_edesc *edesc, |
| 897 | struct ablkcipher_request *req) |
| 898 | { |
| 899 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 900 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); |
| 901 | |
| 902 | caam_unmap(dev, req->src, req->dst, |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 903 | edesc->src_nents, edesc->src_chained, edesc->dst_nents, |
| 904 | edesc->dst_chained, edesc->iv_dma, ivsize, |
| 905 | edesc->sec4_sg_dma, edesc->sec4_sg_bytes); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 906 | } |
| 907 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 908 | static void aead_encrypt_done(struct device *jrdev, u32 *desc, u32 err, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 909 | void *context) |
| 910 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 911 | struct aead_request *req = context; |
| 912 | struct aead_edesc *edesc; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 913 | #ifdef DEBUG |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 914 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 915 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 916 | int ivsize = crypto_aead_ivsize(aead); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 917 | |
| 918 | dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
| 919 | #endif |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 920 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 921 | edesc = (struct aead_edesc *)((char *)desc - |
| 922 | offsetof(struct aead_edesc, hw_desc)); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 923 | |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 924 | if (err) |
| 925 | caam_jr_strstatus(jrdev, err); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 926 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 927 | aead_unmap(jrdev, edesc, req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 928 | |
| 929 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 930 | print_hex_dump(KERN_ERR, "assoc @"__stringify(__LINE__)": ", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 931 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->assoc), |
| 932 | req->assoclen , 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 933 | print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 934 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src) - ivsize, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 935 | edesc->src_nents ? 100 : ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 936 | print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 937 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 938 | edesc->src_nents ? 100 : req->cryptlen + |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 939 | ctx->authsize + 4, 1); |
| 940 | #endif |
| 941 | |
| 942 | kfree(edesc); |
| 943 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 944 | aead_request_complete(req, err); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 945 | } |
| 946 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 947 | static void aead_decrypt_done(struct device *jrdev, u32 *desc, u32 err, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 948 | void *context) |
| 949 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 950 | struct aead_request *req = context; |
| 951 | struct aead_edesc *edesc; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 952 | #ifdef DEBUG |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 953 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 954 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 955 | int ivsize = crypto_aead_ivsize(aead); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 956 | |
| 957 | dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
| 958 | #endif |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 959 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 960 | edesc = (struct aead_edesc *)((char *)desc - |
| 961 | offsetof(struct aead_edesc, hw_desc)); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 962 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 963 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 964 | print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 965 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, |
| 966 | ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 967 | print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 968 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->dst), |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 969 | req->cryptlen - ctx->authsize, 1); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 970 | #endif |
| 971 | |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 972 | if (err) |
| 973 | caam_jr_strstatus(jrdev, err); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 974 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 975 | aead_unmap(jrdev, edesc, req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 976 | |
| 977 | /* |
| 978 | * verify hw auth check passed else return -EBADMSG |
| 979 | */ |
| 980 | if ((err & JRSTA_CCBERR_ERRID_MASK) == JRSTA_CCBERR_ERRID_ICVCHK) |
| 981 | err = -EBADMSG; |
| 982 | |
| 983 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 984 | print_hex_dump(KERN_ERR, "iphdrout@"__stringify(__LINE__)": ", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 985 | DUMP_PREFIX_ADDRESS, 16, 4, |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 986 | ((char *)sg_virt(req->assoc) - sizeof(struct iphdr)), |
| 987 | sizeof(struct iphdr) + req->assoclen + |
| 988 | ((req->cryptlen > 1500) ? 1500 : req->cryptlen) + |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 989 | ctx->authsize + 36, 1); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 990 | if (!err && edesc->sec4_sg_bytes) { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 991 | struct scatterlist *sg = sg_last(req->src, edesc->src_nents); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 992 | print_hex_dump(KERN_ERR, "sglastout@"__stringify(__LINE__)": ", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 993 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(sg), |
| 994 | sg->length + ctx->authsize + 16, 1); |
| 995 | } |
| 996 | #endif |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 997 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 998 | kfree(edesc); |
| 999 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1000 | aead_request_complete(req, err); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1003 | static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err, |
| 1004 | void *context) |
| 1005 | { |
| 1006 | struct ablkcipher_request *req = context; |
| 1007 | struct ablkcipher_edesc *edesc; |
| 1008 | #ifdef DEBUG |
| 1009 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1010 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); |
| 1011 | |
| 1012 | dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
| 1013 | #endif |
| 1014 | |
| 1015 | edesc = (struct ablkcipher_edesc *)((char *)desc - |
| 1016 | offsetof(struct ablkcipher_edesc, hw_desc)); |
| 1017 | |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 1018 | if (err) |
| 1019 | caam_jr_strstatus(jrdev, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1020 | |
| 1021 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1022 | print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1023 | DUMP_PREFIX_ADDRESS, 16, 4, req->info, |
| 1024 | edesc->src_nents > 1 ? 100 : ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1025 | print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1026 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1027 | edesc->dst_nents > 1 ? 100 : req->nbytes, 1); |
| 1028 | #endif |
| 1029 | |
| 1030 | ablkcipher_unmap(jrdev, edesc, req); |
| 1031 | kfree(edesc); |
| 1032 | |
| 1033 | ablkcipher_request_complete(req, err); |
| 1034 | } |
| 1035 | |
| 1036 | static void ablkcipher_decrypt_done(struct device *jrdev, u32 *desc, u32 err, |
| 1037 | void *context) |
| 1038 | { |
| 1039 | struct ablkcipher_request *req = context; |
| 1040 | struct ablkcipher_edesc *edesc; |
| 1041 | #ifdef DEBUG |
| 1042 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1043 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); |
| 1044 | |
| 1045 | dev_err(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); |
| 1046 | #endif |
| 1047 | |
| 1048 | edesc = (struct ablkcipher_edesc *)((char *)desc - |
| 1049 | offsetof(struct ablkcipher_edesc, hw_desc)); |
Marek Vasut | fa9659c | 2014-04-24 20:05:12 +0200 | [diff] [blame] | 1050 | if (err) |
| 1051 | caam_jr_strstatus(jrdev, err); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1052 | |
| 1053 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1054 | print_hex_dump(KERN_ERR, "dstiv @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1055 | DUMP_PREFIX_ADDRESS, 16, 4, req->info, |
| 1056 | ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1057 | print_hex_dump(KERN_ERR, "dst @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1058 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1059 | edesc->dst_nents > 1 ? 100 : req->nbytes, 1); |
| 1060 | #endif |
| 1061 | |
| 1062 | ablkcipher_unmap(jrdev, edesc, req); |
| 1063 | kfree(edesc); |
| 1064 | |
| 1065 | ablkcipher_request_complete(req, err); |
| 1066 | } |
| 1067 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1068 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1069 | * Fill in aead job descriptor |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1070 | */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1071 | static void init_aead_job(u32 *sh_desc, dma_addr_t ptr, |
| 1072 | struct aead_edesc *edesc, |
| 1073 | struct aead_request *req, |
| 1074 | bool all_contig, bool encrypt) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1075 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1076 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1077 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1078 | int ivsize = crypto_aead_ivsize(aead); |
| 1079 | int authsize = ctx->authsize; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1080 | u32 *desc = edesc->hw_desc; |
| 1081 | u32 out_options = 0, in_options; |
| 1082 | dma_addr_t dst_dma, src_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1083 | int len, sec4_sg_index = 0; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1084 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1085 | #ifdef DEBUG |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1086 | debug("assoclen %d cryptlen %d authsize %d\n", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1087 | req->assoclen, req->cryptlen, authsize); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1088 | print_hex_dump(KERN_ERR, "assoc @"__stringify(__LINE__)": ", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1089 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->assoc), |
| 1090 | req->assoclen , 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1091 | print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1092 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1093 | edesc->src_nents ? 100 : ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1094 | print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ", |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1095 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1096 | edesc->src_nents ? 100 : req->cryptlen, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1097 | print_hex_dump(KERN_ERR, "shrdesc@"__stringify(__LINE__)": ", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1098 | DUMP_PREFIX_ADDRESS, 16, 4, sh_desc, |
| 1099 | desc_bytes(sh_desc), 1); |
| 1100 | #endif |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1101 | |
| 1102 | len = desc_len(sh_desc); |
| 1103 | init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); |
| 1104 | |
| 1105 | if (all_contig) { |
| 1106 | src_dma = sg_dma_address(req->assoc); |
| 1107 | in_options = 0; |
| 1108 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1109 | src_dma = edesc->sec4_sg_dma; |
| 1110 | sec4_sg_index += (edesc->assoc_nents ? : 1) + 1 + |
| 1111 | (edesc->src_nents ? : 1); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1112 | in_options = LDST_SGF; |
| 1113 | } |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1114 | |
| 1115 | append_seq_in_ptr(desc, src_dma, req->assoclen + ivsize + req->cryptlen, |
| 1116 | in_options); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1117 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1118 | if (likely(req->src == req->dst)) { |
| 1119 | if (all_contig) { |
| 1120 | dst_dma = sg_dma_address(req->src); |
| 1121 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1122 | dst_dma = src_dma + sizeof(struct sec4_sg_entry) * |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1123 | ((edesc->assoc_nents ? : 1) + 1); |
| 1124 | out_options = LDST_SGF; |
| 1125 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1126 | } else { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1127 | if (!edesc->dst_nents) { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1128 | dst_dma = sg_dma_address(req->dst); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1129 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1130 | dst_dma = edesc->sec4_sg_dma + |
| 1131 | sec4_sg_index * |
| 1132 | sizeof(struct sec4_sg_entry); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1133 | out_options = LDST_SGF; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1134 | } |
| 1135 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1136 | if (encrypt) |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1137 | append_seq_out_ptr(desc, dst_dma, req->cryptlen + authsize, |
| 1138 | out_options); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1139 | else |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1140 | append_seq_out_ptr(desc, dst_dma, req->cryptlen - authsize, |
| 1141 | out_options); |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | * Fill in aead givencrypt job descriptor |
| 1146 | */ |
| 1147 | static void init_aead_giv_job(u32 *sh_desc, dma_addr_t ptr, |
| 1148 | struct aead_edesc *edesc, |
| 1149 | struct aead_request *req, |
| 1150 | int contig) |
| 1151 | { |
| 1152 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1153 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1154 | int ivsize = crypto_aead_ivsize(aead); |
| 1155 | int authsize = ctx->authsize; |
| 1156 | u32 *desc = edesc->hw_desc; |
| 1157 | u32 out_options = 0, in_options; |
| 1158 | dma_addr_t dst_dma, src_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1159 | int len, sec4_sg_index = 0; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1160 | |
| 1161 | #ifdef DEBUG |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1162 | debug("assoclen %d cryptlen %d authsize %d\n", |
| 1163 | req->assoclen, req->cryptlen, authsize); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1164 | print_hex_dump(KERN_ERR, "assoc @"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1165 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->assoc), |
| 1166 | req->assoclen , 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1167 | print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1168 | DUMP_PREFIX_ADDRESS, 16, 4, req->iv, ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1169 | print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1170 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1171 | edesc->src_nents > 1 ? 100 : req->cryptlen, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1172 | print_hex_dump(KERN_ERR, "shrdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1173 | DUMP_PREFIX_ADDRESS, 16, 4, sh_desc, |
| 1174 | desc_bytes(sh_desc), 1); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1175 | #endif |
| 1176 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1177 | len = desc_len(sh_desc); |
| 1178 | init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); |
| 1179 | |
| 1180 | if (contig & GIV_SRC_CONTIG) { |
| 1181 | src_dma = sg_dma_address(req->assoc); |
| 1182 | in_options = 0; |
| 1183 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1184 | src_dma = edesc->sec4_sg_dma; |
| 1185 | sec4_sg_index += edesc->assoc_nents + 1 + edesc->src_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1186 | in_options = LDST_SGF; |
| 1187 | } |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1188 | append_seq_in_ptr(desc, src_dma, req->assoclen + ivsize + req->cryptlen, |
| 1189 | in_options); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1190 | |
| 1191 | if (contig & GIV_DST_CONTIG) { |
| 1192 | dst_dma = edesc->iv_dma; |
| 1193 | } else { |
| 1194 | if (likely(req->src == req->dst)) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1195 | dst_dma = src_dma + sizeof(struct sec4_sg_entry) * |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1196 | edesc->assoc_nents; |
| 1197 | out_options = LDST_SGF; |
| 1198 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1199 | dst_dma = edesc->sec4_sg_dma + |
| 1200 | sec4_sg_index * |
| 1201 | sizeof(struct sec4_sg_entry); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1202 | out_options = LDST_SGF; |
| 1203 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1204 | } |
| 1205 | |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1206 | append_seq_out_ptr(desc, dst_dma, ivsize + req->cryptlen + authsize, |
| 1207 | out_options); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /* |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1211 | * Fill in ablkcipher job descriptor |
| 1212 | */ |
| 1213 | static void init_ablkcipher_job(u32 *sh_desc, dma_addr_t ptr, |
| 1214 | struct ablkcipher_edesc *edesc, |
| 1215 | struct ablkcipher_request *req, |
| 1216 | bool iv_contig) |
| 1217 | { |
| 1218 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1219 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); |
| 1220 | u32 *desc = edesc->hw_desc; |
| 1221 | u32 out_options = 0, in_options; |
| 1222 | dma_addr_t dst_dma, src_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1223 | int len, sec4_sg_index = 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1224 | |
| 1225 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1226 | print_hex_dump(KERN_ERR, "presciv@"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1227 | DUMP_PREFIX_ADDRESS, 16, 4, req->info, |
| 1228 | ivsize, 1); |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1229 | print_hex_dump(KERN_ERR, "src @"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1230 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1231 | edesc->src_nents ? 100 : req->nbytes, 1); |
| 1232 | #endif |
| 1233 | |
| 1234 | len = desc_len(sh_desc); |
| 1235 | init_job_desc_shared(desc, ptr, len, HDR_SHARE_DEFER | HDR_REVERSE); |
| 1236 | |
| 1237 | if (iv_contig) { |
| 1238 | src_dma = edesc->iv_dma; |
| 1239 | in_options = 0; |
| 1240 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1241 | src_dma = edesc->sec4_sg_dma; |
| 1242 | sec4_sg_index += (iv_contig ? 0 : 1) + edesc->src_nents; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1243 | in_options = LDST_SGF; |
| 1244 | } |
| 1245 | append_seq_in_ptr(desc, src_dma, req->nbytes + ivsize, in_options); |
| 1246 | |
| 1247 | if (likely(req->src == req->dst)) { |
| 1248 | if (!edesc->src_nents && iv_contig) { |
| 1249 | dst_dma = sg_dma_address(req->src); |
| 1250 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1251 | dst_dma = edesc->sec4_sg_dma + |
| 1252 | sizeof(struct sec4_sg_entry); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1253 | out_options = LDST_SGF; |
| 1254 | } |
| 1255 | } else { |
| 1256 | if (!edesc->dst_nents) { |
| 1257 | dst_dma = sg_dma_address(req->dst); |
| 1258 | } else { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1259 | dst_dma = edesc->sec4_sg_dma + |
| 1260 | sec4_sg_index * sizeof(struct sec4_sg_entry); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1261 | out_options = LDST_SGF; |
| 1262 | } |
| 1263 | } |
| 1264 | append_seq_out_ptr(desc, dst_dma, req->nbytes, out_options); |
| 1265 | } |
| 1266 | |
| 1267 | /* |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1268 | * allocate and map the aead extended descriptor |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1269 | */ |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1270 | static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1271 | int desc_bytes, bool *all_contig_ptr, |
| 1272 | bool encrypt) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1273 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1274 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1275 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1276 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1277 | gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | |
| 1278 | CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC; |
| 1279 | int assoc_nents, src_nents, dst_nents = 0; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1280 | struct aead_edesc *edesc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1281 | dma_addr_t iv_dma = 0; |
| 1282 | int sgc; |
| 1283 | bool all_contig = true; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1284 | bool assoc_chained = false, src_chained = false, dst_chained = false; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1285 | int ivsize = crypto_aead_ivsize(aead); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1286 | int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes; |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1287 | unsigned int authsize = ctx->authsize; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1288 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1289 | assoc_nents = sg_count(req->assoc, req->assoclen, &assoc_chained); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1290 | |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1291 | if (unlikely(req->dst != req->src)) { |
| 1292 | src_nents = sg_count(req->src, req->cryptlen, &src_chained); |
| 1293 | dst_nents = sg_count(req->dst, |
| 1294 | req->cryptlen + |
| 1295 | (encrypt ? authsize : (-authsize)), |
| 1296 | &dst_chained); |
| 1297 | } else { |
| 1298 | src_nents = sg_count(req->src, |
| 1299 | req->cryptlen + |
| 1300 | (encrypt ? authsize : 0), |
| 1301 | &src_chained); |
| 1302 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1303 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1304 | sgc = dma_map_sg_chained(jrdev, req->assoc, assoc_nents ? : 1, |
Horia Geanta | 286233e | 2013-05-10 15:08:39 +0300 | [diff] [blame] | 1305 | DMA_TO_DEVICE, assoc_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1306 | if (likely(req->src == req->dst)) { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1307 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1308 | DMA_BIDIRECTIONAL, src_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1309 | } else { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1310 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1311 | DMA_TO_DEVICE, src_chained); |
| 1312 | sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1, |
| 1313 | DMA_FROM_DEVICE, dst_chained); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1316 | iv_dma = dma_map_single(jrdev, req->iv, ivsize, DMA_TO_DEVICE); |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1317 | if (dma_mapping_error(jrdev, iv_dma)) { |
| 1318 | dev_err(jrdev, "unable to map IV\n"); |
| 1319 | return ERR_PTR(-ENOMEM); |
| 1320 | } |
| 1321 | |
| 1322 | /* Check if data are contiguous */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1323 | if (assoc_nents || sg_dma_address(req->assoc) + req->assoclen != |
| 1324 | iv_dma || src_nents || iv_dma + ivsize != |
| 1325 | sg_dma_address(req->src)) { |
| 1326 | all_contig = false; |
| 1327 | assoc_nents = assoc_nents ? : 1; |
| 1328 | src_nents = src_nents ? : 1; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1329 | sec4_sg_len = assoc_nents + 1 + src_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1330 | } |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1331 | sec4_sg_len += dst_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1332 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1333 | sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1334 | |
| 1335 | /* allocate space for base edesc and hw desc commands, link tables */ |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1336 | edesc = kmalloc(sizeof(struct aead_edesc) + desc_bytes + |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1337 | sec4_sg_bytes, GFP_DMA | flags); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1338 | if (!edesc) { |
| 1339 | dev_err(jrdev, "could not allocate extended descriptor\n"); |
| 1340 | return ERR_PTR(-ENOMEM); |
| 1341 | } |
| 1342 | |
| 1343 | edesc->assoc_nents = assoc_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1344 | edesc->assoc_chained = assoc_chained; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1345 | edesc->src_nents = src_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1346 | edesc->src_chained = src_chained; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1347 | edesc->dst_nents = dst_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1348 | edesc->dst_chained = dst_chained; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1349 | edesc->iv_dma = iv_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1350 | edesc->sec4_sg_bytes = sec4_sg_bytes; |
| 1351 | edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) + |
| 1352 | desc_bytes; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1353 | *all_contig_ptr = all_contig; |
| 1354 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1355 | sec4_sg_index = 0; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1356 | if (!all_contig) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1357 | sg_to_sec4_sg(req->assoc, |
| 1358 | (assoc_nents ? : 1), |
| 1359 | edesc->sec4_sg + |
| 1360 | sec4_sg_index, 0); |
| 1361 | sec4_sg_index += assoc_nents ? : 1; |
| 1362 | dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index, |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1363 | iv_dma, ivsize, 0); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1364 | sec4_sg_index += 1; |
| 1365 | sg_to_sec4_sg_last(req->src, |
| 1366 | (src_nents ? : 1), |
| 1367 | edesc->sec4_sg + |
| 1368 | sec4_sg_index, 0); |
| 1369 | sec4_sg_index += src_nents ? : 1; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1370 | } |
| 1371 | if (dst_nents) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1372 | sg_to_sec4_sg_last(req->dst, dst_nents, |
| 1373 | edesc->sec4_sg + sec4_sg_index, 0); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1374 | } |
Ruchika Gupta | 1da2be3 | 2014-06-23 19:50:26 +0530 | [diff] [blame] | 1375 | edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, |
| 1376 | sec4_sg_bytes, DMA_TO_DEVICE); |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1377 | if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) { |
| 1378 | dev_err(jrdev, "unable to map S/G table\n"); |
| 1379 | return ERR_PTR(-ENOMEM); |
| 1380 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1381 | |
| 1382 | return edesc; |
| 1383 | } |
| 1384 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1385 | static int aead_encrypt(struct aead_request *req) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1386 | { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1387 | struct aead_edesc *edesc; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1388 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1389 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1390 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1391 | bool all_contig; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1392 | u32 *desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1393 | int ret = 0; |
| 1394 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1395 | /* allocate extended descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1396 | edesc = aead_edesc_alloc(req, DESC_JOB_IO_LEN * |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1397 | CAAM_CMD_SZ, &all_contig, true); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1398 | if (IS_ERR(edesc)) |
| 1399 | return PTR_ERR(edesc); |
| 1400 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1401 | /* Create and submit job descriptor */ |
| 1402 | init_aead_job(ctx->sh_desc_enc, ctx->sh_desc_enc_dma, edesc, req, |
| 1403 | all_contig, true); |
| 1404 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1405 | print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1406 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1407 | desc_bytes(edesc->hw_desc), 1); |
| 1408 | #endif |
| 1409 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1410 | desc = edesc->hw_desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1411 | ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req); |
| 1412 | if (!ret) { |
| 1413 | ret = -EINPROGRESS; |
| 1414 | } else { |
| 1415 | aead_unmap(jrdev, edesc, req); |
| 1416 | kfree(edesc); |
| 1417 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1418 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1419 | return ret; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1420 | } |
| 1421 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1422 | static int aead_decrypt(struct aead_request *req) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1423 | { |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1424 | struct aead_edesc *edesc; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1425 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1426 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1427 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1428 | bool all_contig; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1429 | u32 *desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1430 | int ret = 0; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1431 | |
| 1432 | /* allocate extended descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1433 | edesc = aead_edesc_alloc(req, DESC_JOB_IO_LEN * |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1434 | CAAM_CMD_SZ, &all_contig, false); |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1435 | if (IS_ERR(edesc)) |
| 1436 | return PTR_ERR(edesc); |
| 1437 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1438 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1439 | print_hex_dump(KERN_ERR, "dec src@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1440 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1441 | req->cryptlen, 1); |
| 1442 | #endif |
| 1443 | |
| 1444 | /* Create and submit job descriptor*/ |
| 1445 | init_aead_job(ctx->sh_desc_dec, |
| 1446 | ctx->sh_desc_dec_dma, edesc, req, all_contig, false); |
| 1447 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1448 | print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1449 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1450 | desc_bytes(edesc->hw_desc), 1); |
| 1451 | #endif |
| 1452 | |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1453 | desc = edesc->hw_desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1454 | ret = caam_jr_enqueue(jrdev, desc, aead_decrypt_done, req); |
| 1455 | if (!ret) { |
| 1456 | ret = -EINPROGRESS; |
| 1457 | } else { |
| 1458 | aead_unmap(jrdev, edesc, req); |
| 1459 | kfree(edesc); |
| 1460 | } |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1461 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1462 | return ret; |
| 1463 | } |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1464 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1465 | /* |
| 1466 | * allocate and map the aead extended descriptor for aead givencrypt |
| 1467 | */ |
| 1468 | static struct aead_edesc *aead_giv_edesc_alloc(struct aead_givcrypt_request |
| 1469 | *greq, int desc_bytes, |
| 1470 | u32 *contig_ptr) |
| 1471 | { |
| 1472 | struct aead_request *req = &greq->areq; |
| 1473 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
| 1474 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1475 | struct device *jrdev = ctx->jrdev; |
| 1476 | gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | |
| 1477 | CRYPTO_TFM_REQ_MAY_SLEEP)) ? GFP_KERNEL : GFP_ATOMIC; |
| 1478 | int assoc_nents, src_nents, dst_nents = 0; |
| 1479 | struct aead_edesc *edesc; |
| 1480 | dma_addr_t iv_dma = 0; |
| 1481 | int sgc; |
| 1482 | u32 contig = GIV_SRC_CONTIG | GIV_DST_CONTIG; |
| 1483 | int ivsize = crypto_aead_ivsize(aead); |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1484 | bool assoc_chained = false, src_chained = false, dst_chained = false; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1485 | int sec4_sg_index, sec4_sg_len = 0, sec4_sg_bytes; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1486 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1487 | assoc_nents = sg_count(req->assoc, req->assoclen, &assoc_chained); |
| 1488 | src_nents = sg_count(req->src, req->cryptlen, &src_chained); |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1489 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1490 | if (unlikely(req->dst != req->src)) |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1491 | dst_nents = sg_count(req->dst, req->cryptlen + ctx->authsize, |
| 1492 | &dst_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1493 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1494 | sgc = dma_map_sg_chained(jrdev, req->assoc, assoc_nents ? : 1, |
Horia Geanta | 286233e | 2013-05-10 15:08:39 +0300 | [diff] [blame] | 1495 | DMA_TO_DEVICE, assoc_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1496 | if (likely(req->src == req->dst)) { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1497 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1498 | DMA_BIDIRECTIONAL, src_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1499 | } else { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1500 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1501 | DMA_TO_DEVICE, src_chained); |
| 1502 | sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1, |
| 1503 | DMA_FROM_DEVICE, dst_chained); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1504 | } |
| 1505 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1506 | iv_dma = dma_map_single(jrdev, greq->giv, ivsize, DMA_TO_DEVICE); |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1507 | if (dma_mapping_error(jrdev, iv_dma)) { |
| 1508 | dev_err(jrdev, "unable to map IV\n"); |
| 1509 | return ERR_PTR(-ENOMEM); |
| 1510 | } |
| 1511 | |
| 1512 | /* Check if data are contiguous */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1513 | if (assoc_nents || sg_dma_address(req->assoc) + req->assoclen != |
| 1514 | iv_dma || src_nents || iv_dma + ivsize != sg_dma_address(req->src)) |
| 1515 | contig &= ~GIV_SRC_CONTIG; |
| 1516 | if (dst_nents || iv_dma + ivsize != sg_dma_address(req->dst)) |
| 1517 | contig &= ~GIV_DST_CONTIG; |
Kim Phillips | 2af8f4a | 2012-09-07 04:17:03 +0800 | [diff] [blame] | 1518 | if (unlikely(req->src != req->dst)) { |
| 1519 | dst_nents = dst_nents ? : 1; |
| 1520 | sec4_sg_len += 1; |
| 1521 | } |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1522 | if (!(contig & GIV_SRC_CONTIG)) { |
| 1523 | assoc_nents = assoc_nents ? : 1; |
| 1524 | src_nents = src_nents ? : 1; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1525 | sec4_sg_len += assoc_nents + 1 + src_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1526 | if (likely(req->src == req->dst)) |
| 1527 | contig &= ~GIV_DST_CONTIG; |
| 1528 | } |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1529 | sec4_sg_len += dst_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1530 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1531 | sec4_sg_bytes = sec4_sg_len * sizeof(struct sec4_sg_entry); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1532 | |
| 1533 | /* allocate space for base edesc and hw desc commands, link tables */ |
| 1534 | edesc = kmalloc(sizeof(struct aead_edesc) + desc_bytes + |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1535 | sec4_sg_bytes, GFP_DMA | flags); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1536 | if (!edesc) { |
| 1537 | dev_err(jrdev, "could not allocate extended descriptor\n"); |
| 1538 | return ERR_PTR(-ENOMEM); |
| 1539 | } |
| 1540 | |
| 1541 | edesc->assoc_nents = assoc_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1542 | edesc->assoc_chained = assoc_chained; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1543 | edesc->src_nents = src_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1544 | edesc->src_chained = src_chained; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1545 | edesc->dst_nents = dst_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1546 | edesc->dst_chained = dst_chained; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1547 | edesc->iv_dma = iv_dma; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1548 | edesc->sec4_sg_bytes = sec4_sg_bytes; |
| 1549 | edesc->sec4_sg = (void *)edesc + sizeof(struct aead_edesc) + |
| 1550 | desc_bytes; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1551 | *contig_ptr = contig; |
| 1552 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1553 | sec4_sg_index = 0; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1554 | if (!(contig & GIV_SRC_CONTIG)) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1555 | sg_to_sec4_sg(req->assoc, assoc_nents, |
| 1556 | edesc->sec4_sg + |
| 1557 | sec4_sg_index, 0); |
| 1558 | sec4_sg_index += assoc_nents; |
| 1559 | dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index, |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1560 | iv_dma, ivsize, 0); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1561 | sec4_sg_index += 1; |
| 1562 | sg_to_sec4_sg_last(req->src, src_nents, |
| 1563 | edesc->sec4_sg + |
| 1564 | sec4_sg_index, 0); |
| 1565 | sec4_sg_index += src_nents; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1566 | } |
| 1567 | if (unlikely(req->src != req->dst && !(contig & GIV_DST_CONTIG))) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1568 | dma_to_sec4_sg_one(edesc->sec4_sg + sec4_sg_index, |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1569 | iv_dma, ivsize, 0); |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1570 | sec4_sg_index += 1; |
| 1571 | sg_to_sec4_sg_last(req->dst, dst_nents, |
| 1572 | edesc->sec4_sg + sec4_sg_index, 0); |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1573 | } |
Ruchika Gupta | 1da2be3 | 2014-06-23 19:50:26 +0530 | [diff] [blame] | 1574 | edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, |
| 1575 | sec4_sg_bytes, DMA_TO_DEVICE); |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1576 | if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) { |
| 1577 | dev_err(jrdev, "unable to map S/G table\n"); |
| 1578 | return ERR_PTR(-ENOMEM); |
| 1579 | } |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1580 | |
| 1581 | return edesc; |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | static int aead_givencrypt(struct aead_givcrypt_request *areq) |
| 1585 | { |
| 1586 | struct aead_request *req = &areq->areq; |
| 1587 | struct aead_edesc *edesc; |
| 1588 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1589 | struct caam_ctx *ctx = crypto_aead_ctx(aead); |
| 1590 | struct device *jrdev = ctx->jrdev; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1591 | u32 contig; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1592 | u32 *desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1593 | int ret = 0; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1594 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1595 | /* allocate extended descriptor */ |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1596 | edesc = aead_giv_edesc_alloc(areq, DESC_JOB_IO_LEN * |
| 1597 | CAAM_CMD_SZ, &contig); |
| 1598 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1599 | if (IS_ERR(edesc)) |
| 1600 | return PTR_ERR(edesc); |
| 1601 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1602 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1603 | print_hex_dump(KERN_ERR, "giv src@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1604 | DUMP_PREFIX_ADDRESS, 16, 4, sg_virt(req->src), |
| 1605 | req->cryptlen, 1); |
| 1606 | #endif |
| 1607 | |
| 1608 | /* Create and submit job descriptor*/ |
| 1609 | init_aead_giv_job(ctx->sh_desc_givenc, |
| 1610 | ctx->sh_desc_givenc_dma, edesc, req, contig); |
| 1611 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1612 | print_hex_dump(KERN_ERR, "aead jobdesc@"__stringify(__LINE__)": ", |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1613 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1614 | desc_bytes(edesc->hw_desc), 1); |
| 1615 | #endif |
| 1616 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1617 | desc = edesc->hw_desc; |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1618 | ret = caam_jr_enqueue(jrdev, desc, aead_encrypt_done, req); |
| 1619 | if (!ret) { |
| 1620 | ret = -EINPROGRESS; |
| 1621 | } else { |
| 1622 | aead_unmap(jrdev, edesc, req); |
| 1623 | kfree(edesc); |
| 1624 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1625 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1626 | return ret; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1627 | } |
| 1628 | |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 1629 | static int aead_null_givencrypt(struct aead_givcrypt_request *areq) |
| 1630 | { |
| 1631 | return aead_encrypt(&areq->areq); |
| 1632 | } |
| 1633 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1634 | /* |
| 1635 | * allocate and map the ablkcipher extended descriptor for ablkcipher |
| 1636 | */ |
| 1637 | static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request |
| 1638 | *req, int desc_bytes, |
| 1639 | bool *iv_contig_out) |
| 1640 | { |
| 1641 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1642 | struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); |
| 1643 | struct device *jrdev = ctx->jrdev; |
| 1644 | gfp_t flags = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | |
| 1645 | CRYPTO_TFM_REQ_MAY_SLEEP)) ? |
| 1646 | GFP_KERNEL : GFP_ATOMIC; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1647 | int src_nents, dst_nents = 0, sec4_sg_bytes; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1648 | struct ablkcipher_edesc *edesc; |
| 1649 | dma_addr_t iv_dma = 0; |
| 1650 | bool iv_contig = false; |
| 1651 | int sgc; |
| 1652 | int ivsize = crypto_ablkcipher_ivsize(ablkcipher); |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1653 | bool src_chained = false, dst_chained = false; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1654 | int sec4_sg_index; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1655 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1656 | src_nents = sg_count(req->src, req->nbytes, &src_chained); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1657 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1658 | if (req->dst != req->src) |
| 1659 | dst_nents = sg_count(req->dst, req->nbytes, &dst_chained); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1660 | |
| 1661 | if (likely(req->src == req->dst)) { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1662 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1663 | DMA_BIDIRECTIONAL, src_chained); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1664 | } else { |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1665 | sgc = dma_map_sg_chained(jrdev, req->src, src_nents ? : 1, |
| 1666 | DMA_TO_DEVICE, src_chained); |
| 1667 | sgc = dma_map_sg_chained(jrdev, req->dst, dst_nents ? : 1, |
| 1668 | DMA_FROM_DEVICE, dst_chained); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1669 | } |
| 1670 | |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1671 | iv_dma = dma_map_single(jrdev, req->info, ivsize, DMA_TO_DEVICE); |
| 1672 | if (dma_mapping_error(jrdev, iv_dma)) { |
| 1673 | dev_err(jrdev, "unable to map IV\n"); |
| 1674 | return ERR_PTR(-ENOMEM); |
| 1675 | } |
| 1676 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1677 | /* |
| 1678 | * Check if iv can be contiguous with source and destination. |
| 1679 | * If so, include it. If not, create scatterlist. |
| 1680 | */ |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1681 | if (!src_nents && iv_dma + ivsize == sg_dma_address(req->src)) |
| 1682 | iv_contig = true; |
| 1683 | else |
| 1684 | src_nents = src_nents ? : 1; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1685 | sec4_sg_bytes = ((iv_contig ? 0 : 1) + src_nents + dst_nents) * |
| 1686 | sizeof(struct sec4_sg_entry); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1687 | |
| 1688 | /* allocate space for base edesc and hw desc commands, link tables */ |
| 1689 | edesc = kmalloc(sizeof(struct ablkcipher_edesc) + desc_bytes + |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1690 | sec4_sg_bytes, GFP_DMA | flags); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1691 | if (!edesc) { |
| 1692 | dev_err(jrdev, "could not allocate extended descriptor\n"); |
| 1693 | return ERR_PTR(-ENOMEM); |
| 1694 | } |
| 1695 | |
| 1696 | edesc->src_nents = src_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1697 | edesc->src_chained = src_chained; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1698 | edesc->dst_nents = dst_nents; |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1699 | edesc->dst_chained = dst_chained; |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1700 | edesc->sec4_sg_bytes = sec4_sg_bytes; |
| 1701 | edesc->sec4_sg = (void *)edesc + sizeof(struct ablkcipher_edesc) + |
| 1702 | desc_bytes; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1703 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1704 | sec4_sg_index = 0; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1705 | if (!iv_contig) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1706 | dma_to_sec4_sg_one(edesc->sec4_sg, iv_dma, ivsize, 0); |
| 1707 | sg_to_sec4_sg_last(req->src, src_nents, |
| 1708 | edesc->sec4_sg + 1, 0); |
| 1709 | sec4_sg_index += 1 + src_nents; |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1710 | } |
| 1711 | |
Yuan Kang | 643b39b | 2012-06-22 19:48:49 -0500 | [diff] [blame] | 1712 | if (dst_nents) { |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1713 | sg_to_sec4_sg_last(req->dst, dst_nents, |
| 1714 | edesc->sec4_sg + sec4_sg_index, 0); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1715 | } |
| 1716 | |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1717 | edesc->sec4_sg_dma = dma_map_single(jrdev, edesc->sec4_sg, |
| 1718 | sec4_sg_bytes, DMA_TO_DEVICE); |
Horia Geanta | ce57208 | 2014-07-11 15:34:49 +0300 | [diff] [blame] | 1719 | if (dma_mapping_error(jrdev, edesc->sec4_sg_dma)) { |
| 1720 | dev_err(jrdev, "unable to map S/G table\n"); |
| 1721 | return ERR_PTR(-ENOMEM); |
| 1722 | } |
| 1723 | |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1724 | edesc->iv_dma = iv_dma; |
| 1725 | |
| 1726 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1727 | print_hex_dump(KERN_ERR, "ablkcipher sec4_sg@"__stringify(__LINE__)": ", |
Yuan Kang | a299c83 | 2012-06-22 19:48:46 -0500 | [diff] [blame] | 1728 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->sec4_sg, |
| 1729 | sec4_sg_bytes, 1); |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1730 | #endif |
| 1731 | |
| 1732 | *iv_contig_out = iv_contig; |
| 1733 | return edesc; |
| 1734 | } |
| 1735 | |
| 1736 | static int ablkcipher_encrypt(struct ablkcipher_request *req) |
| 1737 | { |
| 1738 | struct ablkcipher_edesc *edesc; |
| 1739 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1740 | struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); |
| 1741 | struct device *jrdev = ctx->jrdev; |
| 1742 | bool iv_contig; |
| 1743 | u32 *desc; |
| 1744 | int ret = 0; |
| 1745 | |
| 1746 | /* allocate extended descriptor */ |
| 1747 | edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN * |
| 1748 | CAAM_CMD_SZ, &iv_contig); |
| 1749 | if (IS_ERR(edesc)) |
| 1750 | return PTR_ERR(edesc); |
| 1751 | |
| 1752 | /* Create and submit job descriptor*/ |
| 1753 | init_ablkcipher_job(ctx->sh_desc_enc, |
| 1754 | ctx->sh_desc_enc_dma, edesc, req, iv_contig); |
| 1755 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1756 | print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1757 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1758 | desc_bytes(edesc->hw_desc), 1); |
| 1759 | #endif |
| 1760 | desc = edesc->hw_desc; |
| 1761 | ret = caam_jr_enqueue(jrdev, desc, ablkcipher_encrypt_done, req); |
| 1762 | |
| 1763 | if (!ret) { |
| 1764 | ret = -EINPROGRESS; |
| 1765 | } else { |
| 1766 | ablkcipher_unmap(jrdev, edesc, req); |
| 1767 | kfree(edesc); |
| 1768 | } |
| 1769 | |
| 1770 | return ret; |
| 1771 | } |
| 1772 | |
| 1773 | static int ablkcipher_decrypt(struct ablkcipher_request *req) |
| 1774 | { |
| 1775 | struct ablkcipher_edesc *edesc; |
| 1776 | struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); |
| 1777 | struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); |
| 1778 | struct device *jrdev = ctx->jrdev; |
| 1779 | bool iv_contig; |
| 1780 | u32 *desc; |
| 1781 | int ret = 0; |
| 1782 | |
| 1783 | /* allocate extended descriptor */ |
| 1784 | edesc = ablkcipher_edesc_alloc(req, DESC_JOB_IO_LEN * |
| 1785 | CAAM_CMD_SZ, &iv_contig); |
| 1786 | if (IS_ERR(edesc)) |
| 1787 | return PTR_ERR(edesc); |
| 1788 | |
| 1789 | /* Create and submit job descriptor*/ |
| 1790 | init_ablkcipher_job(ctx->sh_desc_dec, |
| 1791 | ctx->sh_desc_dec_dma, edesc, req, iv_contig); |
| 1792 | desc = edesc->hw_desc; |
| 1793 | #ifdef DEBUG |
Alex Porosanu | 514df28 | 2013-08-14 18:56:45 +0300 | [diff] [blame] | 1794 | print_hex_dump(KERN_ERR, "ablkcipher jobdesc@"__stringify(__LINE__)": ", |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1795 | DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, |
| 1796 | desc_bytes(edesc->hw_desc), 1); |
| 1797 | #endif |
| 1798 | |
| 1799 | ret = caam_jr_enqueue(jrdev, desc, ablkcipher_decrypt_done, req); |
| 1800 | if (!ret) { |
| 1801 | ret = -EINPROGRESS; |
| 1802 | } else { |
| 1803 | ablkcipher_unmap(jrdev, edesc, req); |
| 1804 | kfree(edesc); |
| 1805 | } |
| 1806 | |
| 1807 | return ret; |
| 1808 | } |
| 1809 | |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1810 | #define template_aead template_u.aead |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 1811 | #define template_ablkcipher template_u.ablkcipher |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1812 | struct caam_alg_template { |
| 1813 | char name[CRYPTO_MAX_ALG_NAME]; |
| 1814 | char driver_name[CRYPTO_MAX_ALG_NAME]; |
| 1815 | unsigned int blocksize; |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1816 | u32 type; |
| 1817 | union { |
| 1818 | struct ablkcipher_alg ablkcipher; |
| 1819 | struct aead_alg aead; |
| 1820 | struct blkcipher_alg blkcipher; |
| 1821 | struct cipher_alg cipher; |
| 1822 | struct compress_alg compress; |
| 1823 | struct rng_alg rng; |
| 1824 | } template_u; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1825 | u32 class1_alg_type; |
| 1826 | u32 class2_alg_type; |
| 1827 | u32 alg_op; |
| 1828 | }; |
| 1829 | |
| 1830 | static struct caam_alg_template driver_algs[] = { |
Horia Geanta | 246bbed | 2013-03-20 16:31:58 +0200 | [diff] [blame] | 1831 | /* single-pass ipsec_esp descriptor */ |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1832 | { |
Horia Geanta | ae4a825 | 2014-03-14 17:46:52 +0200 | [diff] [blame] | 1833 | .name = "authenc(hmac(md5),ecb(cipher_null))", |
| 1834 | .driver_name = "authenc-hmac-md5-ecb-cipher_null-caam", |
| 1835 | .blocksize = NULL_BLOCK_SIZE, |
| 1836 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1837 | .template_aead = { |
| 1838 | .setkey = aead_setkey, |
| 1839 | .setauthsize = aead_setauthsize, |
| 1840 | .encrypt = aead_encrypt, |
| 1841 | .decrypt = aead_decrypt, |
| 1842 | .givencrypt = aead_null_givencrypt, |
| 1843 | .geniv = "<built-in>", |
| 1844 | .ivsize = NULL_IV_SIZE, |
| 1845 | .maxauthsize = MD5_DIGEST_SIZE, |
| 1846 | }, |
| 1847 | .class1_alg_type = 0, |
| 1848 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1849 | .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC, |
| 1850 | }, |
| 1851 | { |
| 1852 | .name = "authenc(hmac(sha1),ecb(cipher_null))", |
| 1853 | .driver_name = "authenc-hmac-sha1-ecb-cipher_null-caam", |
| 1854 | .blocksize = NULL_BLOCK_SIZE, |
| 1855 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1856 | .template_aead = { |
| 1857 | .setkey = aead_setkey, |
| 1858 | .setauthsize = aead_setauthsize, |
| 1859 | .encrypt = aead_encrypt, |
| 1860 | .decrypt = aead_decrypt, |
| 1861 | .givencrypt = aead_null_givencrypt, |
| 1862 | .geniv = "<built-in>", |
| 1863 | .ivsize = NULL_IV_SIZE, |
| 1864 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 1865 | }, |
| 1866 | .class1_alg_type = 0, |
| 1867 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1868 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, |
| 1869 | }, |
| 1870 | { |
| 1871 | .name = "authenc(hmac(sha224),ecb(cipher_null))", |
| 1872 | .driver_name = "authenc-hmac-sha224-ecb-cipher_null-caam", |
| 1873 | .blocksize = NULL_BLOCK_SIZE, |
| 1874 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1875 | .template_aead = { |
| 1876 | .setkey = aead_setkey, |
| 1877 | .setauthsize = aead_setauthsize, |
| 1878 | .encrypt = aead_encrypt, |
| 1879 | .decrypt = aead_decrypt, |
| 1880 | .givencrypt = aead_null_givencrypt, |
| 1881 | .geniv = "<built-in>", |
| 1882 | .ivsize = NULL_IV_SIZE, |
| 1883 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 1884 | }, |
| 1885 | .class1_alg_type = 0, |
| 1886 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 1887 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1888 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, |
| 1889 | }, |
| 1890 | { |
| 1891 | .name = "authenc(hmac(sha256),ecb(cipher_null))", |
| 1892 | .driver_name = "authenc-hmac-sha256-ecb-cipher_null-caam", |
| 1893 | .blocksize = NULL_BLOCK_SIZE, |
| 1894 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1895 | .template_aead = { |
| 1896 | .setkey = aead_setkey, |
| 1897 | .setauthsize = aead_setauthsize, |
| 1898 | .encrypt = aead_encrypt, |
| 1899 | .decrypt = aead_decrypt, |
| 1900 | .givencrypt = aead_null_givencrypt, |
| 1901 | .geniv = "<built-in>", |
| 1902 | .ivsize = NULL_IV_SIZE, |
| 1903 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 1904 | }, |
| 1905 | .class1_alg_type = 0, |
| 1906 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 1907 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1908 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, |
| 1909 | }, |
| 1910 | { |
| 1911 | .name = "authenc(hmac(sha384),ecb(cipher_null))", |
| 1912 | .driver_name = "authenc-hmac-sha384-ecb-cipher_null-caam", |
| 1913 | .blocksize = NULL_BLOCK_SIZE, |
| 1914 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1915 | .template_aead = { |
| 1916 | .setkey = aead_setkey, |
| 1917 | .setauthsize = aead_setauthsize, |
| 1918 | .encrypt = aead_encrypt, |
| 1919 | .decrypt = aead_decrypt, |
| 1920 | .givencrypt = aead_null_givencrypt, |
| 1921 | .geniv = "<built-in>", |
| 1922 | .ivsize = NULL_IV_SIZE, |
| 1923 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 1924 | }, |
| 1925 | .class1_alg_type = 0, |
| 1926 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 1927 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1928 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, |
| 1929 | }, |
| 1930 | { |
| 1931 | .name = "authenc(hmac(sha512),ecb(cipher_null))", |
| 1932 | .driver_name = "authenc-hmac-sha512-ecb-cipher_null-caam", |
| 1933 | .blocksize = NULL_BLOCK_SIZE, |
| 1934 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1935 | .template_aead = { |
| 1936 | .setkey = aead_setkey, |
| 1937 | .setauthsize = aead_setauthsize, |
| 1938 | .encrypt = aead_encrypt, |
| 1939 | .decrypt = aead_decrypt, |
| 1940 | .givencrypt = aead_null_givencrypt, |
| 1941 | .geniv = "<built-in>", |
| 1942 | .ivsize = NULL_IV_SIZE, |
| 1943 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 1944 | }, |
| 1945 | .class1_alg_type = 0, |
| 1946 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 1947 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1948 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, |
| 1949 | }, |
| 1950 | { |
Kim Phillips | 8b4d43a | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 1951 | .name = "authenc(hmac(md5),cbc(aes))", |
| 1952 | .driver_name = "authenc-hmac-md5-cbc-aes-caam", |
| 1953 | .blocksize = AES_BLOCK_SIZE, |
| 1954 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1955 | .template_aead = { |
| 1956 | .setkey = aead_setkey, |
| 1957 | .setauthsize = aead_setauthsize, |
| 1958 | .encrypt = aead_encrypt, |
| 1959 | .decrypt = aead_decrypt, |
| 1960 | .givencrypt = aead_givencrypt, |
| 1961 | .geniv = "<built-in>", |
| 1962 | .ivsize = AES_BLOCK_SIZE, |
| 1963 | .maxauthsize = MD5_DIGEST_SIZE, |
| 1964 | }, |
| 1965 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 1966 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1967 | .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC, |
| 1968 | }, |
| 1969 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1970 | .name = "authenc(hmac(sha1),cbc(aes))", |
| 1971 | .driver_name = "authenc-hmac-sha1-cbc-aes-caam", |
| 1972 | .blocksize = AES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1973 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 1974 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 1975 | .setkey = aead_setkey, |
| 1976 | .setauthsize = aead_setauthsize, |
| 1977 | .encrypt = aead_encrypt, |
| 1978 | .decrypt = aead_decrypt, |
| 1979 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 1980 | .geniv = "<built-in>", |
| 1981 | .ivsize = AES_BLOCK_SIZE, |
| 1982 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 1983 | }, |
| 1984 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 1985 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, |
| 1986 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, |
| 1987 | }, |
| 1988 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 1989 | .name = "authenc(hmac(sha224),cbc(aes))", |
| 1990 | .driver_name = "authenc-hmac-sha224-cbc-aes-caam", |
| 1991 | .blocksize = AES_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 1992 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 1993 | .template_aead = { |
| 1994 | .setkey = aead_setkey, |
| 1995 | .setauthsize = aead_setauthsize, |
| 1996 | .encrypt = aead_encrypt, |
| 1997 | .decrypt = aead_decrypt, |
| 1998 | .givencrypt = aead_givencrypt, |
| 1999 | .geniv = "<built-in>", |
| 2000 | .ivsize = AES_BLOCK_SIZE, |
| 2001 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2002 | }, |
| 2003 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2004 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2005 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2006 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, |
| 2007 | }, |
| 2008 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2009 | .name = "authenc(hmac(sha256),cbc(aes))", |
| 2010 | .driver_name = "authenc-hmac-sha256-cbc-aes-caam", |
| 2011 | .blocksize = AES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2012 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2013 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2014 | .setkey = aead_setkey, |
| 2015 | .setauthsize = aead_setauthsize, |
| 2016 | .encrypt = aead_encrypt, |
| 2017 | .decrypt = aead_decrypt, |
| 2018 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2019 | .geniv = "<built-in>", |
| 2020 | .ivsize = AES_BLOCK_SIZE, |
| 2021 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2022 | }, |
| 2023 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2024 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2025 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2026 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, |
| 2027 | }, |
| 2028 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2029 | .name = "authenc(hmac(sha384),cbc(aes))", |
| 2030 | .driver_name = "authenc-hmac-sha384-cbc-aes-caam", |
| 2031 | .blocksize = AES_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 2032 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2033 | .template_aead = { |
| 2034 | .setkey = aead_setkey, |
| 2035 | .setauthsize = aead_setauthsize, |
| 2036 | .encrypt = aead_encrypt, |
| 2037 | .decrypt = aead_decrypt, |
| 2038 | .givencrypt = aead_givencrypt, |
| 2039 | .geniv = "<built-in>", |
| 2040 | .ivsize = AES_BLOCK_SIZE, |
| 2041 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2042 | }, |
| 2043 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2044 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2045 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2046 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, |
| 2047 | }, |
| 2048 | |
| 2049 | { |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2050 | .name = "authenc(hmac(sha512),cbc(aes))", |
| 2051 | .driver_name = "authenc-hmac-sha512-cbc-aes-caam", |
| 2052 | .blocksize = AES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2053 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2054 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2055 | .setkey = aead_setkey, |
| 2056 | .setauthsize = aead_setauthsize, |
| 2057 | .encrypt = aead_encrypt, |
| 2058 | .decrypt = aead_decrypt, |
| 2059 | .givencrypt = aead_givencrypt, |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2060 | .geniv = "<built-in>", |
| 2061 | .ivsize = AES_BLOCK_SIZE, |
| 2062 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2063 | }, |
| 2064 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2065 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2066 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2067 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, |
| 2068 | }, |
| 2069 | { |
Kim Phillips | 8b4d43a | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 2070 | .name = "authenc(hmac(md5),cbc(des3_ede))", |
| 2071 | .driver_name = "authenc-hmac-md5-cbc-des3_ede-caam", |
| 2072 | .blocksize = DES3_EDE_BLOCK_SIZE, |
| 2073 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2074 | .template_aead = { |
| 2075 | .setkey = aead_setkey, |
| 2076 | .setauthsize = aead_setauthsize, |
| 2077 | .encrypt = aead_encrypt, |
| 2078 | .decrypt = aead_decrypt, |
| 2079 | .givencrypt = aead_givencrypt, |
| 2080 | .geniv = "<built-in>", |
| 2081 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2082 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2083 | }, |
| 2084 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2085 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2086 | .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC, |
| 2087 | }, |
| 2088 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2089 | .name = "authenc(hmac(sha1),cbc(des3_ede))", |
| 2090 | .driver_name = "authenc-hmac-sha1-cbc-des3_ede-caam", |
| 2091 | .blocksize = DES3_EDE_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2092 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2093 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2094 | .setkey = aead_setkey, |
| 2095 | .setauthsize = aead_setauthsize, |
| 2096 | .encrypt = aead_encrypt, |
| 2097 | .decrypt = aead_decrypt, |
| 2098 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2099 | .geniv = "<built-in>", |
| 2100 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2101 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2102 | }, |
| 2103 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2104 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2105 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, |
| 2106 | }, |
| 2107 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2108 | .name = "authenc(hmac(sha224),cbc(des3_ede))", |
| 2109 | .driver_name = "authenc-hmac-sha224-cbc-des3_ede-caam", |
| 2110 | .blocksize = DES3_EDE_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 2111 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2112 | .template_aead = { |
| 2113 | .setkey = aead_setkey, |
| 2114 | .setauthsize = aead_setauthsize, |
| 2115 | .encrypt = aead_encrypt, |
| 2116 | .decrypt = aead_decrypt, |
| 2117 | .givencrypt = aead_givencrypt, |
| 2118 | .geniv = "<built-in>", |
| 2119 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2120 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2121 | }, |
| 2122 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2123 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2124 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2125 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, |
| 2126 | }, |
| 2127 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2128 | .name = "authenc(hmac(sha256),cbc(des3_ede))", |
| 2129 | .driver_name = "authenc-hmac-sha256-cbc-des3_ede-caam", |
| 2130 | .blocksize = DES3_EDE_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2131 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2132 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2133 | .setkey = aead_setkey, |
| 2134 | .setauthsize = aead_setauthsize, |
| 2135 | .encrypt = aead_encrypt, |
| 2136 | .decrypt = aead_decrypt, |
| 2137 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2138 | .geniv = "<built-in>", |
| 2139 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2140 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2141 | }, |
| 2142 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2143 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2144 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2145 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, |
| 2146 | }, |
| 2147 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2148 | .name = "authenc(hmac(sha384),cbc(des3_ede))", |
| 2149 | .driver_name = "authenc-hmac-sha384-cbc-des3_ede-caam", |
| 2150 | .blocksize = DES3_EDE_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 2151 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2152 | .template_aead = { |
| 2153 | .setkey = aead_setkey, |
| 2154 | .setauthsize = aead_setauthsize, |
| 2155 | .encrypt = aead_encrypt, |
| 2156 | .decrypt = aead_decrypt, |
| 2157 | .givencrypt = aead_givencrypt, |
| 2158 | .geniv = "<built-in>", |
| 2159 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2160 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2161 | }, |
| 2162 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2163 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2164 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2165 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, |
| 2166 | }, |
| 2167 | { |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2168 | .name = "authenc(hmac(sha512),cbc(des3_ede))", |
| 2169 | .driver_name = "authenc-hmac-sha512-cbc-des3_ede-caam", |
| 2170 | .blocksize = DES3_EDE_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2171 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2172 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2173 | .setkey = aead_setkey, |
| 2174 | .setauthsize = aead_setauthsize, |
| 2175 | .encrypt = aead_encrypt, |
| 2176 | .decrypt = aead_decrypt, |
| 2177 | .givencrypt = aead_givencrypt, |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2178 | .geniv = "<built-in>", |
| 2179 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2180 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2181 | }, |
| 2182 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2183 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2184 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2185 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, |
| 2186 | }, |
| 2187 | { |
Kim Phillips | 8b4d43a | 2011-11-21 16:13:27 +0800 | [diff] [blame] | 2188 | .name = "authenc(hmac(md5),cbc(des))", |
| 2189 | .driver_name = "authenc-hmac-md5-cbc-des-caam", |
| 2190 | .blocksize = DES_BLOCK_SIZE, |
| 2191 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2192 | .template_aead = { |
| 2193 | .setkey = aead_setkey, |
| 2194 | .setauthsize = aead_setauthsize, |
| 2195 | .encrypt = aead_encrypt, |
| 2196 | .decrypt = aead_decrypt, |
| 2197 | .givencrypt = aead_givencrypt, |
| 2198 | .geniv = "<built-in>", |
| 2199 | .ivsize = DES_BLOCK_SIZE, |
| 2200 | .maxauthsize = MD5_DIGEST_SIZE, |
| 2201 | }, |
| 2202 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2203 | .class2_alg_type = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2204 | .alg_op = OP_ALG_ALGSEL_MD5 | OP_ALG_AAI_HMAC, |
| 2205 | }, |
| 2206 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2207 | .name = "authenc(hmac(sha1),cbc(des))", |
| 2208 | .driver_name = "authenc-hmac-sha1-cbc-des-caam", |
| 2209 | .blocksize = DES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2210 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2211 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2212 | .setkey = aead_setkey, |
| 2213 | .setauthsize = aead_setauthsize, |
| 2214 | .encrypt = aead_encrypt, |
| 2215 | .decrypt = aead_decrypt, |
| 2216 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2217 | .geniv = "<built-in>", |
| 2218 | .ivsize = DES_BLOCK_SIZE, |
| 2219 | .maxauthsize = SHA1_DIGEST_SIZE, |
| 2220 | }, |
| 2221 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2222 | .class2_alg_type = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2223 | .alg_op = OP_ALG_ALGSEL_SHA1 | OP_ALG_AAI_HMAC, |
| 2224 | }, |
| 2225 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2226 | .name = "authenc(hmac(sha224),cbc(des))", |
| 2227 | .driver_name = "authenc-hmac-sha224-cbc-des-caam", |
| 2228 | .blocksize = DES_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 2229 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2230 | .template_aead = { |
| 2231 | .setkey = aead_setkey, |
| 2232 | .setauthsize = aead_setauthsize, |
| 2233 | .encrypt = aead_encrypt, |
| 2234 | .decrypt = aead_decrypt, |
| 2235 | .givencrypt = aead_givencrypt, |
| 2236 | .geniv = "<built-in>", |
| 2237 | .ivsize = DES_BLOCK_SIZE, |
| 2238 | .maxauthsize = SHA224_DIGEST_SIZE, |
| 2239 | }, |
| 2240 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2241 | .class2_alg_type = OP_ALG_ALGSEL_SHA224 | |
| 2242 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2243 | .alg_op = OP_ALG_ALGSEL_SHA224 | OP_ALG_AAI_HMAC, |
| 2244 | }, |
| 2245 | { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2246 | .name = "authenc(hmac(sha256),cbc(des))", |
| 2247 | .driver_name = "authenc-hmac-sha256-cbc-des-caam", |
| 2248 | .blocksize = DES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2249 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2250 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2251 | .setkey = aead_setkey, |
| 2252 | .setauthsize = aead_setauthsize, |
| 2253 | .encrypt = aead_encrypt, |
| 2254 | .decrypt = aead_decrypt, |
| 2255 | .givencrypt = aead_givencrypt, |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2256 | .geniv = "<built-in>", |
| 2257 | .ivsize = DES_BLOCK_SIZE, |
| 2258 | .maxauthsize = SHA256_DIGEST_SIZE, |
| 2259 | }, |
| 2260 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2261 | .class2_alg_type = OP_ALG_ALGSEL_SHA256 | |
| 2262 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2263 | .alg_op = OP_ALG_ALGSEL_SHA256 | OP_ALG_AAI_HMAC, |
| 2264 | }, |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2265 | { |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2266 | .name = "authenc(hmac(sha384),cbc(des))", |
| 2267 | .driver_name = "authenc-hmac-sha384-cbc-des-caam", |
| 2268 | .blocksize = DES_BLOCK_SIZE, |
Vakul Garg | cb7d566 | 2013-03-12 14:09:24 +0530 | [diff] [blame] | 2269 | .type = CRYPTO_ALG_TYPE_AEAD, |
Hemant Agrawal | e863f9cc | 2012-01-09 18:26:44 -0600 | [diff] [blame] | 2270 | .template_aead = { |
| 2271 | .setkey = aead_setkey, |
| 2272 | .setauthsize = aead_setauthsize, |
| 2273 | .encrypt = aead_encrypt, |
| 2274 | .decrypt = aead_decrypt, |
| 2275 | .givencrypt = aead_givencrypt, |
| 2276 | .geniv = "<built-in>", |
| 2277 | .ivsize = DES_BLOCK_SIZE, |
| 2278 | .maxauthsize = SHA384_DIGEST_SIZE, |
| 2279 | }, |
| 2280 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2281 | .class2_alg_type = OP_ALG_ALGSEL_SHA384 | |
| 2282 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2283 | .alg_op = OP_ALG_ALGSEL_SHA384 | OP_ALG_AAI_HMAC, |
| 2284 | }, |
| 2285 | { |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2286 | .name = "authenc(hmac(sha512),cbc(des))", |
| 2287 | .driver_name = "authenc-hmac-sha512-cbc-des-caam", |
| 2288 | .blocksize = DES_BLOCK_SIZE, |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2289 | .type = CRYPTO_ALG_TYPE_AEAD, |
| 2290 | .template_aead = { |
Yuan Kang | 0e47930 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2291 | .setkey = aead_setkey, |
| 2292 | .setauthsize = aead_setauthsize, |
| 2293 | .encrypt = aead_encrypt, |
| 2294 | .decrypt = aead_decrypt, |
| 2295 | .givencrypt = aead_givencrypt, |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2296 | .geniv = "<built-in>", |
| 2297 | .ivsize = DES_BLOCK_SIZE, |
| 2298 | .maxauthsize = SHA512_DIGEST_SIZE, |
| 2299 | }, |
| 2300 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2301 | .class2_alg_type = OP_ALG_ALGSEL_SHA512 | |
| 2302 | OP_ALG_AAI_HMAC_PRECOMP, |
| 2303 | .alg_op = OP_ALG_ALGSEL_SHA512 | OP_ALG_AAI_HMAC, |
| 2304 | }, |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 2305 | /* ablkcipher descriptor */ |
| 2306 | { |
| 2307 | .name = "cbc(aes)", |
| 2308 | .driver_name = "cbc-aes-caam", |
| 2309 | .blocksize = AES_BLOCK_SIZE, |
| 2310 | .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2311 | .template_ablkcipher = { |
| 2312 | .setkey = ablkcipher_setkey, |
| 2313 | .encrypt = ablkcipher_encrypt, |
| 2314 | .decrypt = ablkcipher_decrypt, |
| 2315 | .geniv = "eseqiv", |
| 2316 | .min_keysize = AES_MIN_KEY_SIZE, |
| 2317 | .max_keysize = AES_MAX_KEY_SIZE, |
| 2318 | .ivsize = AES_BLOCK_SIZE, |
| 2319 | }, |
| 2320 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, |
| 2321 | }, |
| 2322 | { |
| 2323 | .name = "cbc(des3_ede)", |
| 2324 | .driver_name = "cbc-3des-caam", |
| 2325 | .blocksize = DES3_EDE_BLOCK_SIZE, |
| 2326 | .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2327 | .template_ablkcipher = { |
| 2328 | .setkey = ablkcipher_setkey, |
| 2329 | .encrypt = ablkcipher_encrypt, |
| 2330 | .decrypt = ablkcipher_decrypt, |
| 2331 | .geniv = "eseqiv", |
| 2332 | .min_keysize = DES3_EDE_KEY_SIZE, |
| 2333 | .max_keysize = DES3_EDE_KEY_SIZE, |
| 2334 | .ivsize = DES3_EDE_BLOCK_SIZE, |
| 2335 | }, |
| 2336 | .class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, |
| 2337 | }, |
| 2338 | { |
| 2339 | .name = "cbc(des)", |
| 2340 | .driver_name = "cbc-des-caam", |
| 2341 | .blocksize = DES_BLOCK_SIZE, |
| 2342 | .type = CRYPTO_ALG_TYPE_ABLKCIPHER, |
| 2343 | .template_ablkcipher = { |
| 2344 | .setkey = ablkcipher_setkey, |
| 2345 | .encrypt = ablkcipher_encrypt, |
| 2346 | .decrypt = ablkcipher_decrypt, |
| 2347 | .geniv = "eseqiv", |
| 2348 | .min_keysize = DES_KEY_SIZE, |
| 2349 | .max_keysize = DES_KEY_SIZE, |
| 2350 | .ivsize = DES_BLOCK_SIZE, |
| 2351 | }, |
| 2352 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
| 2353 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2354 | }; |
| 2355 | |
| 2356 | struct caam_crypto_alg { |
| 2357 | struct list_head entry; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2358 | int class1_alg_type; |
| 2359 | int class2_alg_type; |
| 2360 | int alg_op; |
| 2361 | struct crypto_alg crypto_alg; |
| 2362 | }; |
| 2363 | |
| 2364 | static int caam_cra_init(struct crypto_tfm *tfm) |
| 2365 | { |
| 2366 | struct crypto_alg *alg = tfm->__crt_alg; |
| 2367 | struct caam_crypto_alg *caam_alg = |
| 2368 | container_of(alg, struct caam_crypto_alg, crypto_alg); |
| 2369 | struct caam_ctx *ctx = crypto_tfm_ctx(tfm); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2370 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2371 | ctx->jrdev = caam_jr_alloc(); |
| 2372 | if (IS_ERR(ctx->jrdev)) { |
| 2373 | pr_err("Job Ring Device allocation for transform failed\n"); |
| 2374 | return PTR_ERR(ctx->jrdev); |
| 2375 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2376 | |
| 2377 | /* copy descriptor header template value */ |
| 2378 | ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type; |
| 2379 | ctx->class2_alg_type = OP_TYPE_CLASS2_ALG | caam_alg->class2_alg_type; |
| 2380 | ctx->alg_op = OP_TYPE_CLASS2_ALG | caam_alg->alg_op; |
| 2381 | |
| 2382 | return 0; |
| 2383 | } |
| 2384 | |
| 2385 | static void caam_cra_exit(struct crypto_tfm *tfm) |
| 2386 | { |
| 2387 | struct caam_ctx *ctx = crypto_tfm_ctx(tfm); |
| 2388 | |
Yuan Kang | 1acebad | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 2389 | if (ctx->sh_desc_enc_dma && |
| 2390 | !dma_mapping_error(ctx->jrdev, ctx->sh_desc_enc_dma)) |
| 2391 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_enc_dma, |
| 2392 | desc_bytes(ctx->sh_desc_enc), DMA_TO_DEVICE); |
| 2393 | if (ctx->sh_desc_dec_dma && |
| 2394 | !dma_mapping_error(ctx->jrdev, ctx->sh_desc_dec_dma)) |
| 2395 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_dec_dma, |
| 2396 | desc_bytes(ctx->sh_desc_dec), DMA_TO_DEVICE); |
| 2397 | if (ctx->sh_desc_givenc_dma && |
| 2398 | !dma_mapping_error(ctx->jrdev, ctx->sh_desc_givenc_dma)) |
| 2399 | dma_unmap_single(ctx->jrdev, ctx->sh_desc_givenc_dma, |
| 2400 | desc_bytes(ctx->sh_desc_givenc), |
Kim Phillips | 4427b1b | 2011-05-14 22:08:17 -0500 | [diff] [blame] | 2401 | DMA_TO_DEVICE); |
Horia Geanta | ec31eed | 2014-03-14 17:48:30 +0200 | [diff] [blame] | 2402 | if (ctx->key_dma && |
| 2403 | !dma_mapping_error(ctx->jrdev, ctx->key_dma)) |
| 2404 | dma_unmap_single(ctx->jrdev, ctx->key_dma, |
| 2405 | ctx->enckeylen + ctx->split_key_pad_len, |
| 2406 | DMA_TO_DEVICE); |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2407 | |
| 2408 | caam_jr_free(ctx->jrdev); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | static void __exit caam_algapi_exit(void) |
| 2412 | { |
| 2413 | |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2414 | struct caam_crypto_alg *t_alg, *n; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2415 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2416 | if (!alg_list.next) |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2417 | return; |
| 2418 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2419 | list_for_each_entry_safe(t_alg, n, &alg_list, entry) { |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2420 | crypto_unregister_alg(&t_alg->crypto_alg); |
| 2421 | list_del(&t_alg->entry); |
| 2422 | kfree(t_alg); |
| 2423 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2424 | } |
| 2425 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2426 | static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2427 | *template) |
| 2428 | { |
| 2429 | struct caam_crypto_alg *t_alg; |
| 2430 | struct crypto_alg *alg; |
| 2431 | |
| 2432 | t_alg = kzalloc(sizeof(struct caam_crypto_alg), GFP_KERNEL); |
| 2433 | if (!t_alg) { |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2434 | pr_err("failed to allocate t_alg\n"); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2435 | return ERR_PTR(-ENOMEM); |
| 2436 | } |
| 2437 | |
| 2438 | alg = &t_alg->crypto_alg; |
| 2439 | |
| 2440 | snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name); |
| 2441 | snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s", |
| 2442 | template->driver_name); |
| 2443 | alg->cra_module = THIS_MODULE; |
| 2444 | alg->cra_init = caam_cra_init; |
| 2445 | alg->cra_exit = caam_cra_exit; |
| 2446 | alg->cra_priority = CAAM_CRA_PRIORITY; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2447 | alg->cra_blocksize = template->blocksize; |
| 2448 | alg->cra_alignmask = 0; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2449 | alg->cra_ctxsize = sizeof(struct caam_ctx); |
Nikos Mavrogiannopoulos | d912bb7 | 2011-11-01 13:39:56 +0100 | [diff] [blame] | 2450 | alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY | |
| 2451 | template->type; |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2452 | switch (template->type) { |
Yuan Kang | acdca31 | 2011-07-15 11:21:42 +0800 | [diff] [blame] | 2453 | case CRYPTO_ALG_TYPE_ABLKCIPHER: |
| 2454 | alg->cra_type = &crypto_ablkcipher_type; |
| 2455 | alg->cra_ablkcipher = template->template_ablkcipher; |
| 2456 | break; |
Yuan Kang | 885e9e2 | 2011-07-15 11:21:41 +0800 | [diff] [blame] | 2457 | case CRYPTO_ALG_TYPE_AEAD: |
| 2458 | alg->cra_type = &crypto_aead_type; |
| 2459 | alg->cra_aead = template->template_aead; |
| 2460 | break; |
| 2461 | } |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2462 | |
| 2463 | t_alg->class1_alg_type = template->class1_alg_type; |
| 2464 | t_alg->class2_alg_type = template->class2_alg_type; |
| 2465 | t_alg->alg_op = template->alg_op; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2466 | |
| 2467 | return t_alg; |
| 2468 | } |
| 2469 | |
| 2470 | static int __init caam_algapi_init(void) |
| 2471 | { |
Ruchika Gupta | 35af640 | 2014-07-07 10:42:12 +0530 | [diff] [blame] | 2472 | struct device_node *dev_node; |
| 2473 | struct platform_device *pdev; |
| 2474 | struct device *ctrldev; |
| 2475 | void *priv; |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2476 | int i = 0, err = 0; |
| 2477 | |
Ruchika Gupta | 35af640 | 2014-07-07 10:42:12 +0530 | [diff] [blame] | 2478 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0"); |
| 2479 | if (!dev_node) { |
| 2480 | dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0"); |
| 2481 | if (!dev_node) |
| 2482 | return -ENODEV; |
| 2483 | } |
| 2484 | |
| 2485 | pdev = of_find_device_by_node(dev_node); |
| 2486 | if (!pdev) { |
| 2487 | of_node_put(dev_node); |
| 2488 | return -ENODEV; |
| 2489 | } |
| 2490 | |
| 2491 | ctrldev = &pdev->dev; |
| 2492 | priv = dev_get_drvdata(ctrldev); |
| 2493 | of_node_put(dev_node); |
| 2494 | |
| 2495 | /* |
| 2496 | * If priv is NULL, it's probably because the caam driver wasn't |
| 2497 | * properly initialized (e.g. RNG4 init failed). Thus, bail out here. |
| 2498 | */ |
| 2499 | if (!priv) |
| 2500 | return -ENODEV; |
| 2501 | |
| 2502 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2503 | INIT_LIST_HEAD(&alg_list); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2504 | |
| 2505 | /* register crypto algorithms the device supports */ |
| 2506 | for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { |
| 2507 | /* TODO: check if h/w supports alg */ |
| 2508 | struct caam_crypto_alg *t_alg; |
| 2509 | |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2510 | t_alg = caam_alg_alloc(&driver_algs[i]); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2511 | if (IS_ERR(t_alg)) { |
| 2512 | err = PTR_ERR(t_alg); |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2513 | pr_warn("%s alg allocation failed\n", |
| 2514 | driver_algs[i].driver_name); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2515 | continue; |
| 2516 | } |
| 2517 | |
| 2518 | err = crypto_register_alg(&t_alg->crypto_alg); |
| 2519 | if (err) { |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2520 | pr_warn("%s alg registration failed\n", |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2521 | t_alg->crypto_alg.cra_driver_name); |
| 2522 | kfree(t_alg); |
Horia Geanta | 246bbed | 2013-03-20 16:31:58 +0200 | [diff] [blame] | 2523 | } else |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2524 | list_add_tail(&t_alg->entry, &alg_list); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2525 | } |
Ruchika Gupta | cfc6f11 | 2013-10-25 12:01:03 +0530 | [diff] [blame] | 2526 | if (!list_empty(&alg_list)) |
| 2527 | pr_info("caam algorithms registered in /proc/crypto\n"); |
Kim Phillips | 8e8ec59 | 2011-03-13 16:54:26 +0800 | [diff] [blame] | 2528 | |
| 2529 | return err; |
| 2530 | } |
| 2531 | |
| 2532 | module_init(caam_algapi_init); |
| 2533 | module_exit(caam_algapi_exit); |
| 2534 | |
| 2535 | MODULE_LICENSE("GPL"); |
| 2536 | MODULE_DESCRIPTION("FSL CAAM support for crypto API"); |
| 2537 | MODULE_AUTHOR("Freescale Semiconductor - NMG/STC"); |