i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / crypto / caam / desc_constr.h
blob348b882275f059ede78df5d3ecf82b447c8e847e
1 /*
2 * caam descriptor construction helper functions
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
5 */
7 #include "desc.h"
9 #define IMMEDIATE (1 << 23)
10 #define CAAM_CMD_SZ sizeof(u32)
11 #define CAAM_PTR_SZ sizeof(dma_addr_t)
12 #define CAAM_DESC_BYTES_MAX (CAAM_CMD_SZ * MAX_CAAM_DESCSIZE)
14 #ifdef DEBUG
15 #define PRINT_POS do { printk(KERN_DEBUG "%02d: %s\n", desc_len(desc),\
16 &__func__[sizeof("append")]); } while (0)
17 #else
18 #define PRINT_POS
19 #endif
21 #define SET_OK_NO_PROP_ERRORS (IMMEDIATE | LDST_CLASS_DECO | \
22 LDST_SRCDST_WORD_DECOCTRL | \
23 (LDOFF_CHG_SHARE_OK_NO_PROP << \
24 LDST_OFFSET_SHIFT))
25 #define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
26 LDST_SRCDST_WORD_DECOCTRL | \
27 (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
28 #define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
29 LDST_SRCDST_WORD_DECOCTRL | \
30 (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
32 static inline int desc_len(u32 *desc)
34 return *desc & HDR_DESCLEN_MASK;
37 static inline int desc_bytes(void *desc)
39 return desc_len(desc) * CAAM_CMD_SZ;
42 static inline u32 *desc_end(u32 *desc)
44 return desc + desc_len(desc);
47 static inline void *sh_desc_pdb(u32 *desc)
49 return desc + 1;
52 static inline void init_desc(u32 *desc, u32 options)
54 *desc = options | HDR_ONE | 1;
57 static inline void init_sh_desc(u32 *desc, u32 options)
59 PRINT_POS;
60 init_desc(desc, CMD_SHARED_DESC_HDR | options);
63 static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
65 u32 pdb_len = pdb_bytes / CAAM_CMD_SZ + 1;
67 init_sh_desc(desc, ((pdb_len << HDR_START_IDX_SHIFT) + pdb_len) |
68 options);
71 static inline void init_job_desc(u32 *desc, u32 options)
73 init_desc(desc, CMD_DESC_HDR | options);
76 static inline void append_ptr(u32 *desc, dma_addr_t ptr)
78 dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
80 *offset = ptr;
82 (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ;
85 static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
86 u32 options)
88 PRINT_POS;
89 init_job_desc(desc, HDR_SHARED | options |
90 (len << HDR_START_IDX_SHIFT));
91 append_ptr(desc, ptr);
94 static inline void append_data(u32 *desc, void *data, int len)
96 u32 *offset = desc_end(desc);
98 if (len) /* avoid sparse warning: memcpy with byte count of 0 */
99 memcpy(offset, data, len);
101 (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
104 static inline void append_cmd(u32 *desc, u32 command)
106 u32 *cmd = desc_end(desc);
108 *cmd = command;
110 (*desc)++;
113 static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len,
114 u32 command)
116 append_cmd(desc, command | len);
117 append_ptr(desc, ptr);
120 static inline void append_cmd_data(u32 *desc, void *data, int len,
121 u32 command)
123 append_cmd(desc, command | IMMEDIATE | len);
124 append_data(desc, data, len);
127 static inline u32 *append_jump(u32 *desc, u32 options)
129 u32 *cmd = desc_end(desc);
131 PRINT_POS;
132 append_cmd(desc, CMD_JUMP | options);
134 return cmd;
137 static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
139 *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc));
142 #define APPEND_CMD(cmd, op) \
143 static inline void append_##cmd(u32 *desc, u32 options) \
145 PRINT_POS; \
146 append_cmd(desc, CMD_##op | options); \
148 APPEND_CMD(operation, OPERATION)
149 APPEND_CMD(move, MOVE)
151 #define APPEND_CMD_LEN(cmd, op) \
152 static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \
154 PRINT_POS; \
155 append_cmd(desc, CMD_##op | len | options); \
157 APPEND_CMD_LEN(seq_store, SEQ_STORE)
158 APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD)
159 APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
161 #define APPEND_CMD_PTR(cmd, op) \
162 static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \
163 u32 options) \
165 PRINT_POS; \
166 append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
168 APPEND_CMD_PTR(key, KEY)
169 APPEND_CMD_PTR(seq_in_ptr, SEQ_IN_PTR)
170 APPEND_CMD_PTR(seq_out_ptr, SEQ_OUT_PTR)
171 APPEND_CMD_PTR(load, LOAD)
172 APPEND_CMD_PTR(store, STORE)
173 APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
174 APPEND_CMD_PTR(fifo_store, FIFO_STORE)
176 #define APPEND_CMD_PTR_TO_IMM(cmd, op) \
177 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
178 unsigned int len, u32 options) \
180 PRINT_POS; \
181 append_cmd_data(desc, data, len, CMD_##op | options); \
183 APPEND_CMD_PTR_TO_IMM(load, LOAD);
184 APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
187 * 2nd variant for commands whose specified immediate length differs
188 * from length of immediate data provided, e.g., split keys
190 #define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
191 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
192 unsigned int data_len, \
193 unsigned int len, u32 options) \
195 PRINT_POS; \
196 append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \
197 append_data(desc, data, data_len); \
199 APPEND_CMD_PTR_TO_IMM2(key, KEY);
201 #define APPEND_CMD_RAW_IMM(cmd, op, type) \
202 static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \
203 u32 options) \
205 PRINT_POS; \
206 append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \
207 append_cmd(desc, immediate); \
209 APPEND_CMD_RAW_IMM(load, LOAD, u32);
212 * Append math command. Only the last part of destination and source need to
213 * be specified
215 #define APPEND_MATH(op, desc, dest, src_0, src_1, len) \
216 append_cmd(desc, CMD_MATH | MATH_FUN_##op | MATH_DEST_##dest | \
217 MATH_SRC0_##src_0 | MATH_SRC1_##src_1 | (u32) (len & MATH_LEN_MASK));
219 #define append_math_add(desc, dest, src0, src1, len) \
220 APPEND_MATH(ADD, desc, dest, src0, src1, len)
221 #define append_math_sub(desc, dest, src0, src1, len) \
222 APPEND_MATH(SUB, desc, dest, src0, src1, len)
223 #define append_math_add_c(desc, dest, src0, src1, len) \
224 APPEND_MATH(ADDC, desc, dest, src0, src1, len)
225 #define append_math_sub_b(desc, dest, src0, src1, len) \
226 APPEND_MATH(SUBB, desc, dest, src0, src1, len)
227 #define append_math_and(desc, dest, src0, src1, len) \
228 APPEND_MATH(AND, desc, dest, src0, src1, len)
229 #define append_math_or(desc, dest, src0, src1, len) \
230 APPEND_MATH(OR, desc, dest, src0, src1, len)
231 #define append_math_xor(desc, dest, src0, src1, len) \
232 APPEND_MATH(XOR, desc, dest, src0, src1, len)
233 #define append_math_lshift(desc, dest, src0, src1, len) \
234 APPEND_MATH(LSHIFT, desc, dest, src0, src1, len)
235 #define append_math_rshift(desc, dest, src0, src1, len) \
236 APPEND_MATH(RSHIFT, desc, dest, src0, src1, len)
238 /* Exactly one source is IMM. Data is passed in as u32 value */
239 #define APPEND_MATH_IMM_u32(op, desc, dest, src_0, src_1, data) \
240 do { \
241 APPEND_MATH(op, desc, dest, src_0, src_1, CAAM_CMD_SZ); \
242 append_cmd(desc, data); \
243 } while (0);
245 #define append_math_add_imm_u32(desc, dest, src0, src1, data) \
246 APPEND_MATH_IMM_u32(ADD, desc, dest, src0, src1, data)
247 #define append_math_sub_imm_u32(desc, dest, src0, src1, data) \
248 APPEND_MATH_IMM_u32(SUB, desc, dest, src0, src1, data)
249 #define append_math_add_c_imm_u32(desc, dest, src0, src1, data) \
250 APPEND_MATH_IMM_u32(ADDC, desc, dest, src0, src1, data)
251 #define append_math_sub_b_imm_u32(desc, dest, src0, src1, data) \
252 APPEND_MATH_IMM_u32(SUBB, desc, dest, src0, src1, data)
253 #define append_math_and_imm_u32(desc, dest, src0, src1, data) \
254 APPEND_MATH_IMM_u32(AND, desc, dest, src0, src1, data)
255 #define append_math_or_imm_u32(desc, dest, src0, src1, data) \
256 APPEND_MATH_IMM_u32(OR, desc, dest, src0, src1, data)
257 #define append_math_xor_imm_u32(desc, dest, src0, src1, data) \
258 APPEND_MATH_IMM_u32(XOR, desc, dest, src0, src1, data)
259 #define append_math_lshift_imm_u32(desc, dest, src0, src1, data) \
260 APPEND_MATH_IMM_u32(LSHIFT, desc, dest, src0, src1, data)
261 #define append_math_rshift_imm_u32(desc, dest, src0, src1, data) \
262 APPEND_MATH_IMM_u32(RSHIFT, desc, dest, src0, src1, data)