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
21 #define CPT_MAJOR_OP_MISC 0x01
23 #define CPT_BYTE_16 16
24 #define CPT_BYTE_24 24
25 #define CPT_BYTE_32 32
26 #define CPT_MAX_SG_IN_OUT_CNT 32
27 #define CPT_MAX_SG_CNT (CPT_MAX_SG_IN_OUT_CNT/2)
29 #define COMPLETION_CODE_SIZE 8
30 #define COMPLETION_CODE_INIT 0
32 #define SG_LIST_HDR_SIZE (8u)
33 #define SG_ENTRY_SIZE sizeof(sg_comp_t)
35 #define CPT_DMA_MODE (1 << 7)
37 #define CPT_FROM_CTX 0
38 #define CPT_FROM_DPTR 1
41 #define ZUC_SNOW3G 0x2
50 #define CPT_OP_CIPHER_ENCRYPT 0x1
51 #define CPT_OP_CIPHER_DECRYPT 0x2
52 #define CPT_OP_CIPHER_MASK 0x3
54 #define CPT_OP_AUTH_VERIFY 0x4
55 #define CPT_OP_AUTH_GENERATE 0x8
56 #define CPT_OP_AUTH_MASK 0xC
58 #define CPT_OP_ENCODE (CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
59 #define CPT_OP_DECODE (CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
61 /* #define CPT_ALWAYS_USE_SG_MODE */
62 #define CPT_ALWAYS_USE_SEPARATE_BUF
65 * Parameters for Flexi Crypto
68 #define VALID_AAD_BUF 0x01
69 #define VALID_MAC_BUF 0x02
70 #define VALID_IV_BUF 0x04
71 #define SINGLE_BUF_INPLACE 0x08
72 #define SINGLE_BUF_HEADTAILROOM 0x10
74 #define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff)
75 #define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff)
76 #define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff)
77 #define ENCR_DLEN(__d_lens) (__d_lens >> 32)
78 #define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff)
80 /* FC offset_control at start of DPTR in bytes */
81 #define OFF_CTRL_LEN 8 /**< bytes */
99 /* These are only for software use */
102 KASUMI_F9_CBC = 0x92,
103 KASUMI_F9_ECB = 0x93,
107 /* To support passthrough */
110 * These are defined by MC for Flexi crypto
111 * for field of 4 bits
122 /* These are only for software use */
125 KASUMI_F8_CBC = 0x92,
126 KASUMI_F8_ECB = 0x93,
136 /* Microcode errors */
138 ERR_OPCODE_UNSUPPORTED = 0x01,
141 ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
142 ERR_SCATTER_GATHER_LIST = 0x03,
143 ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
146 ERR_GC_LENGTH_INVALID = 0x41,
147 ERR_GC_RANDOM_LEN_INVALID = 0x42,
148 ERR_GC_DATA_LEN_INVALID = 0x43,
149 ERR_GC_DRBG_TYPE_INVALID = 0x44,
150 ERR_GC_CTX_LEN_INVALID = 0x45,
151 ERR_GC_CIPHER_UNSUPPORTED = 0x46,
152 ERR_GC_AUTH_UNSUPPORTED = 0x47,
153 ERR_GC_OFFSET_INVALID = 0x48,
154 ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
155 ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
156 ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
157 ERR_GC_ICV_MISCOMPARE = 0x4c,
158 ERR_GC_DATA_UNALIGNED = 0x4d,
161 ERR_BAD_ALT_CCODE = 0xfd,
162 ERR_REQ_PENDING = 0xfe,
163 ERR_REQ_TIMEOUT = 0xff,
165 ERR_BAD_INPUT_LENGTH = (0x40000000 | 384), /* 0x40000180 */
168 ERR_BAD_CONTEXT_HANDLE,
169 ERR_BAD_SCALAR_LENGTH,
170 ERR_BAD_DIGEST_LENGTH,
172 ERR_BAD_RECORD_PADDING,
173 ERR_NB_REQUEST_PENDING,
178 typedef struct sglist_comp {
188 struct cpt_sess_misc {
191 /** ZUC, SNOW3G & KASUMI flags */
193 /** Flag for AES GCM */
195 /** Flag for AES CTR */
197 /** Flag for NULL cipher/auth */
203 /** MAC len in bytes */
205 /** IV length in bytes */
207 /** Auth IV length in bytes */
208 uint8_t auth_iv_length;
209 /** Reserved field */
211 /** IV offset in bytes */
213 /** Auth IV offset in bytes */
214 uint16_t auth_iv_offset;
217 /** Context DMA address */
218 phys_addr_t ctx_dma_addr;
224 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
225 uint64_t enc_cipher : 4;
226 uint64_t reserved1 : 1;
227 uint64_t aes_key : 2;
228 uint64_t iv_source : 1;
229 uint64_t hash_type : 4;
230 uint64_t reserved2 : 3;
231 uint64_t auth_input_type : 1;
232 uint64_t mac_len : 8;
233 uint64_t reserved3 : 8;
234 uint64_t encr_offset : 16;
235 uint64_t iv_offset : 8;
236 uint64_t auth_offset : 8;
238 uint64_t auth_offset : 8;
239 uint64_t iv_offset : 8;
240 uint64_t encr_offset : 16;
241 uint64_t reserved3 : 8;
242 uint64_t mac_len : 8;
243 uint64_t auth_input_type : 1;
244 uint64_t reserved2 : 3;
245 uint64_t hash_type : 4;
246 uint64_t iv_source : 1;
247 uint64_t aes_key : 2;
248 uint64_t reserved1 : 1;
249 uint64_t enc_cipher : 4;
255 encr_ctrl_t enc_ctrl;
256 uint8_t encr_key[32];
263 } mc_fc_hmac_context_t;
266 mc_enc_context_t enc;
267 mc_fc_hmac_context_t hmac;
271 uint8_t encr_auth_iv[16];
273 uint8_t zuc_const[32];
274 } mc_zuc_snow3g_ctx_t;
282 /* Below fields are accessed by sw */
283 uint64_t enc_cipher :8;
284 uint64_t hash_type :8;
286 uint64_t auth_key_len :8;
289 uint64_t zsk_flags :3;
293 /* Below fields are accessed by hardware */
295 mc_fc_context_t fctx;
296 mc_zuc_snow3g_ctx_t zs_ctx;
297 mc_kasumi_ctx_t k_ctx;
299 uint8_t auth_key[64];
303 typedef struct buf_ptr {
305 phys_addr_t dma_addr;
316 typedef union opcode_info {
324 typedef struct fc_params {
346 * Parameters for digest
348 * Only src_iov, op, ctx_buf, mac_buf, prep_req
349 * meta_buf, auth_data_len are used for digest gen.
351 typedef struct fc_params digest_params_t;
353 /* Cipher Algorithms */
354 typedef mc_cipher_type_t cipher_type_t;
356 /* Auth Algorithms */
357 typedef mc_hash_type_t auth_type_t;
361 #define CPT_P_ENC_CTRL(fctx) fctx->enc.enc_ctrl.e
363 #define SRC_IOV_SIZE \
364 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
365 #define DST_IOV_SIZE \
366 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
368 #define SESS_PRIV(__sess) \
369 (void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
371 #endif /* _CPT_MCODE_DEFINES_H_ */