2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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
33 #define CMD_QUEUE_MASK_OFFSET 0x000
34 #define CMD_QUEUE_PRIO_OFFSET 0x004
35 #define CMD_REQID_CONFIG_OFFSET 0x008
36 #define TRNG_OUT_OFFSET 0x00C
37 #define CMD_CMD_TIMEOUT_OFFSET 0x010
38 #define LSB_PUBLIC_MASK_LO_OFFSET 0x018
39 #define LSB_PUBLIC_MASK_HI_OFFSET 0x01C
40 #define LSB_PRIVATE_MASK_LO_OFFSET 0x020
41 #define LSB_PRIVATE_MASK_HI_OFFSET 0x024
43 #define VERSION_REG 0x100
44 #define VERSION_NUM_MASK 0x3F
45 #define VERSION_CAP_MASK 0x7FC0
46 #define VERSION_CAP_AES (1 << 6)
47 #define VERSION_CAP_3DES (1 << 7)
48 #define VERSION_CAP_SHA (1 << 8)
49 #define VERSION_CAP_RSA (1 << 9)
50 #define VERSION_CAP_ECC (1 << 10)
51 #define VERSION_CAP_ZDE (1 << 11)
52 #define VERSION_CAP_ZCE (1 << 12)
53 #define VERSION_CAP_TRNG (1 << 13)
54 #define VERSION_CAP_ELFC (1 << 14)
55 #define VERSION_NUMVQM_SHIFT 15
56 #define VERSION_NUMVQM_MASK 0xF
57 #define VERSION_LSBSIZE_SHIFT 19
58 #define VERSION_LSBSIZE_MASK 0x3FF
60 #define CMD_Q_CONTROL_BASE 0x000
61 #define CMD_Q_TAIL_LO_BASE 0x004
62 #define CMD_Q_HEAD_LO_BASE 0x008
63 #define CMD_Q_INT_ENABLE_BASE 0x00C
64 #define CMD_Q_INTERRUPT_STATUS_BASE 0x010
66 #define CMD_Q_STATUS_BASE 0x100
67 #define CMD_Q_INT_STATUS_BASE 0x104
69 #define CMD_Q_STATUS_INCR 0x1000
71 /* Don't think there's much point in keeping these -- OS can't access: */
72 #define CMD_CONFIG_0_OFFSET 0x6000
73 #define CMD_TRNG_CTL_OFFSET 0x6008
74 #define CMD_AES_MASK_OFFSET 0x6010
75 #define CMD_CLK_GATE_CTL_OFFSET 0x603C
77 /* CMD_Q_CONTROL_BASE bits */
78 #define CMD_Q_RUN (1 << 0)
79 #define CMD_Q_HALTED (1 << 1)
80 #define CMD_Q_MEM_LOCATION (1 << 2)
81 #define CMD_Q_SIZE_SHIFT 3
82 #define CMD_Q_SIZE_MASK 0x1F
83 #define CMD_Q_PTR_HI_SHIFT 16
84 #define CMD_Q_PTR_HI_MASK 0xFFFF
87 * The following bits are used for both CMD_Q_INT_ENABLE_BASE and
88 * CMD_Q_INTERRUPT_STATUS_BASE.
90 #define INT_COMPLETION (1 << 0)
91 #define INT_ERROR (1 << 1)
92 #define INT_QUEUE_STOPPED (1 << 2)
93 #define INT_QUEUE_EMPTY (1 << 3)
94 #define ALL_INTERRUPTS (INT_COMPLETION | \
99 #define STATUS_ERROR_MASK 0x3F
100 #define STATUS_JOBSTATUS_SHIFT 7
101 #define STATUS_JOBSTATUS_MASK 0x7
102 #define STATUS_ERRORSOURCE_SHIFT 10
103 #define STATUS_ERRORSOURCE_MASK 0x3
104 #define STATUS_VLSB_FAULTBLOCK_SHIFT 12
105 #define STATUS_VLSB_FAULTBLOCK_MASK 0x7
107 /* From JOBSTATUS field in STATUS register above */
108 #define JOBSTATUS_IDLE 0
109 #define JOBSTATUS_ACTIVE_WAITING 1
110 #define JOBSTATUS_ACTIVE 2
111 #define JOBSTATUS_WAIT_ABORT 3
112 #define JOBSTATUS_DYN_ERROR 4
113 #define JOBSTATUS_PREPARE_HALT 5
115 /* From ERRORSOURCE field in STATUS register */
116 #define ERRORSOURCE_INPUT_MEMORY 0
117 #define ERRORSOURCE_CMD_DESCRIPTOR 1
118 #define ERRORSOURCE_INPUT_DATA 2
119 #define ERRORSOURCE_KEY_DATA 3
121 #define Q_DESC_SIZE sizeof(struct ccp_desc)
124 CCP_AES_MODE_ECB = 0,
132 CCP_AES_MODE_IAPM_NIST,
133 CCP_AES_MODE_IAPM_IPSEC,
135 /* Not a real hardware mode; used as a sentinel value internally. */
139 enum ccp_aes_ghash_mode {
140 CCP_AES_MODE_GHASH_AAD = 0,
141 CCP_AES_MODE_GHASH_FINAL,
145 CCP_AES_TYPE_128 = 0,
151 CCP_DES_MODE_ECB = 0,
157 CCP_DES_TYPE_128 = 0, /* 112 + 16 parity */
158 CCP_DES_TYPE_192, /* 168 + 24 parity */
175 enum ccp_cipher_algo {
176 CCP_CIPHER_ALGO_AES_CBC = 0,
177 CCP_CIPHER_ALGO_AES_ECB,
178 CCP_CIPHER_ALGO_AES_CTR,
179 CCP_CIPHER_ALGO_AES_GCM,
180 CCP_CIPHER_ALGO_3DES_CBC,
183 enum ccp_cipher_dir {
184 CCP_CIPHER_DIR_DECRYPT = 0,
185 CCP_CIPHER_DIR_ENCRYPT = 1,
189 CCP_AUTH_ALGO_SHA1 = 0,
190 CCP_AUTH_ALGO_SHA1_HMAC,
191 CCP_AUTH_ALGO_SHA224,
192 CCP_AUTH_ALGO_SHA224_HMAC,
193 CCP_AUTH_ALGO_SHA3_224,
194 CCP_AUTH_ALGO_SHA3_224_HMAC,
195 CCP_AUTH_ALGO_SHA256,
196 CCP_AUTH_ALGO_SHA256_HMAC,
197 CCP_AUTH_ALGO_SHA3_256,
198 CCP_AUTH_ALGO_SHA3_256_HMAC,
199 CCP_AUTH_ALGO_SHA384,
200 CCP_AUTH_ALGO_SHA384_HMAC,
201 CCP_AUTH_ALGO_SHA3_384,
202 CCP_AUTH_ALGO_SHA3_384_HMAC,
203 CCP_AUTH_ALGO_SHA512,
204 CCP_AUTH_ALGO_SHA512_HMAC,
205 CCP_AUTH_ALGO_SHA3_512,
206 CCP_AUTH_ALGO_SHA3_512_HMAC,
207 CCP_AUTH_ALGO_AES_CMAC,
208 CCP_AUTH_ALGO_AES_GCM,
212 CCP_AUTH_OP_GENERATE = 0,
213 CCP_AUTH_OP_VERIFY = 1,
223 CCP_ENGINE_ZLIB_DECOMPRESS,
227 enum ccp_xts_unitsize {
228 CCP_XTS_AES_UNIT_SIZE_16 = 0,
229 CCP_XTS_AES_UNIT_SIZE_512,
230 CCP_XTS_AES_UNIT_SIZE_1024,
231 CCP_XTS_AES_UNIT_SIZE_2048,
232 CCP_XTS_AES_UNIT_SIZE_4096,
235 enum ccp_passthru_bitwise {
236 CCP_PASSTHRU_BITWISE_NOOP = 0,
237 CCP_PASSTHRU_BITWISE_AND,
238 CCP_PASSTHRU_BITWISE_OR,
239 CCP_PASSTHRU_BITWISE_XOR,
240 CCP_PASSTHRU_BITWISE_MASK,
243 enum ccp_passthru_byteswap {
244 CCP_PASSTHRU_BYTESWAP_NOOP = 0,
245 CCP_PASSTHRU_BYTESWAP_32BIT,
246 CCP_PASSTHRU_BYTESWAP_256BIT,
250 * descriptor for version 5 CPP commands
252 * word 0: function; engine; control bits
253 * word 1: length of source data
254 * word 2: low 32 bits of source pointer
255 * word 3: upper 16 bits of source pointer; source memory type
256 * word 4: low 32 bits of destination pointer
257 * word 5: upper 16 bits of destination pointer; destination memory
259 * word 6: low 32 bits of key pointer
260 * word 7: upper 16 bits of key pointer; key memory type
266 uint32_t hoc:1; /* Halt on completion */
267 uint32_t ioc:1; /* Intr. on completion */
268 uint32_t reserved_1:1;
269 uint32_t som:1; /* Start of message */
270 uint32_t eom:1; /* End " */
277 uint32_t reserved_2:7;
280 uint32_t hoc:1; /* Halt on completion */
281 uint32_t ioc:1; /* Intr. on completion */
282 uint32_t reserved_1:1;
283 uint32_t som:1; /* Start of message */
284 uint32_t eom:1; /* End " */
291 uint32_t reserved_2:7;
294 uint32_t hoc:1; /* Halt on completion */
295 uint32_t ioc:1; /* Intr. on completion */
296 uint32_t reserved_1:1;
297 uint32_t som:1; /* Start of message */
298 uint32_t eom:1; /* End " */
301 uint32_t reserved_2:5;
305 uint32_t reserved_3:7;
308 uint32_t hoc:1; /* Halt on completion */
309 uint32_t ioc:1; /* Intr. on completion */
310 uint32_t reserved_1:1;
311 uint32_t som:1; /* Start of message */
312 uint32_t eom:1; /* End " */
313 uint32_t reserved_2:10;
315 uint32_t reserved_3:1;
318 uint32_t reserved_4:7;
321 uint32_t hoc:1; /* Halt on completion */
322 uint32_t ioc:1; /* Intr. on completion */
323 uint32_t reserved_1:1;
324 uint32_t som:1; /* Start of message */
325 uint32_t eom:1; /* End " */
330 uint32_t reserved_2:7;
333 uint32_t hoc:1; /* Halt on completion */
334 uint32_t ioc:1; /* Intr. on completion */
335 uint32_t reserved_1:1;
336 uint32_t som:1; /* Start of message */
337 uint32_t eom:1; /* End " */
341 uint32_t reserved_2:8;
344 uint32_t reserved_3:7;
347 uint32_t hoc:1; /* Halt on completion */
348 uint32_t ioc:1; /* Intr. on completion */
349 uint32_t reserved_1:1;
350 uint32_t som:1; /* Start of message */
351 uint32_t eom:1; /* End " */
352 uint32_t reserved_2:13;
353 uint32_t reserved_3:2;
356 uint32_t reserved_4:7;
359 uint32_t hoc:1; /* Halt on completion */
360 uint32_t ioc:1; /* Intr. on completion */
361 uint32_t reserved_1:1;
362 uint32_t som:1; /* Start of message */
363 uint32_t eom:1; /* End " */
369 uint32_t reserved_2:7;
372 uint32_t hoc:1; /* Halt on completion */
373 uint32_t ioc:1; /* Intr. on completion */
374 uint32_t reserved_1:1;
375 uint32_t som:1; /* Start of message */
376 uint32_t eom:1; /* End " */
377 uint32_t function:15;
380 uint32_t reserved_2:7;
390 uint32_t lsb_ctx_id:8;
391 uint32_t reserved_3:5;
392 uint32_t src_fixed:1;
396 uint32_t dst_lo; /* NON-SHA */
397 uint32_t sha_len_lo; /* SHA */
404 uint32_t reserved_4:13;
405 uint32_t dst_fixed:1;
415 uint32_t reserved_5:14;
420 CCP_MEMTYPE_SYSTEM = 0,
431 CCP_CMD_NOT_SUPPORTED,