2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2017 Conrad Meyer <cem@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #define CMD_QUEUE_MASK_OFFSET 0x000
32 #define CMD_QUEUE_PRIO_OFFSET 0x004
33 #define CMD_REQID_CONFIG_OFFSET 0x008
34 #define TRNG_OUT_OFFSET 0x00C
35 #define CMD_CMD_TIMEOUT_OFFSET 0x010
36 #define LSB_PUBLIC_MASK_LO_OFFSET 0x018
37 #define LSB_PUBLIC_MASK_HI_OFFSET 0x01C
38 #define LSB_PRIVATE_MASK_LO_OFFSET 0x020
39 #define LSB_PRIVATE_MASK_HI_OFFSET 0x024
41 #define VERSION_REG 0x100
42 #define VERSION_NUM_MASK 0x3F
43 #define VERSION_CAP_MASK 0x7FC0
44 #define VERSION_CAP_AES (1 << 6)
45 #define VERSION_CAP_3DES (1 << 7)
46 #define VERSION_CAP_SHA (1 << 8)
47 #define VERSION_CAP_RSA (1 << 9)
48 #define VERSION_CAP_ECC (1 << 10)
49 #define VERSION_CAP_ZDE (1 << 11)
50 #define VERSION_CAP_ZCE (1 << 12)
51 #define VERSION_CAP_TRNG (1 << 13)
52 #define VERSION_CAP_ELFC (1 << 14)
53 #define VERSION_NUMVQM_SHIFT 15
54 #define VERSION_NUMVQM_MASK 0xF
55 #define VERSION_LSBSIZE_SHIFT 19
56 #define VERSION_LSBSIZE_MASK 0x3FF
58 #define CMD_Q_CONTROL_BASE 0x000
59 #define CMD_Q_TAIL_LO_BASE 0x004
60 #define CMD_Q_HEAD_LO_BASE 0x008
61 #define CMD_Q_INT_ENABLE_BASE 0x00C
62 #define CMD_Q_INTERRUPT_STATUS_BASE 0x010
64 #define CMD_Q_STATUS_BASE 0x100
65 #define CMD_Q_INT_STATUS_BASE 0x104
67 #define CMD_Q_STATUS_INCR 0x1000
69 /* Don't think there's much point in keeping these -- OS can't access: */
70 #define CMD_CONFIG_0_OFFSET 0x6000
71 #define CMD_TRNG_CTL_OFFSET 0x6008
72 #define CMD_AES_MASK_OFFSET 0x6010
73 #define CMD_CLK_GATE_CTL_OFFSET 0x603C
75 /* CMD_Q_CONTROL_BASE bits */
76 #define CMD_Q_RUN (1 << 0)
77 #define CMD_Q_HALTED (1 << 1)
78 #define CMD_Q_MEM_LOCATION (1 << 2)
79 #define CMD_Q_SIZE_SHIFT 3
80 #define CMD_Q_SIZE_MASK 0x1F
81 #define CMD_Q_PTR_HI_SHIFT 16
82 #define CMD_Q_PTR_HI_MASK 0xFFFF
85 * The following bits are used for both CMD_Q_INT_ENABLE_BASE and
86 * CMD_Q_INTERRUPT_STATUS_BASE.
88 #define INT_COMPLETION (1 << 0)
89 #define INT_ERROR (1 << 1)
90 #define INT_QUEUE_STOPPED (1 << 2)
91 #define INT_QUEUE_EMPTY (1 << 3)
92 #define ALL_INTERRUPTS (INT_COMPLETION | \
97 #define STATUS_ERROR_MASK 0x3F
98 #define STATUS_JOBSTATUS_SHIFT 7
99 #define STATUS_JOBSTATUS_MASK 0x7
100 #define STATUS_ERRORSOURCE_SHIFT 10
101 #define STATUS_ERRORSOURCE_MASK 0x3
102 #define STATUS_VLSB_FAULTBLOCK_SHIFT 12
103 #define STATUS_VLSB_FAULTBLOCK_MASK 0x7
105 /* From JOBSTATUS field in STATUS register above */
106 #define JOBSTATUS_IDLE 0
107 #define JOBSTATUS_ACTIVE_WAITING 1
108 #define JOBSTATUS_ACTIVE 2
109 #define JOBSTATUS_WAIT_ABORT 3
110 #define JOBSTATUS_DYN_ERROR 4
111 #define JOBSTATUS_PREPARE_HALT 5
113 /* From ERRORSOURCE field in STATUS register */
114 #define ERRORSOURCE_INPUT_MEMORY 0
115 #define ERRORSOURCE_CMD_DESCRIPTOR 1
116 #define ERRORSOURCE_INPUT_DATA 2
117 #define ERRORSOURCE_KEY_DATA 3
119 #define Q_DESC_SIZE sizeof(struct ccp_desc)
122 CCP_AES_MODE_ECB = 0,
130 CCP_AES_MODE_IAPM_NIST,
131 CCP_AES_MODE_IAPM_IPSEC,
133 /* Not a real hardware mode; used as a sentinel value internally. */
137 enum ccp_aes_ghash_mode {
138 CCP_AES_MODE_GHASH_AAD = 0,
139 CCP_AES_MODE_GHASH_FINAL,
143 CCP_AES_TYPE_128 = 0,
149 CCP_DES_MODE_ECB = 0,
155 CCP_DES_TYPE_128 = 0, /* 112 + 16 parity */
156 CCP_DES_TYPE_192, /* 168 + 24 parity */
173 enum ccp_cipher_algo {
174 CCP_CIPHER_ALGO_AES_CBC = 0,
175 CCP_CIPHER_ALGO_AES_ECB,
176 CCP_CIPHER_ALGO_AES_CTR,
177 CCP_CIPHER_ALGO_AES_GCM,
178 CCP_CIPHER_ALGO_3DES_CBC,
181 enum ccp_cipher_dir {
182 CCP_CIPHER_DIR_DECRYPT = 0,
183 CCP_CIPHER_DIR_ENCRYPT = 1,
187 CCP_AUTH_ALGO_SHA1 = 0,
188 CCP_AUTH_ALGO_SHA1_HMAC,
189 CCP_AUTH_ALGO_SHA224,
190 CCP_AUTH_ALGO_SHA224_HMAC,
191 CCP_AUTH_ALGO_SHA3_224,
192 CCP_AUTH_ALGO_SHA3_224_HMAC,
193 CCP_AUTH_ALGO_SHA256,
194 CCP_AUTH_ALGO_SHA256_HMAC,
195 CCP_AUTH_ALGO_SHA3_256,
196 CCP_AUTH_ALGO_SHA3_256_HMAC,
197 CCP_AUTH_ALGO_SHA384,
198 CCP_AUTH_ALGO_SHA384_HMAC,
199 CCP_AUTH_ALGO_SHA3_384,
200 CCP_AUTH_ALGO_SHA3_384_HMAC,
201 CCP_AUTH_ALGO_SHA512,
202 CCP_AUTH_ALGO_SHA512_HMAC,
203 CCP_AUTH_ALGO_SHA3_512,
204 CCP_AUTH_ALGO_SHA3_512_HMAC,
205 CCP_AUTH_ALGO_AES_CMAC,
206 CCP_AUTH_ALGO_AES_GCM,
210 CCP_AUTH_OP_GENERATE = 0,
211 CCP_AUTH_OP_VERIFY = 1,
221 CCP_ENGINE_ZLIB_DECOMPRESS,
225 enum ccp_xts_unitsize {
226 CCP_XTS_AES_UNIT_SIZE_16 = 0,
227 CCP_XTS_AES_UNIT_SIZE_512,
228 CCP_XTS_AES_UNIT_SIZE_1024,
229 CCP_XTS_AES_UNIT_SIZE_2048,
230 CCP_XTS_AES_UNIT_SIZE_4096,
233 enum ccp_passthru_bitwise {
234 CCP_PASSTHRU_BITWISE_NOOP = 0,
235 CCP_PASSTHRU_BITWISE_AND,
236 CCP_PASSTHRU_BITWISE_OR,
237 CCP_PASSTHRU_BITWISE_XOR,
238 CCP_PASSTHRU_BITWISE_MASK,
241 enum ccp_passthru_byteswap {
242 CCP_PASSTHRU_BYTESWAP_NOOP = 0,
243 CCP_PASSTHRU_BYTESWAP_32BIT,
244 CCP_PASSTHRU_BYTESWAP_256BIT,
248 * descriptor for version 5 CPP commands
250 * word 0: function; engine; control bits
251 * word 1: length of source data
252 * word 2: low 32 bits of source pointer
253 * word 3: upper 16 bits of source pointer; source memory type
254 * word 4: low 32 bits of destination pointer
255 * word 5: upper 16 bits of destination pointer; destination memory
257 * word 6: low 32 bits of key pointer
258 * word 7: upper 16 bits of key pointer; key memory type
264 uint32_t hoc:1; /* Halt on completion */
265 uint32_t ioc:1; /* Intr. on completion */
266 uint32_t reserved_1:1;
267 uint32_t som:1; /* Start of message */
268 uint32_t eom:1; /* End " */
275 uint32_t reserved_2:7;
278 uint32_t hoc:1; /* Halt on completion */
279 uint32_t ioc:1; /* Intr. on completion */
280 uint32_t reserved_1:1;
281 uint32_t som:1; /* Start of message */
282 uint32_t eom:1; /* End " */
289 uint32_t reserved_2:7;
292 uint32_t hoc:1; /* Halt on completion */
293 uint32_t ioc:1; /* Intr. on completion */
294 uint32_t reserved_1:1;
295 uint32_t som:1; /* Start of message */
296 uint32_t eom:1; /* End " */
299 uint32_t reserved_2:5;
303 uint32_t reserved_3:7;
306 uint32_t hoc:1; /* Halt on completion */
307 uint32_t ioc:1; /* Intr. on completion */
308 uint32_t reserved_1:1;
309 uint32_t som:1; /* Start of message */
310 uint32_t eom:1; /* End " */
311 uint32_t reserved_2:10;
313 uint32_t reserved_3:1;
316 uint32_t reserved_4:7;
319 uint32_t hoc:1; /* Halt on completion */
320 uint32_t ioc:1; /* Intr. on completion */
321 uint32_t reserved_1:1;
322 uint32_t som:1; /* Start of message */
323 uint32_t eom:1; /* End " */
328 uint32_t reserved_2:7;
331 uint32_t hoc:1; /* Halt on completion */
332 uint32_t ioc:1; /* Intr. on completion */
333 uint32_t reserved_1:1;
334 uint32_t som:1; /* Start of message */
335 uint32_t eom:1; /* End " */
339 uint32_t reserved_2:8;
342 uint32_t reserved_3:7;
345 uint32_t hoc:1; /* Halt on completion */
346 uint32_t ioc:1; /* Intr. on completion */
347 uint32_t reserved_1:1;
348 uint32_t som:1; /* Start of message */
349 uint32_t eom:1; /* End " */
350 uint32_t reserved_2:13;
351 uint32_t reserved_3:2;
354 uint32_t reserved_4:7;
357 uint32_t hoc:1; /* Halt on completion */
358 uint32_t ioc:1; /* Intr. on completion */
359 uint32_t reserved_1:1;
360 uint32_t som:1; /* Start of message */
361 uint32_t eom:1; /* End " */
367 uint32_t reserved_2:7;
370 uint32_t hoc:1; /* Halt on completion */
371 uint32_t ioc:1; /* Intr. on completion */
372 uint32_t reserved_1:1;
373 uint32_t som:1; /* Start of message */
374 uint32_t eom:1; /* End " */
375 uint32_t function:15;
378 uint32_t reserved_2:7;
388 uint32_t lsb_ctx_id:8;
389 uint32_t reserved_3:5;
390 uint32_t src_fixed:1;
394 uint32_t dst_lo; /* NON-SHA */
395 uint32_t sha_len_lo; /* SHA */
402 uint32_t reserved_4:13;
403 uint32_t dst_fixed:1;
413 uint32_t reserved_5:14;
418 CCP_MEMTYPE_SYSTEM = 0,
429 CCP_CMD_NOT_SUPPORTED,