MIPS: perf: Add support for 64-bit perf counters.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / crypto / caam / desc_constr.h
blob0991323cf3fd40bd7e9f09f2e9c522aa78be3dfb
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_PROP_ERRORS (IMMEDIATE | LDST_CLASS_DECO | \
22 LDST_SRCDST_WORD_DECOCTRL | \
23 (LDOFF_CHG_SHARE_OK_PROP << LDST_OFFSET_SHIFT))
24 #define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
25 LDST_SRCDST_WORD_DECOCTRL | \
26 (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
27 #define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
28 LDST_SRCDST_WORD_DECOCTRL | \
29 (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
31 static inline int desc_len(u32 *desc)
33 return *desc & HDR_DESCLEN_MASK;
36 static inline int desc_bytes(void *desc)
38 return desc_len(desc) * CAAM_CMD_SZ;
41 static inline u32 *desc_end(u32 *desc)
43 return desc + desc_len(desc);
46 static inline void *sh_desc_pdb(u32 *desc)
48 return desc + 1;
51 static inline void init_desc(u32 *desc, u32 options)
53 *desc = options | HDR_ONE | 1;
56 static inline void init_sh_desc(u32 *desc, u32 options)
58 PRINT_POS;
59 init_desc(desc, CMD_SHARED_DESC_HDR | options);
62 static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
64 u32 pdb_len = pdb_bytes / CAAM_CMD_SZ + 1;
66 init_sh_desc(desc, ((pdb_len << HDR_START_IDX_SHIFT) + pdb_len) |
67 options);
70 static inline void init_job_desc(u32 *desc, u32 options)
72 init_desc(desc, CMD_DESC_HDR | options);
75 static inline void append_ptr(u32 *desc, dma_addr_t ptr)
77 dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
79 *offset = ptr;
81 (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ;
84 static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
85 u32 options)
87 PRINT_POS;
88 init_job_desc(desc, HDR_SHARED | options |
89 (len << HDR_START_IDX_SHIFT));
90 append_ptr(desc, ptr);
93 static inline void append_data(u32 *desc, void *data, int len)
95 u32 *offset = desc_end(desc);
97 if (len) /* avoid sparse warning: memcpy with byte count of 0 */
98 memcpy(offset, data, len);
100 (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
103 static inline void append_cmd(u32 *desc, u32 command)
105 u32 *cmd = desc_end(desc);
107 *cmd = command;
109 (*desc)++;
112 static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len,
113 u32 command)
115 append_cmd(desc, command | len);
116 append_ptr(desc, ptr);
119 static inline void append_cmd_data(u32 *desc, void *data, int len,
120 u32 command)
122 append_cmd(desc, command | IMMEDIATE | len);
123 append_data(desc, data, len);
126 static inline u32 *append_jump(u32 *desc, u32 options)
128 u32 *cmd = desc_end(desc);
130 PRINT_POS;
131 append_cmd(desc, CMD_JUMP | options);
133 return cmd;
136 static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
138 *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc));
141 #define APPEND_CMD(cmd, op) \
142 static inline void append_##cmd(u32 *desc, u32 options) \
144 PRINT_POS; \
145 append_cmd(desc, CMD_##op | options); \
147 APPEND_CMD(operation, OPERATION)
148 APPEND_CMD(move, MOVE)
150 #define APPEND_CMD_LEN(cmd, op) \
151 static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \
153 PRINT_POS; \
154 append_cmd(desc, CMD_##op | len | options); \
156 APPEND_CMD_LEN(seq_store, SEQ_STORE)
157 APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD)
158 APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
160 #define APPEND_CMD_PTR(cmd, op) \
161 static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \
162 u32 options) \
164 PRINT_POS; \
165 append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
167 APPEND_CMD_PTR(key, KEY)
168 APPEND_CMD_PTR(seq_in_ptr, SEQ_IN_PTR)
169 APPEND_CMD_PTR(seq_out_ptr, SEQ_OUT_PTR)
170 APPEND_CMD_PTR(load, LOAD)
171 APPEND_CMD_PTR(store, STORE)
172 APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
173 APPEND_CMD_PTR(fifo_store, FIFO_STORE)
175 #define APPEND_CMD_PTR_TO_IMM(cmd, op) \
176 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
177 unsigned int len, u32 options) \
179 PRINT_POS; \
180 append_cmd_data(desc, data, len, CMD_##op | options); \
182 APPEND_CMD_PTR_TO_IMM(load, LOAD);
183 APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
186 * 2nd variant for commands whose specified immediate length differs
187 * from length of immediate data provided, e.g., split keys
189 #define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
190 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
191 unsigned int data_len, \
192 unsigned int len, u32 options) \
194 PRINT_POS; \
195 append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \
196 append_data(desc, data, data_len); \
198 APPEND_CMD_PTR_TO_IMM2(key, KEY);
200 #define APPEND_CMD_RAW_IMM(cmd, op, type) \
201 static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \
202 u32 options) \
204 PRINT_POS; \
205 append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \
206 append_cmd(desc, immediate); \
208 APPEND_CMD_RAW_IMM(load, LOAD, u32);
211 * Append math command. Only the last part of destination and source need to
212 * be specified
214 #define APPEND_MATH(op, desc, dest, src_0, src_1, len) \
215 append_cmd(desc, CMD_MATH | MATH_FUN_##op | MATH_DEST_##dest | \
216 MATH_SRC0_##src_0 | MATH_SRC1_##src_1 | (u32) (len & MATH_LEN_MASK));
218 #define append_math_add(desc, dest, src0, src1, len) \
219 APPEND_MATH(ADD, desc, dest, src0, src1, len)
220 #define append_math_sub(desc, dest, src0, src1, len) \
221 APPEND_MATH(SUB, desc, dest, src0, src1, len)
222 #define append_math_add_c(desc, dest, src0, src1, len) \
223 APPEND_MATH(ADDC, desc, dest, src0, src1, len)
224 #define append_math_sub_b(desc, dest, src0, src1, len) \
225 APPEND_MATH(SUBB, desc, dest, src0, src1, len)
226 #define append_math_and(desc, dest, src0, src1, len) \
227 APPEND_MATH(AND, desc, dest, src0, src1, len)
228 #define append_math_or(desc, dest, src0, src1, len) \
229 APPEND_MATH(OR, desc, dest, src0, src1, len)
230 #define append_math_xor(desc, dest, src0, src1, len) \
231 APPEND_MATH(XOR, desc, dest, src0, src1, len)
232 #define append_math_lshift(desc, dest, src0, src1, len) \
233 APPEND_MATH(LSHIFT, desc, dest, src0, src1, len)
234 #define append_math_rshift(desc, dest, src0, src1, len) \
235 APPEND_MATH(RSHIFT, desc, dest, src0, src1, len)
237 /* Exactly one source is IMM. Data is passed in as u32 value */
238 #define APPEND_MATH_IMM_u32(op, desc, dest, src_0, src_1, data) \
239 do { \
240 APPEND_MATH(op, desc, dest, src_0, src_1, CAAM_CMD_SZ); \
241 append_cmd(desc, data); \
242 } while (0);
244 #define append_math_add_imm_u32(desc, dest, src0, src1, data) \
245 APPEND_MATH_IMM_u32(ADD, desc, dest, src0, src1, data)
246 #define append_math_sub_imm_u32(desc, dest, src0, src1, data) \
247 APPEND_MATH_IMM_u32(SUB, desc, dest, src0, src1, data)
248 #define append_math_add_c_imm_u32(desc, dest, src0, src1, data) \
249 APPEND_MATH_IMM_u32(ADDC, desc, dest, src0, src1, data)
250 #define append_math_sub_b_imm_u32(desc, dest, src0, src1, data) \
251 APPEND_MATH_IMM_u32(SUBB, desc, dest, src0, src1, data)
252 #define append_math_and_imm_u32(desc, dest, src0, src1, data) \
253 APPEND_MATH_IMM_u32(AND, desc, dest, src0, src1, data)
254 #define append_math_or_imm_u32(desc, dest, src0, src1, data) \
255 APPEND_MATH_IMM_u32(OR, desc, dest, src0, src1, data)
256 #define append_math_xor_imm_u32(desc, dest, src0, src1, data) \
257 APPEND_MATH_IMM_u32(XOR, desc, dest, src0, src1, data)
258 #define append_math_lshift_imm_u32(desc, dest, src0, src1, data) \
259 APPEND_MATH_IMM_u32(LSHIFT, desc, dest, src0, src1, data)
260 #define append_math_rshift_imm_u32(desc, dest, src0, src1, data) \
261 APPEND_MATH_IMM_u32(RSHIFT, desc, dest, src0, src1, data)