1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium, Inc
5 #ifndef _CPT_MCODE_DEFINES_H_
6 #define _CPT_MCODE_DEFINES_H_
8 #include <rte_byteorder.h>
9 #include <rte_memory.h>
12 * This file defines macros and structures according to microcode spec
16 #define CPT_MAJOR_OP_FC 0x33
17 #define CPT_MAJOR_OP_HASH 0x34
18 #define CPT_MAJOR_OP_HMAC 0x35
19 #define CPT_MAJOR_OP_ZUC_SNOW3G 0x37
20 #define CPT_MAJOR_OP_KASUMI 0x38
22 #define CPT_BYTE_16 16
23 #define CPT_BYTE_24 24
24 #define CPT_BYTE_32 32
25 #define CPT_MAX_SG_IN_OUT_CNT 32
26 #define CPT_MAX_SG_CNT (CPT_MAX_SG_IN_OUT_CNT/2)
28 #define COMPLETION_CODE_SIZE 8
29 #define COMPLETION_CODE_INIT 0
31 #define SG_LIST_HDR_SIZE (8u)
32 #define SG_ENTRY_SIZE sizeof(sg_comp_t)
34 #define CPT_DMA_MODE (1 << 7)
36 #define CPT_FROM_CTX 0
37 #define CPT_FROM_DPTR 1
40 #define ZUC_SNOW3G 0x2
49 #define CPT_OP_CIPHER_ENCRYPT 0x1
50 #define CPT_OP_CIPHER_DECRYPT 0x2
51 #define CPT_OP_CIPHER_MASK 0x3
53 #define CPT_OP_AUTH_VERIFY 0x4
54 #define CPT_OP_AUTH_GENERATE 0x8
55 #define CPT_OP_AUTH_MASK 0xC
57 #define CPT_OP_ENCODE (CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
58 #define CPT_OP_DECODE (CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
60 /* #define CPT_ALWAYS_USE_SG_MODE */
61 #define CPT_ALWAYS_USE_SEPARATE_BUF
64 * Parameters for Flexi Crypto
67 #define VALID_AAD_BUF 0x01
68 #define VALID_MAC_BUF 0x02
69 #define VALID_IV_BUF 0x04
70 #define SINGLE_BUF_INPLACE 0x08
71 #define SINGLE_BUF_HEADTAILROOM 0x10
73 #define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff)
74 #define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff)
75 #define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff)
76 #define ENCR_DLEN(__d_lens) (__d_lens >> 32)
77 #define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff)
79 /* FC offset_control at start of DPTR in bytes */
80 #define OFF_CTRL_LEN 8 /**< bytes */
98 /* These are only for software use */
101 KASUMI_F9_CBC = 0x92,
102 KASUMI_F9_ECB = 0x93,
106 /* To support passthrough */
109 * These are defined by MC for Flexi crypto
110 * for field of 4 bits
121 /* These are only for software use */
124 KASUMI_F8_CBC = 0x92,
125 KASUMI_F8_ECB = 0x93,
135 /* Microcode errors */
137 ERR_OPCODE_UNSUPPORTED = 0x01,
140 ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
141 ERR_SCATTER_GATHER_LIST = 0x03,
142 ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
145 ERR_GC_LENGTH_INVALID = 0x41,
146 ERR_GC_RANDOM_LEN_INVALID = 0x42,
147 ERR_GC_DATA_LEN_INVALID = 0x43,
148 ERR_GC_DRBG_TYPE_INVALID = 0x44,
149 ERR_GC_CTX_LEN_INVALID = 0x45,
150 ERR_GC_CIPHER_UNSUPPORTED = 0x46,
151 ERR_GC_AUTH_UNSUPPORTED = 0x47,
152 ERR_GC_OFFSET_INVALID = 0x48,
153 ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
154 ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
155 ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
156 ERR_GC_ICV_MISCOMPARE = 0x4c,
157 ERR_GC_DATA_UNALIGNED = 0x4d,
160 ERR_BAD_ALT_CCODE = 0xfd,
161 ERR_REQ_PENDING = 0xfe,
162 ERR_REQ_TIMEOUT = 0xff,
164 ERR_BAD_INPUT_LENGTH = (0x40000000 | 384), /* 0x40000180 */
167 ERR_BAD_CONTEXT_HANDLE,
168 ERR_BAD_SCALAR_LENGTH,
169 ERR_BAD_DIGEST_LENGTH,
171 ERR_BAD_RECORD_PADDING,
172 ERR_NB_REQUEST_PENDING,
177 typedef struct sglist_comp {
187 struct cpt_sess_misc {
190 /** ZUC, SNOW3G & KASUMI flags */
192 /** Flag for AES GCM */
194 /** Flag for AES CTR */
196 /** Flag for NULL cipher/auth */
202 /** MAC len in bytes */
204 /** IV length in bytes */
206 /** Auth IV length in bytes */
207 uint8_t auth_iv_length;
208 /** Reserved field */
210 /** IV offset in bytes */
212 /** Auth IV offset in bytes */
213 uint16_t auth_iv_offset;
216 /** Context DMA address */
217 phys_addr_t ctx_dma_addr;
223 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
224 uint64_t enc_cipher : 4;
225 uint64_t reserved1 : 1;
226 uint64_t aes_key : 2;
227 uint64_t iv_source : 1;
228 uint64_t hash_type : 4;
229 uint64_t reserved2 : 3;
230 uint64_t auth_input_type : 1;
231 uint64_t mac_len : 8;
232 uint64_t reserved3 : 8;
233 uint64_t encr_offset : 16;
234 uint64_t iv_offset : 8;
235 uint64_t auth_offset : 8;
237 uint64_t auth_offset : 8;
238 uint64_t iv_offset : 8;
239 uint64_t encr_offset : 16;
240 uint64_t reserved3 : 8;
241 uint64_t mac_len : 8;
242 uint64_t auth_input_type : 1;
243 uint64_t reserved2 : 3;
244 uint64_t hash_type : 4;
245 uint64_t iv_source : 1;
246 uint64_t aes_key : 2;
247 uint64_t reserved1 : 1;
248 uint64_t enc_cipher : 4;
254 encr_ctrl_t enc_ctrl;
255 uint8_t encr_key[32];
262 } mc_fc_hmac_context_t;
265 mc_enc_context_t enc;
266 mc_fc_hmac_context_t hmac;
270 uint8_t encr_auth_iv[16];
272 uint8_t zuc_const[32];
273 } mc_zuc_snow3g_ctx_t;
281 /* Below fields are accessed by sw */
282 uint64_t enc_cipher :8;
283 uint64_t hash_type :8;
285 uint64_t auth_key_len :8;
288 uint64_t zsk_flags :3;
292 /* Below fields are accessed by hardware */
294 mc_fc_context_t fctx;
295 mc_zuc_snow3g_ctx_t zs_ctx;
296 mc_kasumi_ctx_t k_ctx;
298 uint8_t auth_key[64];
302 typedef struct buf_ptr {
304 phys_addr_t dma_addr;
315 typedef union opcode_info {
323 typedef struct fc_params {
344 typedef struct fc_params digest_params_t;
346 /* Cipher Algorithms */
347 typedef mc_cipher_type_t cipher_type_t;
349 /* Auth Algorithms */
350 typedef mc_hash_type_t auth_type_t;
354 #define CPT_P_ENC_CTRL(fctx) fctx->enc.enc_ctrl.e
356 #define SRC_IOV_SIZE \
357 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
358 #define DST_IOV_SIZE \
359 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
361 #define SESS_PRIV(__sess) \
362 (void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
364 #endif /* _CPT_MCODE_DEFINES_H_ */