1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * CAAM descriptor composition header
4  * Definitions to support CAAM descriptor instruction generation
5  *
6  * Copyright 2008-2014 Freescale Semiconductor, Inc.
7  *
8  * Based on desc.h file in linux drivers/crypto/caam
9  */
10 
11 #ifndef DESC_H
12 #define DESC_H
13 
14 #include "type.h"
15 
16 #define KEY_BLOB_SIZE		32
17 #define MAC_SIZE			16
18 
19 /* Max size of any CAAM descriptor in 32-bit words, inclusive of header */
20 #define MAX_CAAM_DESCSIZE	64
21 
22 /* Size of DEK Blob  descriptor, inclusive of header */
23 #define DEK_BLOB_DESCSIZE	9
24 
25 /* Block size of any entity covered/uncovered with a KEK/TKEK */
26 #define KEK_BLOCKSIZE		16
27 
28 /*
29  * Supported descriptor command types as they show up
30  * inside a descriptor command word.
31  */
32 #define CMD_SHIFT		27
33 #define CMD_MASK		0xf8000000
34 
35 #define CMD_KEY			(0x00 << CMD_SHIFT)
36 #define CMD_SEQ_KEY		(0x01 << CMD_SHIFT)
37 #define CMD_LOAD		(0x02 << CMD_SHIFT)
38 #define CMD_SEQ_LOAD		(0x03 << CMD_SHIFT)
39 #define CMD_FIFO_LOAD		(0x04 << CMD_SHIFT)
40 #define CMD_SEQ_FIFO_LOAD	(0x05 << CMD_SHIFT)
41 #define CMD_STORE		(0x0a << CMD_SHIFT)
42 #define CMD_SEQ_STORE		(0x0b << CMD_SHIFT)
43 #define CMD_FIFO_STORE		(0x0c << CMD_SHIFT)
44 #define CMD_SEQ_FIFO_STORE	(0x0d << CMD_SHIFT)
45 #define CMD_MOVE_LEN		(0x0e << CMD_SHIFT)
46 #define CMD_MOVE		(0x0f << CMD_SHIFT)
47 #define CMD_OPERATION		(0x10 << CMD_SHIFT)
48 #define CMD_SIGNATURE		(0x12 << CMD_SHIFT)
49 #define CMD_JUMP		(0x14 << CMD_SHIFT)
50 #define CMD_MATH		(0x15 << CMD_SHIFT)
51 #define CMD_DESC_HDR		(0x16 << CMD_SHIFT)
52 #define CMD_SHARED_DESC_HDR	(0x17 << CMD_SHIFT)
53 #define CMD_SEQ_IN_PTR		(0x1e << CMD_SHIFT)
54 #define CMD_SEQ_OUT_PTR		(0x1f << CMD_SHIFT)
55 
56 /* General-purpose class selector for all commands */
57 #define CLASS_SHIFT		25
58 #define CLASS_MASK		(0x03 << CLASS_SHIFT)
59 
60 #define CLASS_NONE		(0x00 << CLASS_SHIFT)
61 #define CLASS_1			(0x01 << CLASS_SHIFT)
62 #define CLASS_2			(0x02 << CLASS_SHIFT)
63 #define CLASS_BOTH		(0x03 << CLASS_SHIFT)
64 
65 /*
66  * Descriptor header command constructs
67  * Covers shared, job, and trusted descriptor headers
68  */
69 
70 /*
71  * Do Not Run - marks a descriptor inexecutable if there was
72  * a preceding error somewhere
73  */
74 #define HDR_DNR			0x01000000
75 
76 /*
77  * ONE - should always be set. Combination of ONE (always
78  * set) and ZRO (always clear) forms an endianness sanity check
79  */
80 #define HDR_ONE			0x00800000
81 #define HDR_ZRO			0x00008000
82 
83 /* Start Index or SharedDesc Length */
84 #define HDR_START_IDX_MASK	0x3f
85 #define HDR_START_IDX_SHIFT	16
86 
87 /* If shared descriptor header, 6-bit length */
88 #define HDR_DESCLEN_SHR_MASK	0x3f
89 
90 /* If non-shared header, 7-bit length */
91 #define HDR_DESCLEN_MASK	0x7f
92 
93 /* This is a TrustedDesc (if not SharedDesc) */
94 #define HDR_TRUSTED		0x00004000
95 
96 /* Make into TrustedDesc (if not SharedDesc) */
97 #define HDR_MAKE_TRUSTED	0x00002000
98 
99 /* Save context if self-shared (if SharedDesc) */
100 #define HDR_SAVECTX		0x00001000
101 
102 /* Next item points to SharedDesc */
103 #define HDR_SHARED		0x00001000
104 
105 /*
106  * Reverse Execution Order - execute JobDesc first, then
107  * execute SharedDesc (normally SharedDesc goes first).
108  */
109 #define HDR_REVERSE		0x00000800
110 
111 /* Propagate DNR property to SharedDesc */
112 #define HDR_PROP_DNR		0x00000800
113 
114 /* JobDesc/SharedDesc share property */
115 #define HDR_SD_SHARE_MASK	0x03
116 #define HDR_SD_SHARE_SHIFT	8
117 #define HDR_JD_SHARE_MASK	0x07
118 #define HDR_JD_SHARE_SHIFT	8
119 
120 #define HDR_SHARE_NEVER		(0x00 << HDR_SD_SHARE_SHIFT)
121 #define HDR_SHARE_WAIT		(0x01 << HDR_SD_SHARE_SHIFT)
122 #define HDR_SHARE_SERIAL	(0x02 << HDR_SD_SHARE_SHIFT)
123 #define HDR_SHARE_ALWAYS	(0x03 << HDR_SD_SHARE_SHIFT)
124 #define HDR_SHARE_DEFER		(0x04 << HDR_SD_SHARE_SHIFT)
125 
126 /* JobDesc/SharedDesc descriptor length */
127 #define HDR_JD_LENGTH_MASK	0x7f
128 #define HDR_SD_LENGTH_MASK	0x3f
129 
130 /*
131  * KEY/SEQ_KEY Command Constructs
132  */
133 
134 /* Key Destination Class: 01 = Class 1, 02 - Class 2 */
135 #define KEY_DEST_CLASS_SHIFT	25	/* use CLASS_1 or CLASS_2 */
136 #define KEY_DEST_CLASS_MASK	(0x03 << KEY_DEST_CLASS_SHIFT)
137 
138 /* Scatter-Gather Table/Variable Length Field */
139 #define KEY_SGF			0x01000000
140 #define KEY_VLF			0x01000000
141 
142 /* Immediate - Key follows command in the descriptor */
143 #define KEY_IMM			0x00800000
144 
145 /*
146  * Encrypted - Key is encrypted either with the KEK, or
147  * with the TDKEK if TK is set
148  */
149 #define KEY_ENC			0x00400000
150 
151 /*
152  * No Write Back - Do not allow key to be FIFO STOREd
153  */
154 #define KEY_NWB			0x00200000
155 
156 /*
157  * Enhanced Encryption of Key
158  */
159 #define KEY_EKT			0x00100000
160 
161 /*
162  * Encrypted with Trusted Key
163  */
164 #define KEY_TK			0x00008000
165 
166 /*
167  * KDEST - Key Destination: 0 - class key register,
168  * 1 - PKHA 'e', 2 - AFHA Sbox, 3 - MDHA split-key
169  */
170 #define KEY_DEST_SHIFT		16
171 #define KEY_DEST_MASK		(0x03 << KEY_DEST_SHIFT)
172 
173 #define KEY_DEST_CLASS_REG	(0x00 << KEY_DEST_SHIFT)
174 #define KEY_DEST_PKHA_E		(0x01 << KEY_DEST_SHIFT)
175 #define KEY_DEST_AFHA_SBOX	(0x02 << KEY_DEST_SHIFT)
176 #define KEY_DEST_MDHA_SPLIT	(0x03 << KEY_DEST_SHIFT)
177 
178 /* Length in bytes */
179 #define KEY_LENGTH_MASK		0x000003ff
180 
181 /*
182  * LOAD/SEQ_LOAD/STORE/SEQ_STORE Command Constructs
183  */
184 
185 /*
186  * Load/Store Destination: 0 = class independent CCB,
187  * 1 = class 1 CCB, 2 = class 2 CCB, 3 = DECO
188  */
189 #define LDST_CLASS_SHIFT	25
190 #define LDST_CLASS_MASK		(0x03 << LDST_CLASS_SHIFT)
191 #define LDST_CLASS_IND_CCB	(0x00 << LDST_CLASS_SHIFT)
192 #define LDST_CLASS_1_CCB	(0x01 << LDST_CLASS_SHIFT)
193 #define LDST_CLASS_2_CCB	(0x02 << LDST_CLASS_SHIFT)
194 #define LDST_CLASS_DECO		(0x03 << LDST_CLASS_SHIFT)
195 
196 /* Scatter-Gather Table/Variable Length Field */
197 #define LDST_SGF		0x01000000
198 #define LDST_VLF		LDST_SGF
199 
200 /* Immediate - Key follows this command in descriptor */
201 #define LDST_IMM_MASK		1
202 #define LDST_IMM_SHIFT		23
203 #define LDST_IMM		(LDST_IMM_MASK << LDST_IMM_SHIFT)
204 
205 /* SRC/DST - Destination for LOAD, Source for STORE */
206 #define LDST_SRCDST_SHIFT	16
207 #define LDST_SRCDST_MASK	(0x7f << LDST_SRCDST_SHIFT)
208 
209 #define LDST_SRCDST_BYTE_CONTEXT	(0x20 << LDST_SRCDST_SHIFT)
210 #define LDST_SRCDST_BYTE_KEY		(0x40 << LDST_SRCDST_SHIFT)
211 #define LDST_SRCDST_BYTE_INFIFO		(0x7c << LDST_SRCDST_SHIFT)
212 #define LDST_SRCDST_BYTE_OUTFIFO	(0x7e << LDST_SRCDST_SHIFT)
213 
214 #define LDST_SRCDST_WORD_MODE_REG	(0x00 << LDST_SRCDST_SHIFT)
215 #define LDST_SRCDST_WORD_KEYSZ_REG	(0x01 << LDST_SRCDST_SHIFT)
216 #define LDST_SRCDST_WORD_DATASZ_REG	(0x02 << LDST_SRCDST_SHIFT)
217 #define LDST_SRCDST_WORD_ICVSZ_REG	(0x03 << LDST_SRCDST_SHIFT)
218 #define LDST_SRCDST_WORD_CHACTRL	(0x06 << LDST_SRCDST_SHIFT)
219 #define LDST_SRCDST_WORD_DECOCTRL	(0x06 << LDST_SRCDST_SHIFT)
220 #define LDST_SRCDST_WORD_IRQCTRL	(0x07 << LDST_SRCDST_SHIFT)
221 #define LDST_SRCDST_WORD_DECO_PCLOVRD	(0x07 << LDST_SRCDST_SHIFT)
222 #define LDST_SRCDST_WORD_CLRW		(0x08 << LDST_SRCDST_SHIFT)
223 #define LDST_SRCDST_WORD_DECO_MATH0	(0x08 << LDST_SRCDST_SHIFT)
224 #define LDST_SRCDST_WORD_STAT		(0x09 << LDST_SRCDST_SHIFT)
225 #define LDST_SRCDST_WORD_DECO_MATH1	(0x09 << LDST_SRCDST_SHIFT)
226 #define LDST_SRCDST_WORD_DECO_MATH2	(0x0a << LDST_SRCDST_SHIFT)
227 #define LDST_SRCDST_WORD_DECO_AAD_SZ	(0x0b << LDST_SRCDST_SHIFT)
228 #define LDST_SRCDST_WORD_DECO_MATH3	(0x0b << LDST_SRCDST_SHIFT)
229 #define LDST_SRCDST_WORD_CLASS1_ICV_SZ	(0x0c << LDST_SRCDST_SHIFT)
230 #define LDST_SRCDST_WORD_ALTDS_CLASS1	(0x0f << LDST_SRCDST_SHIFT)
231 #define LDST_SRCDST_WORD_PKHA_A_SZ	(0x10 << LDST_SRCDST_SHIFT)
232 #define LDST_SRCDST_WORD_PKHA_B_SZ	(0x11 << LDST_SRCDST_SHIFT)
233 #define LDST_SRCDST_WORD_PKHA_N_SZ	(0x12 << LDST_SRCDST_SHIFT)
234 #define LDST_SRCDST_WORD_PKHA_E_SZ	(0x13 << LDST_SRCDST_SHIFT)
235 #define LDST_SRCDST_WORD_CLASS_CTX	(0x20 << LDST_SRCDST_SHIFT)
236 #define LDST_SRCDST_WORD_DESCBUF	(0x40 << LDST_SRCDST_SHIFT)
237 #define LDST_SRCDST_WORD_DESCBUF_JOB	(0x41 << LDST_SRCDST_SHIFT)
238 #define LDST_SRCDST_WORD_DESCBUF_SHARED	(0x42 << LDST_SRCDST_SHIFT)
239 #define LDST_SRCDST_WORD_DESCBUF_JOB_WE	(0x45 << LDST_SRCDST_SHIFT)
240 #define LDST_SRCDST_WORD_DESCBUF_SHARED_WE (0x46 << LDST_SRCDST_SHIFT)
241 #define LDST_SRCDST_WORD_INFO_FIFO	(0x7a << LDST_SRCDST_SHIFT)
242 
243 /* Offset in source/destination */
244 #define LDST_OFFSET_SHIFT	8
245 #define LDST_OFFSET_MASK	(0xff << LDST_OFFSET_SHIFT)
246 
247 /* LDOFF definitions used when DST = LDST_SRCDST_WORD_DECOCTRL */
248 /* These could also be shifted by LDST_OFFSET_SHIFT - this reads better */
249 #define LDOFF_CHG_SHARE_SHIFT		0
250 #define LDOFF_CHG_SHARE_MASK		(0x3 << LDOFF_CHG_SHARE_SHIFT)
251 #define LDOFF_CHG_SHARE_NEVER		(0x1 << LDOFF_CHG_SHARE_SHIFT)
252 #define LDOFF_CHG_SHARE_OK_PROP		(0x2 << LDOFF_CHG_SHARE_SHIFT)
253 #define LDOFF_CHG_SHARE_OK_NO_PROP	(0x3 << LDOFF_CHG_SHARE_SHIFT)
254 
255 #define LDOFF_ENABLE_AUTO_NFIFO		(1 << 2)
256 #define LDOFF_DISABLE_AUTO_NFIFO	(1 << 3)
257 
258 #define LDOFF_CHG_NONSEQLIODN_SHIFT	4
259 #define LDOFF_CHG_NONSEQLIODN_MASK	(0x3 << LDOFF_CHG_NONSEQLIODN_SHIFT)
260 #define LDOFF_CHG_NONSEQLIODN_SEQ	(0x1 << LDOFF_CHG_NONSEQLIODN_SHIFT)
261 #define LDOFF_CHG_NONSEQLIODN_NON_SEQ	(0x2 << LDOFF_CHG_NONSEQLIODN_SHIFT)
262 #define LDOFF_CHG_NONSEQLIODN_TRUSTED	(0x3 << LDOFF_CHG_NONSEQLIODN_SHIFT)
263 
264 #define LDOFF_CHG_SEQLIODN_SHIFT	6
265 #define LDOFF_CHG_SEQLIODN_MASK		(0x3 << LDOFF_CHG_SEQLIODN_SHIFT)
266 #define LDOFF_CHG_SEQLIODN_SEQ		(0x1 << LDOFF_CHG_SEQLIODN_SHIFT)
267 #define LDOFF_CHG_SEQLIODN_NON_SEQ	(0x2 << LDOFF_CHG_SEQLIODN_SHIFT)
268 #define LDOFF_CHG_SEQLIODN_TRUSTED	(0x3 << LDOFF_CHG_SEQLIODN_SHIFT)
269 
270 /* Data length in bytes	*/
271 #define LDST_LEN_SHIFT		0
272 #define LDST_LEN_MASK		(0xff << LDST_LEN_SHIFT)
273 
274 /* Special Length definitions when dst=deco-ctrl */
275 #define LDLEN_ENABLE_OSL_COUNT		(1 << 7)
276 #define LDLEN_RST_CHA_OFIFO_PTR		(1 << 6)
277 #define LDLEN_RST_OFIFO			(1 << 5)
278 #define LDLEN_SET_OFIFO_OFF_VALID	(1 << 4)
279 #define LDLEN_SET_OFIFO_OFF_RSVD	(1 << 3)
280 #define LDLEN_SET_OFIFO_OFFSET_SHIFT	0
281 #define LDLEN_SET_OFIFO_OFFSET_MASK	(3 << LDLEN_SET_OFIFO_OFFSET_SHIFT)
282 
283 /*
284  * AAD Definitions
285  */
286 #define AES_KEY_SHIFT		8
287 #define LD_CCM_MODE		0x66
288 #define KEY_AES_SRC		(0x55 << AES_KEY_SHIFT)
289 
290 /*
291  * FIFO_LOAD/FIFO_STORE/SEQ_FIFO_LOAD/SEQ_FIFO_STORE
292  * Command Constructs
293  */
294 
295 /*
296  * Load Destination: 0 = skip (SEQ_FIFO_LOAD only),
297  * 1 = Load for Class1, 2 = Load for Class2, 3 = Load both
298  * Store Source: 0 = normal, 1 = Class1key, 2 = Class2key
299  */
300 #define FIFOLD_CLASS_SHIFT	25
301 #define FIFOLD_CLASS_MASK	(0x03 << FIFOLD_CLASS_SHIFT)
302 #define FIFOLD_CLASS_SKIP	(0x00 << FIFOLD_CLASS_SHIFT)
303 #define FIFOLD_CLASS_CLASS1	(0x01 << FIFOLD_CLASS_SHIFT)
304 #define FIFOLD_CLASS_CLASS2	(0x02 << FIFOLD_CLASS_SHIFT)
305 #define FIFOLD_CLASS_BOTH	(0x03 << FIFOLD_CLASS_SHIFT)
306 
307 #define FIFOST_CLASS_SHIFT	25
308 #define FIFOST_CLASS_MASK	(0x03 << FIFOST_CLASS_SHIFT)
309 #define FIFOST_CLASS_NORMAL	(0x00 << FIFOST_CLASS_SHIFT)
310 #define FIFOST_CLASS_CLASS1KEY	(0x01 << FIFOST_CLASS_SHIFT)
311 #define FIFOST_CLASS_CLASS2KEY	(0x02 << FIFOST_CLASS_SHIFT)
312 
313 /*
314  * Scatter-Gather Table/Variable Length Field
315  * If set for FIFO_LOAD, refers to a SG table. Within
316  * SEQ_FIFO_LOAD, is variable input sequence
317  */
318 #define FIFOLDST_SGF_SHIFT	24
319 #define FIFOLDST_SGF_MASK	(1 << FIFOLDST_SGF_SHIFT)
320 #define FIFOLDST_VLF_MASK	(1 << FIFOLDST_SGF_SHIFT)
321 #define FIFOLDST_SGF		(1 << FIFOLDST_SGF_SHIFT)
322 #define FIFOLDST_VLF		(1 << FIFOLDST_SGF_SHIFT)
323 
324 /* Immediate - Data follows command in descriptor */
325 #define FIFOLD_IMM_SHIFT	23
326 #define FIFOLD_IMM_MASK		(1 << FIFOLD_IMM_SHIFT)
327 #define FIFOLD_IMM		(1 << FIFOLD_IMM_SHIFT)
328 
329 /* Continue - Not the last FIFO store to come */
330 #define FIFOST_CONT_SHIFT	23
331 #define FIFOST_CONT_MASK	(1 << FIFOST_CONT_SHIFT)
332 
333 /*
334  * Extended Length - use 32-bit extended length that
335  * follows the pointer field. Illegal with IMM set
336  */
337 #define FIFOLDST_EXT_SHIFT	22
338 #define FIFOLDST_EXT_MASK	(1 << FIFOLDST_EXT_SHIFT)
339 #define FIFOLDST_EXT		(1 << FIFOLDST_EXT_SHIFT)
340 
341 /* Input data type.*/
342 #define FIFOLD_TYPE_SHIFT	16
343 #define FIFOLD_CONT_TYPE_SHIFT	19 /* shift past last-flush bits */
344 #define FIFOLD_TYPE_MASK	(0x3f << FIFOLD_TYPE_SHIFT)
345 
346 /* PK types */
347 #define FIFOLD_TYPE_PK		(0x00 << FIFOLD_TYPE_SHIFT)
348 #define FIFOLD_TYPE_PK_MASK	(0x30 << FIFOLD_TYPE_SHIFT)
349 #define FIFOLD_TYPE_PK_TYPEMASK (0x0f << FIFOLD_TYPE_SHIFT)
350 #define FIFOLD_TYPE_PK_A0	(0x00 << FIFOLD_TYPE_SHIFT)
351 #define FIFOLD_TYPE_PK_A1	(0x01 << FIFOLD_TYPE_SHIFT)
352 #define FIFOLD_TYPE_PK_A2	(0x02 << FIFOLD_TYPE_SHIFT)
353 #define FIFOLD_TYPE_PK_A3	(0x03 << FIFOLD_TYPE_SHIFT)
354 #define FIFOLD_TYPE_PK_B0	(0x04 << FIFOLD_TYPE_SHIFT)
355 #define FIFOLD_TYPE_PK_B1	(0x05 << FIFOLD_TYPE_SHIFT)
356 #define FIFOLD_TYPE_PK_B2	(0x06 << FIFOLD_TYPE_SHIFT)
357 #define FIFOLD_TYPE_PK_B3	(0x07 << FIFOLD_TYPE_SHIFT)
358 #define FIFOLD_TYPE_PK_N	(0x08 << FIFOLD_TYPE_SHIFT)
359 #define FIFOLD_TYPE_PK_A	(0x0c << FIFOLD_TYPE_SHIFT)
360 #define FIFOLD_TYPE_PK_B	(0x0d << FIFOLD_TYPE_SHIFT)
361 
362 /* Other types. Need to OR in last/flush bits as desired */
363 #define FIFOLD_TYPE_MSG_MASK	(0x38 << FIFOLD_TYPE_SHIFT)
364 #define FIFOLD_TYPE_MSG		(0x10 << FIFOLD_TYPE_SHIFT)
365 #define FIFOLD_TYPE_MSG1OUT2	(0x18 << FIFOLD_TYPE_SHIFT)
366 #define FIFOLD_TYPE_IV		(0x20 << FIFOLD_TYPE_SHIFT)
367 #define FIFOLD_TYPE_BITDATA	(0x28 << FIFOLD_TYPE_SHIFT)
368 #define FIFOLD_TYPE_AAD		(0x30 << FIFOLD_TYPE_SHIFT)
369 #define FIFOLD_TYPE_ICV		(0x38 << FIFOLD_TYPE_SHIFT)
370 
371 /* Last/Flush bits for use with "other" types above */
372 #define FIFOLD_TYPE_ACT_MASK	(0x07 << FIFOLD_TYPE_SHIFT)
373 #define FIFOLD_TYPE_NOACTION	(0x00 << FIFOLD_TYPE_SHIFT)
374 #define FIFOLD_TYPE_FLUSH1	(0x01 << FIFOLD_TYPE_SHIFT)
375 #define FIFOLD_TYPE_LAST1	(0x02 << FIFOLD_TYPE_SHIFT)
376 #define FIFOLD_TYPE_LAST2FLUSH	(0x03 << FIFOLD_TYPE_SHIFT)
377 #define FIFOLD_TYPE_LAST2	(0x04 << FIFOLD_TYPE_SHIFT)
378 #define FIFOLD_TYPE_LAST2FLUSH1 (0x05 << FIFOLD_TYPE_SHIFT)
379 #define FIFOLD_TYPE_LASTBOTH	(0x06 << FIFOLD_TYPE_SHIFT)
380 #define FIFOLD_TYPE_LASTBOTHFL	(0x07 << FIFOLD_TYPE_SHIFT)
381 #define FIFOLD_TYPE_NOINFOFIFO	(0x0F << FIFOLD_TYPE_SHIFT)
382 
383 #define FIFOLDST_LEN_MASK	0xffff
384 #define FIFOLDST_EXT_LEN_MASK	0xffffffff
385 
386 /* Output data types */
387 #define FIFOST_TYPE_SHIFT	16
388 #define FIFOST_TYPE_MASK	(0x3f << FIFOST_TYPE_SHIFT)
389 
390 #define FIFOST_TYPE_PKHA_A0	 (0x00 << FIFOST_TYPE_SHIFT)
391 #define FIFOST_TYPE_PKHA_A1	 (0x01 << FIFOST_TYPE_SHIFT)
392 #define FIFOST_TYPE_PKHA_A2	 (0x02 << FIFOST_TYPE_SHIFT)
393 #define FIFOST_TYPE_PKHA_A3	 (0x03 << FIFOST_TYPE_SHIFT)
394 #define FIFOST_TYPE_PKHA_B0	 (0x04 << FIFOST_TYPE_SHIFT)
395 #define FIFOST_TYPE_PKHA_B1	 (0x05 << FIFOST_TYPE_SHIFT)
396 #define FIFOST_TYPE_PKHA_B2	 (0x06 << FIFOST_TYPE_SHIFT)
397 #define FIFOST_TYPE_PKHA_B3	 (0x07 << FIFOST_TYPE_SHIFT)
398 #define FIFOST_TYPE_PKHA_N	 (0x08 << FIFOST_TYPE_SHIFT)
399 #define FIFOST_TYPE_PKHA_A	 (0x0c << FIFOST_TYPE_SHIFT)
400 #define FIFOST_TYPE_PKHA_B	 (0x0d << FIFOST_TYPE_SHIFT)
401 #define FIFOST_TYPE_AF_SBOX_JKEK (0x10 << FIFOST_TYPE_SHIFT)
402 #define FIFOST_TYPE_AF_SBOX_TKEK (0x21 << FIFOST_TYPE_SHIFT)
403 #define FIFOST_TYPE_PKHA_E_JKEK	 (0x22 << FIFOST_TYPE_SHIFT)
404 #define FIFOST_TYPE_PKHA_E_TKEK	 (0x23 << FIFOST_TYPE_SHIFT)
405 #define FIFOST_TYPE_KEY_KEK	 (0x24 << FIFOST_TYPE_SHIFT)
406 #define FIFOST_TYPE_KEY_TKEK	 (0x25 << FIFOST_TYPE_SHIFT)
407 #define FIFOST_TYPE_SPLIT_KEK	 (0x26 << FIFOST_TYPE_SHIFT)
408 #define FIFOST_TYPE_SPLIT_TKEK	 (0x27 << FIFOST_TYPE_SHIFT)
409 #define FIFOST_TYPE_OUTFIFO_KEK	 (0x28 << FIFOST_TYPE_SHIFT)
410 #define FIFOST_TYPE_OUTFIFO_TKEK (0x29 << FIFOST_TYPE_SHIFT)
411 #define FIFOST_TYPE_MESSAGE_DATA (0x30 << FIFOST_TYPE_SHIFT)
412 #define FIFOST_TYPE_RNGSTORE	 (0x34 << FIFOST_TYPE_SHIFT)
413 #define FIFOST_TYPE_RNGFIFO	 (0x35 << FIFOST_TYPE_SHIFT)
414 #define FIFOST_TYPE_SKIP	 (0x3f << FIFOST_TYPE_SHIFT)
415 
416 /*
417  * OPERATION Command Constructs
418  */
419 
420 /* Operation type selectors - OP TYPE */
421 #define OP_TYPE_SHIFT		24
422 #define OP_TYPE_MASK		(0x07 << OP_TYPE_SHIFT)
423 
424 #define OP_TYPE_UNI_PROTOCOL	(0x00 << OP_TYPE_SHIFT)
425 #define OP_TYPE_PK		(0x01 << OP_TYPE_SHIFT)
426 #define OP_TYPE_CLASS1_ALG	(0x02 << OP_TYPE_SHIFT)
427 #define OP_TYPE_CLASS2_ALG	(0x04 << OP_TYPE_SHIFT)
428 #define OP_TYPE_DECAP_PROTOCOL	(0x06 << OP_TYPE_SHIFT)
429 #define OP_TYPE_ENCAP_PROTOCOL	(0x07 << OP_TYPE_SHIFT)
430 
431 /* ProtocolID selectors - PROTID */
432 #define OP_PCLID_SHIFT		16
433 #define OP_PCLID_MASK		(0xff << 16)
434 
435 /* Assuming OP_TYPE = OP_TYPE_UNI_PROTOCOL */
436 #define OP_PCLID_SECMEM		0x08
437 #define OP_PCLID_BLOB		(0x0d << OP_PCLID_SHIFT)
438 #define OP_PCLID_SECRETKEY	(0x11 << OP_PCLID_SHIFT)
439 #define OP_PCLID_PUBLICKEYPAIR	(0x14 << OP_PCLID_SHIFT)
440 #define OP_PCLID_DSA_SIGN	(0x15 << OP_PCLID_SHIFT)
441 #define OP_PCLID_DSA_VERIFY	(0x16 << OP_PCLID_SHIFT)
442 
443 /* Assuming OP_TYPE = OP_TYPE_DECAP_PROTOCOL */
444 #define OP_PCLID_MP_PUB_KEY	(0x14 << OP_PCLID_SHIFT)
445 #define OP_PCLID_MP_SIGN	(0x15 << OP_PCLID_SHIFT)
446 
447 /* Assuming OP_TYPE = OP_TYPE_ENCAP_PROTOCOL */
448 #define OP_PCLID_MP_PRIV_KEY	(0x14 << OP_PCLID_SHIFT)
449 
450 /* PROTINFO fields for discrete log public key protocols */
451 #define OP_PROTINFO_F2M_FP	0x00000001
452 #define OP_PROTINFO_ECC_DL	0x00000002
453 #define OP_PROTINFO_ENC_PRI	0x00000004
454 #define OP_PROTINFO_TEST	0x00000008
455 #define OP_PROTINFO_EXT_PRI	0x00000010
456 #define OP_PROTINFO_ENC_Z	0x00000020
457 #define OP_PROTINFO_EKT_Z	0x00000040
458 #define OP_PROTINFO_MES_REP	0x00000400
459 #define OP_PROTINFO_HASH_MD5	0x00000000
460 #define OP_PROTINFO_HASH_SHA1	0x00000080
461 #define OP_PROTINFO_HASH_SHA224	0x00000100
462 #define OP_PROTINFO_HASH_SHA256	0x00000180
463 #define OP_PROTINFO_HASH_SHA384	0x00000200
464 #define OP_PROTINFO_HASH_SHA512	0x00000280
465 
466 /* For non-protocol/alg-only op commands */
467 #define OP_ALG_TYPE_SHIFT	24
468 #define OP_ALG_TYPE_MASK	(0x7 << OP_ALG_TYPE_SHIFT)
469 #define OP_ALG_TYPE_CLASS1	2
470 #define OP_ALG_TYPE_CLASS2	4
471 
472 #define OP_ALG_ALGSEL_SHIFT	16
473 #define OP_ALG_ALGSEL_MASK	(0xff << OP_ALG_ALGSEL_SHIFT)
474 #define OP_ALG_ALGSEL_SUBMASK	(0x0f << OP_ALG_ALGSEL_SHIFT)
475 #define OP_ALG_ALGSEL_AES	(0x10 << OP_ALG_ALGSEL_SHIFT)
476 #define OP_ALG_ALGSEL_DES	(0x20 << OP_ALG_ALGSEL_SHIFT)
477 #define OP_ALG_ALGSEL_3DES	(0x21 << OP_ALG_ALGSEL_SHIFT)
478 #define OP_ALG_ALGSEL_ARC4	(0x30 << OP_ALG_ALGSEL_SHIFT)
479 #define OP_ALG_ALGSEL_MD5	(0x40 << OP_ALG_ALGSEL_SHIFT)
480 #define OP_ALG_ALGSEL_SHA1	(0x41 << OP_ALG_ALGSEL_SHIFT)
481 #define OP_ALG_ALGSEL_SHA224	(0x42 << OP_ALG_ALGSEL_SHIFT)
482 #define OP_ALG_ALGSEL_SHA256	(0x43 << OP_ALG_ALGSEL_SHIFT)
483 #define OP_ALG_ALGSEL_SHA384	(0x44 << OP_ALG_ALGSEL_SHIFT)
484 #define OP_ALG_ALGSEL_SHA512	(0x45 << OP_ALG_ALGSEL_SHIFT)
485 #define OP_ALG_ALGSEL_RNG	(0x50 << OP_ALG_ALGSEL_SHIFT)
486 #define OP_ALG_ALGSEL_SNOW	(0x60 << OP_ALG_ALGSEL_SHIFT)
487 #define OP_ALG_ALGSEL_SNOW_F8	(0x60 << OP_ALG_ALGSEL_SHIFT)
488 #define OP_ALG_ALGSEL_KASUMI	(0x70 << OP_ALG_ALGSEL_SHIFT)
489 #define OP_ALG_ALGSEL_CRC	(0x90 << OP_ALG_ALGSEL_SHIFT)
490 #define OP_ALG_ALGSEL_SNOW_F9	(0xA0 << OP_ALG_ALGSEL_SHIFT)
491 
492 #define OP_ALG_AAI_SHIFT	4
493 #define OP_ALG_AAI_MASK		(0x1ff << OP_ALG_AAI_SHIFT)
494 
495 /* randomizer AAI set */
496 #define OP_ALG_AAI_RNG		(0x00 << OP_ALG_AAI_SHIFT)
497 #define OP_ALG_AAI_RNG_NZB	(0x10 << OP_ALG_AAI_SHIFT)
498 #define OP_ALG_AAI_RNG_OBP	(0x20 << OP_ALG_AAI_SHIFT)
499 
500 /* RNG4 AAI set */
501 #define OP_ALG_AAI_RNG4_SH_0	(0x00 << OP_ALG_AAI_SHIFT)
502 #define OP_ALG_AAI_RNG4_SH_1	(0x01 << OP_ALG_AAI_SHIFT)
503 #define OP_ALG_AAI_RNG4_PS	(0x40 << OP_ALG_AAI_SHIFT)
504 #define OP_ALG_AAI_RNG4_AI	(0x80 << OP_ALG_AAI_SHIFT)
505 #define OP_ALG_AAI_RNG4_SK	(0x100 << OP_ALG_AAI_SHIFT)
506 
507 /* hmac/smac AAI set */
508 #define OP_ALG_AAI_HASH		(0x00 << OP_ALG_AAI_SHIFT)
509 #define OP_ALG_AAI_HMAC		(0x01 << OP_ALG_AAI_SHIFT)
510 #define OP_ALG_AAI_SMAC		(0x02 << OP_ALG_AAI_SHIFT)
511 #define OP_ALG_AAI_HMAC_PRECOMP	(0x04 << OP_ALG_AAI_SHIFT)
512 
513 #define OP_ALG_AS_SHIFT		2
514 #define OP_ALG_AS_MASK		(0x3 << OP_ALG_AS_SHIFT)
515 #define OP_ALG_AS_UPDATE	(0 << OP_ALG_AS_SHIFT)
516 #define OP_ALG_AS_INIT		(1 << OP_ALG_AS_SHIFT)
517 #define OP_ALG_AS_FINALIZE	(2 << OP_ALG_AS_SHIFT)
518 #define OP_ALG_AS_INITFINAL	(3 << OP_ALG_AS_SHIFT)
519 
520 #define OP_ALG_ICV_SHIFT	1
521 #define OP_ALG_ICV_MASK		(1 << OP_ALG_ICV_SHIFT)
522 #define OP_ALG_ICV_OFF		(0 << OP_ALG_ICV_SHIFT)
523 #define OP_ALG_ICV_ON		(1 << OP_ALG_ICV_SHIFT)
524 
525 #define OP_ALG_PR_ON		0x02
526 
527 #define OP_ALG_DIR_SHIFT	0
528 #define OP_ALG_DIR_MASK		1
529 #define OP_ALG_DECRYPT		0
530 #define OP_ALG_ENCRYPT		1
531 
532 /* PKHA algorithm type set */
533 #define OP_ALG_PK		0x00800000
534 #define OP_ALG_PK_FUN_MASK	0x3f /* clrmem, modmath, or cpymem */
535 
536 /* PKHA mode modular-arithmetic functions */
537 #define OP_ALG_PKMODE_MOD_EXPO		0x006
538 
539 /*
540  * SEQ_IN_PTR Command Constructs
541  */
542 
543 /* Release Buffers */
544 #define SQIN_RBS	0x04000000
545 
546 /* Sequence pointer is really a descriptor */
547 #define SQIN_INL	0x02000000
548 
549 /* Sequence pointer is a scatter-gather table */
550 #define SQIN_SGF	0x01000000
551 
552 /* Appends to a previous pointer */
553 #define SQIN_PRE	0x00800000
554 
555 /* Use extended length following pointer */
556 #define SQIN_EXT	0x00400000
557 
558 /* Restore sequence with pointer/length */
559 #define SQIN_RTO	0x00200000
560 
561 /* Replace job descriptor */
562 #define SQIN_RJD	0x00100000
563 
564 #define SQIN_LEN_SHIFT		 0
565 #define SQIN_LEN_MASK		(0xffff << SQIN_LEN_SHIFT)
566 
567 /*
568  * SEQ_OUT_PTR Command Constructs
569  */
570 
571 /* Sequence pointer is a scatter-gather table */
572 #define SQOUT_SGF	0x01000000
573 
574 /* Appends to a previous pointer */
575 #define SQOUT_PRE	SQIN_PRE
576 
577 /* Restore sequence with pointer/length */
578 #define SQOUT_RTO	 SQIN_RTO
579 
580 /* Use extended length following pointer */
581 #define SQOUT_EXT	0x00400000
582 
583 #define SQOUT_LEN_SHIFT		0
584 #define SQOUT_LEN_MASK		(0xffff << SQOUT_LEN_SHIFT)
585 
586 /*
587  * MOVE Command Constructs
588  */
589 
590 #define MOVE_AUX_SHIFT		25
591 #define MOVE_AUX_MASK		(3 << MOVE_AUX_SHIFT)
592 #define MOVE_AUX_MS		(2 << MOVE_AUX_SHIFT)
593 #define MOVE_AUX_LS		(1 << MOVE_AUX_SHIFT)
594 
595 #define MOVE_WAITCOMP_SHIFT	24
596 #define MOVE_WAITCOMP_MASK	(1 << MOVE_WAITCOMP_SHIFT)
597 #define MOVE_WAITCOMP		(1 << MOVE_WAITCOMP_SHIFT)
598 
599 #define MOVE_SRC_SHIFT		20
600 #define MOVE_SRC_MASK		(0x0f << MOVE_SRC_SHIFT)
601 #define MOVE_SRC_CLASS1CTX	(0x00 << MOVE_SRC_SHIFT)
602 #define MOVE_SRC_CLASS2CTX	(0x01 << MOVE_SRC_SHIFT)
603 #define MOVE_SRC_OUTFIFO	(0x02 << MOVE_SRC_SHIFT)
604 #define MOVE_SRC_DESCBUF	(0x03 << MOVE_SRC_SHIFT)
605 #define MOVE_SRC_MATH0		(0x04 << MOVE_SRC_SHIFT)
606 #define MOVE_SRC_MATH1		(0x05 << MOVE_SRC_SHIFT)
607 #define MOVE_SRC_MATH2		(0x06 << MOVE_SRC_SHIFT)
608 #define MOVE_SRC_MATH3		(0x07 << MOVE_SRC_SHIFT)
609 #define MOVE_SRC_INFIFO		(0x08 << MOVE_SRC_SHIFT)
610 #define MOVE_SRC_INFIFO_CL	(0x09 << MOVE_SRC_SHIFT)
611 
612 #define MOVE_DEST_SHIFT		16
613 #define MOVE_DEST_MASK		(0x0f << MOVE_DEST_SHIFT)
614 #define MOVE_DEST_CLASS1CTX	(0x00 << MOVE_DEST_SHIFT)
615 #define MOVE_DEST_CLASS2CTX	(0x01 << MOVE_DEST_SHIFT)
616 #define MOVE_DEST_OUTFIFO	(0x02 << MOVE_DEST_SHIFT)
617 #define MOVE_DEST_DESCBUF	(0x03 << MOVE_DEST_SHIFT)
618 #define MOVE_DEST_MATH0		(0x04 << MOVE_DEST_SHIFT)
619 #define MOVE_DEST_MATH1		(0x05 << MOVE_DEST_SHIFT)
620 #define MOVE_DEST_MATH2		(0x06 << MOVE_DEST_SHIFT)
621 #define MOVE_DEST_MATH3		(0x07 << MOVE_DEST_SHIFT)
622 #define MOVE_DEST_CLASS1INFIFO	(0x08 << MOVE_DEST_SHIFT)
623 #define MOVE_DEST_CLASS2INFIFO	(0x09 << MOVE_DEST_SHIFT)
624 #define MOVE_DEST_INFIFO_NOINFO (0x0a << MOVE_DEST_SHIFT)
625 #define MOVE_DEST_PK_A		(0x0c << MOVE_DEST_SHIFT)
626 #define MOVE_DEST_CLASS1KEY	(0x0d << MOVE_DEST_SHIFT)
627 #define MOVE_DEST_CLASS2KEY	(0x0e << MOVE_DEST_SHIFT)
628 
629 #define MOVE_OFFSET_SHIFT	8
630 #define MOVE_OFFSET_MASK	(0xff << MOVE_OFFSET_SHIFT)
631 
632 #define MOVE_LEN_SHIFT		0
633 #define MOVE_LEN_MASK		(0xff << MOVE_LEN_SHIFT)
634 
635 #define MOVELEN_MRSEL_SHIFT	0
636 #define MOVELEN_MRSEL_MASK	(0x3 << MOVE_LEN_SHIFT)
637 
638 /*
639  * JUMP Command Constructs
640  */
641 
642 #define JUMP_CLASS_SHIFT	25
643 #define JUMP_CLASS_MASK		(3 << JUMP_CLASS_SHIFT)
644 #define JUMP_CLASS_NONE		0
645 #define JUMP_CLASS_CLASS1	(1 << JUMP_CLASS_SHIFT)
646 #define JUMP_CLASS_CLASS2	(2 << JUMP_CLASS_SHIFT)
647 #define JUMP_CLASS_BOTH		(3 << JUMP_CLASS_SHIFT)
648 
649 #define JUMP_JSL_SHIFT		24
650 #define JUMP_JSL_MASK		(1 << JUMP_JSL_SHIFT)
651 #define JUMP_JSL		(1 << JUMP_JSL_SHIFT)
652 
653 #define JUMP_TYPE_SHIFT		22
654 #define JUMP_TYPE_MASK		(0x03 << JUMP_TYPE_SHIFT)
655 #define JUMP_TYPE_LOCAL		(0x00 << JUMP_TYPE_SHIFT)
656 #define JUMP_TYPE_NONLOCAL	(0x01 << JUMP_TYPE_SHIFT)
657 #define JUMP_TYPE_HALT		(0x02 << JUMP_TYPE_SHIFT)
658 #define JUMP_TYPE_HALT_USER	(0x03 << JUMP_TYPE_SHIFT)
659 
660 #define JUMP_TEST_SHIFT		16
661 #define JUMP_TEST_MASK		(0x03 << JUMP_TEST_SHIFT)
662 #define JUMP_TEST_ALL		(0x00 << JUMP_TEST_SHIFT)
663 #define JUMP_TEST_INVALL	(0x01 << JUMP_TEST_SHIFT)
664 #define JUMP_TEST_ANY		(0x02 << JUMP_TEST_SHIFT)
665 #define JUMP_TEST_INVANY	(0x03 << JUMP_TEST_SHIFT)
666 
667 /* Condition codes. JSL bit is factored in */
668 #define JUMP_COND_SHIFT		8
669 #define JUMP_COND_MASK		(0x100ff << JUMP_COND_SHIFT)
670 #define JUMP_COND_PK_0		(0x80 << JUMP_COND_SHIFT)
671 #define JUMP_COND_PK_GCD_1	(0x40 << JUMP_COND_SHIFT)
672 #define JUMP_COND_PK_PRIME	(0x20 << JUMP_COND_SHIFT)
673 #define JUMP_COND_MATH_N	(0x08 << JUMP_COND_SHIFT)
674 #define JUMP_COND_MATH_Z	(0x04 << JUMP_COND_SHIFT)
675 #define JUMP_COND_MATH_C	(0x02 << JUMP_COND_SHIFT)
676 #define JUMP_COND_MATH_NV	(0x01 << JUMP_COND_SHIFT)
677 
678 #define JUMP_COND_JRP		((0x80 << JUMP_COND_SHIFT) | JUMP_JSL)
679 #define JUMP_COND_SHRD		((0x40 << JUMP_COND_SHIFT) | JUMP_JSL)
680 #define JUMP_COND_SELF		((0x20 << JUMP_COND_SHIFT) | JUMP_JSL)
681 #define JUMP_COND_CALM		((0x10 << JUMP_COND_SHIFT) | JUMP_JSL)
682 #define JUMP_COND_NIP		((0x08 << JUMP_COND_SHIFT) | JUMP_JSL)
683 #define JUMP_COND_NIFP		((0x04 << JUMP_COND_SHIFT) | JUMP_JSL)
684 #define JUMP_COND_NOP		((0x02 << JUMP_COND_SHIFT) | JUMP_JSL)
685 #define JUMP_COND_NCP		((0x01 << JUMP_COND_SHIFT) | JUMP_JSL)
686 
687 #define JUMP_OFFSET_SHIFT	0
688 #define JUMP_OFFSET_MASK	(0xff << JUMP_OFFSET_SHIFT)
689 
690 #define OP_ALG_RNG4_SHIFT      4
691 #define OP_ALG_RNG4_MAS                (0x1f3 << OP_ALG_RNG4_SHIFT)
692 #define OP_ALG_RNG4_SK         (0x100 << OP_ALG_RNG4_SHIFT)
693 
694 
695 /* Structures for Protocol Data Blocks */
696 struct __packed pdb_ecdsa_verify {
697 	uint32_t pdb_hdr;
698 	caam_dma_addr_t dma_q;	/* Pointer to q (elliptic curve) */
699 	caam_dma_addr_t dma_r;	/* Pointer to r (elliptic curve) */
700 	caam_dma_addr_t dma_g_xy;	/* Pointer to Gx,y (elliptic curve) */
701 	caam_dma_addr_t dma_pkey;	/* Pointer to Wx,y (public key) */
702 	caam_dma_addr_t dma_hash;	/* Pointer to hash input */
703 	caam_dma_addr_t dma_c;	/* Pointer to C_signature */
704 	caam_dma_addr_t dma_d;	/* Pointer to D_signature */
705 	caam_dma_addr_t dma_buf;	/* Pointer to 64-byte temp buffer */
706 	caam_dma_addr_t dma_ab;	/* Pointer to a,b (elliptic curve ) */
707 	uint32_t img_size;	/* Length of Message */
708 };
709 
710 struct __packed pdb_ecdsa_sign {
711 	uint32_t pdb_hdr;
712 	caam_dma_addr_t dma_q;	/* Pointer to q (elliptic curve) */
713 	caam_dma_addr_t dma_r;	/* Pointer to r (elliptic curve) */
714 	caam_dma_addr_t dma_g_xy;	/* Pointer to Gx,y (elliptic curve) */
715 	caam_dma_addr_t dma_pri_key;	/* Pointer to S (Private key) */
716 	caam_dma_addr_t dma_hash;	/* Pointer to hash input */
717 	caam_dma_addr_t dma_c;	/* Pointer to C_signature */
718 	caam_dma_addr_t dma_d;	/* Pointer to D_signature */
719 	caam_dma_addr_t dma_ab;	/* Pointer to a,b (elliptic curve ) */
720 	caam_dma_addr_t dma_u;	/* Pointer to Per Message Random */
721 	uint32_t img_size;	/* Length of Message */
722 };
723 
724 #define PDB_ECDSA_SGF_SHIFT	23
725 #define PDB_ECDSA_L_SHIFT	7
726 #define PDB_ECDSA_N_SHIFT	0
727 
728 struct __packed pdb_mp_pub_k {
729 	uint32_t pdb_hdr;
730 	#define PDB_MP_PUB_K_SGF_SHIFT		31
731 	caam_dma_addr_t dma_pkey;	/* Pointer to Wx,y (public key) */
732 };
733 
734 struct __packed pdb_mp_sign {
735 	uint32_t pdb_hdr;
736 	#define PDB_MP_SIGN_SGF_SHIFT		28
737 	caam_dma_addr_t dma_addr_msg;	/* Pointer to Message */
738 	caam_dma_addr_t dma_addr_hash;	/* Pointer to hash output */
739 	caam_dma_addr_t dma_addr_c_sig;	/* Pointer to C_signature */
740 	caam_dma_addr_t dma_addr_d_sig;	/* Pointer to D_signature */
741 	uint32_t img_size;		/* Length of Message */
742 };
743 
744 #define PDB_MP_CSEL_SHIFT	17
745 #define PDB_MP_CSEL_WIDTH	4
746 #define PDB_MP_CSEL_P256	0x3 << PDB_MP_CSEL_SHIFT	/* P-256 */
747 #define PDB_MP_CSEL_P384	0x4 << PDB_MP_CSEL_SHIFT	/* P-384 */
748 #define PDB_MP_CSEL_P521	0x5 << PDB_MP_CSEL_SHIFT	/* P-521 */
749 
750 #endif /* DESC_H */
751