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