2 * caam descriptor construction helper functions
4 * Copyright 2008-2011 Freescale Semiconductor, Inc.
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 * 64)
15 #define PRINT_POS do { printk(KERN_DEBUG "%02d: %s\n", desc_len(desc),\
16 &__func__[sizeof("append")]); } while (0)
21 #define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
22 LDST_SRCDST_WORD_DECOCTRL | \
23 (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
24 #define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
25 LDST_SRCDST_WORD_DECOCTRL | \
26 (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
28 static inline int desc_len(u32 *desc)
30 return *desc & HDR_DESCLEN_MASK;
33 static inline int desc_bytes(void *desc)
35 return desc_len(desc) * CAAM_CMD_SZ;
38 static inline u32 *desc_end(u32 *desc)
40 return desc + desc_len(desc);
43 static inline void *sh_desc_pdb(u32 *desc)
48 static inline void init_desc(u32 *desc, u32 options)
50 *desc = options | HDR_ONE | 1;
53 static inline void init_sh_desc(u32 *desc, u32 options)
56 init_desc(desc, CMD_SHARED_DESC_HDR | options);
59 static inline void init_sh_desc_pdb(u32 *desc, u32 options, size_t pdb_bytes)
61 u32 pdb_len = pdb_bytes / CAAM_CMD_SZ + 1;
63 init_sh_desc(desc, ((pdb_len << HDR_START_IDX_SHIFT) + pdb_len) |
67 static inline void init_job_desc(u32 *desc, u32 options)
69 init_desc(desc, CMD_DESC_HDR | options);
72 static inline void append_ptr(u32 *desc, dma_addr_t ptr)
74 dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
78 (*desc) += CAAM_PTR_SZ / CAAM_CMD_SZ;
81 static inline void init_job_desc_shared(u32 *desc, dma_addr_t ptr, int len,
85 init_job_desc(desc, HDR_SHARED | options |
86 (len << HDR_START_IDX_SHIFT));
87 append_ptr(desc, ptr);
90 static inline void append_data(u32 *desc, void *data, int len)
92 u32 *offset = desc_end(desc);
94 if (len) /* avoid sparse warning: memcpy with byte count of 0 */
95 memcpy(offset, data, len);
97 (*desc) += (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
100 static inline void append_cmd(u32 *desc, u32 command)
102 u32 *cmd = desc_end(desc);
109 static inline void append_cmd_ptr(u32 *desc, dma_addr_t ptr, int len,
112 append_cmd(desc, command | len);
113 append_ptr(desc, ptr);
116 static inline void append_cmd_data(u32 *desc, void *data, int len,
119 append_cmd(desc, command | IMMEDIATE | len);
120 append_data(desc, data, len);
123 static inline u32 *append_jump(u32 *desc, u32 options)
125 u32 *cmd = desc_end(desc);
128 append_cmd(desc, CMD_JUMP | options);
133 static inline void set_jump_tgt_here(u32 *desc, u32 *jump_cmd)
135 *jump_cmd = *jump_cmd | (desc_len(desc) - (jump_cmd - desc));
138 #define APPEND_CMD(cmd, op) \
139 static inline void append_##cmd(u32 *desc, u32 options) \
142 append_cmd(desc, CMD_##op | options); \
144 APPEND_CMD(operation, OPERATION)
145 APPEND_CMD(move, MOVE)
147 #define APPEND_CMD_LEN(cmd, op) \
148 static inline void append_##cmd(u32 *desc, unsigned int len, u32 options) \
151 append_cmd(desc, CMD_##op | len | options); \
153 APPEND_CMD_LEN(seq_store, SEQ_STORE)
154 APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD)
155 APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
157 #define APPEND_CMD_PTR(cmd, op) \
158 static inline void append_##cmd(u32 *desc, dma_addr_t ptr, unsigned int len, \
162 append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
164 APPEND_CMD_PTR(key, KEY)
165 APPEND_CMD_PTR(seq_in_ptr, SEQ_IN_PTR)
166 APPEND_CMD_PTR(seq_out_ptr, SEQ_OUT_PTR)
167 APPEND_CMD_PTR(load, LOAD)
168 APPEND_CMD_PTR(store, STORE)
169 APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
170 APPEND_CMD_PTR(fifo_store, FIFO_STORE)
172 #define APPEND_CMD_PTR_TO_IMM(cmd, op) \
173 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
174 unsigned int len, u32 options) \
177 append_cmd_data(desc, data, len, CMD_##op | options); \
179 APPEND_CMD_PTR_TO_IMM(load, LOAD);
180 APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
183 * 2nd variant for commands whose specified immediate length differs
184 * from length of immediate data provided, e.g., split keys
186 #define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
187 static inline void append_##cmd##_as_imm(u32 *desc, void *data, \
188 unsigned int data_len, \
189 unsigned int len, u32 options) \
192 append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \
193 append_data(desc, data, data_len); \
195 APPEND_CMD_PTR_TO_IMM2(key, KEY);
197 #define APPEND_CMD_RAW_IMM(cmd, op, type) \
198 static inline void append_##cmd##_imm_##type(u32 *desc, type immediate, \
202 append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \
203 append_cmd(desc, immediate); \
205 APPEND_CMD_RAW_IMM(load, LOAD, u32);