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_crypto_asym.h>
10 #include <rte_memory.h>
13 * This file defines macros and structures according to microcode spec
17 #define CPT_MAJOR_OP_FC 0x33
18 #define CPT_MAJOR_OP_HASH 0x34
19 #define CPT_MAJOR_OP_HMAC 0x35
20 #define CPT_MAJOR_OP_ZUC_SNOW3G 0x37
21 #define CPT_MAJOR_OP_KASUMI 0x38
22 #define CPT_MAJOR_OP_MISC 0x01
25 #define CPT_MAJOR_OP_MODEX 0x03
26 #define CPT_MINOR_OP_MODEX 0x01
27 #define CPT_MINOR_OP_PKCS_ENC 0x02
28 #define CPT_MINOR_OP_PKCS_ENC_CRT 0x03
29 #define CPT_MINOR_OP_PKCS_DEC 0x04
30 #define CPT_MINOR_OP_PKCS_DEC_CRT 0x05
31 #define CPT_MINOR_OP_MODEX_CRT 0x06
33 #define CPT_BLOCK_TYPE1 0
34 #define CPT_BLOCK_TYPE2 1
36 #define CPT_BYTE_16 16
37 #define CPT_BYTE_24 24
38 #define CPT_BYTE_32 32
39 #define CPT_MAX_SG_IN_OUT_CNT 32
40 #define CPT_MAX_SG_CNT (CPT_MAX_SG_IN_OUT_CNT/2)
42 #define COMPLETION_CODE_SIZE 8
43 #define COMPLETION_CODE_INIT 0
45 #define SG_LIST_HDR_SIZE (8u)
46 #define SG_ENTRY_SIZE sizeof(sg_comp_t)
48 #define CPT_DMA_MODE (1 << 7)
50 #define CPT_FROM_CTX 0
51 #define CPT_FROM_DPTR 1
54 #define ZUC_SNOW3G 0x2
63 #define CPT_OP_CIPHER_ENCRYPT 0x1
64 #define CPT_OP_CIPHER_DECRYPT 0x2
65 #define CPT_OP_CIPHER_MASK 0x3
67 #define CPT_OP_AUTH_VERIFY 0x4
68 #define CPT_OP_AUTH_GENERATE 0x8
69 #define CPT_OP_AUTH_MASK 0xC
71 #define CPT_OP_ENCODE (CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
72 #define CPT_OP_DECODE (CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
74 /* #define CPT_ALWAYS_USE_SG_MODE */
75 #define CPT_ALWAYS_USE_SEPARATE_BUF
78 * Parameters for Flexi Crypto
81 #define VALID_AAD_BUF 0x01
82 #define VALID_MAC_BUF 0x02
83 #define VALID_IV_BUF 0x04
84 #define SINGLE_BUF_INPLACE 0x08
85 #define SINGLE_BUF_HEADTAILROOM 0x10
87 #define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff)
88 #define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff)
89 #define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff)
90 #define ENCR_DLEN(__d_lens) (__d_lens >> 32)
91 #define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff)
93 /* FC offset_control at start of DPTR in bytes */
94 #define OFF_CTRL_LEN 8 /**< bytes */
112 /* These are only for software use */
115 KASUMI_F9_CBC = 0x92,
116 KASUMI_F9_ECB = 0x93,
120 /* To support passthrough */
123 * These are defined by MC for Flexi crypto
124 * for field of 4 bits
135 /* These are only for software use */
138 KASUMI_F8_CBC = 0x92,
139 KASUMI_F8_ECB = 0x93,
149 /* Microcode errors */
151 ERR_OPCODE_UNSUPPORTED = 0x01,
154 ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
155 ERR_SCATTER_GATHER_LIST = 0x03,
156 ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
159 ERR_GC_LENGTH_INVALID = 0x41,
160 ERR_GC_RANDOM_LEN_INVALID = 0x42,
161 ERR_GC_DATA_LEN_INVALID = 0x43,
162 ERR_GC_DRBG_TYPE_INVALID = 0x44,
163 ERR_GC_CTX_LEN_INVALID = 0x45,
164 ERR_GC_CIPHER_UNSUPPORTED = 0x46,
165 ERR_GC_AUTH_UNSUPPORTED = 0x47,
166 ERR_GC_OFFSET_INVALID = 0x48,
167 ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
168 ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
169 ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
170 ERR_GC_ICV_MISCOMPARE = 0x4c,
171 ERR_GC_DATA_UNALIGNED = 0x4d,
174 ERR_BAD_ALT_CCODE = 0xfd,
175 ERR_REQ_PENDING = 0xfe,
176 ERR_REQ_TIMEOUT = 0xff,
178 ERR_BAD_INPUT_LENGTH = (0x40000000 | 384), /* 0x40000180 */
181 ERR_BAD_CONTEXT_HANDLE,
182 ERR_BAD_SCALAR_LENGTH,
183 ERR_BAD_DIGEST_LENGTH,
185 ERR_BAD_RECORD_PADDING,
186 ERR_NB_REQUEST_PENDING,
192 * Enumeration cpt_comp_e
194 * CPT Completion Enumeration
195 * Enumerates the values of CPT_RES_S[COMPCODE].
198 CPT_8X_COMP_E_NOTDONE = (0x00),
199 CPT_8X_COMP_E_GOOD = (0x01),
200 CPT_8X_COMP_E_FAULT = (0x02),
201 CPT_8X_COMP_E_SWERR = (0x03),
202 CPT_8X_COMP_E_HWERR = (0x04),
203 CPT_8X_COMP_E_LAST_ENTRY = (0xFF)
206 typedef struct sglist_comp {
216 struct cpt_sess_misc {
219 /** ZUC, SNOW3G & KASUMI flags */
221 /** Flag for AES GCM */
223 /** Flag for AES CTR */
225 /** Flag for NULL cipher/auth */
233 /** MAC len in bytes */
235 /** IV length in bytes */
237 /** Auth IV length in bytes */
238 uint8_t auth_iv_length;
239 /** Reserved field */
241 /** IV offset in bytes */
243 /** Auth IV offset in bytes */
244 uint16_t auth_iv_offset;
247 /** Context DMA address */
248 phys_addr_t ctx_dma_addr;
254 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
255 uint64_t enc_cipher : 4;
256 uint64_t reserved1 : 1;
257 uint64_t aes_key : 2;
258 uint64_t iv_source : 1;
259 uint64_t hash_type : 4;
260 uint64_t reserved2 : 3;
261 uint64_t auth_input_type : 1;
262 uint64_t mac_len : 8;
263 uint64_t reserved3 : 8;
264 uint64_t encr_offset : 16;
265 uint64_t iv_offset : 8;
266 uint64_t auth_offset : 8;
268 uint64_t auth_offset : 8;
269 uint64_t iv_offset : 8;
270 uint64_t encr_offset : 16;
271 uint64_t reserved3 : 8;
272 uint64_t mac_len : 8;
273 uint64_t auth_input_type : 1;
274 uint64_t reserved2 : 3;
275 uint64_t hash_type : 4;
276 uint64_t iv_source : 1;
277 uint64_t aes_key : 2;
278 uint64_t reserved1 : 1;
279 uint64_t enc_cipher : 4;
285 encr_ctrl_t enc_ctrl;
286 uint8_t encr_key[32];
293 } mc_fc_hmac_context_t;
296 mc_enc_context_t enc;
297 mc_fc_hmac_context_t hmac;
301 uint8_t encr_auth_iv[16];
303 uint8_t zuc_const[32];
304 } mc_zuc_snow3g_ctx_t;
312 /* Below fields are accessed by sw */
313 uint64_t enc_cipher :8;
314 uint64_t hash_type :8;
316 uint64_t auth_key_len :8;
319 uint64_t zsk_flags :3;
323 /* Below fields are accessed by hardware */
325 mc_fc_context_t fctx;
326 mc_zuc_snow3g_ctx_t zs_ctx;
327 mc_kasumi_ctx_t k_ctx;
329 uint8_t auth_key[64];
332 struct cpt_asym_sess_misc {
333 enum rte_crypto_asym_xform_type xfrm_type;
335 struct rte_crypto_rsa_xform rsa_ctx;
336 struct rte_crypto_modex_xform mod_ctx;
341 typedef struct buf_ptr {
343 phys_addr_t dma_addr;
354 typedef union opcode_info {
362 typedef struct fc_params {
384 * Parameters for asymmetric operations
386 struct asym_op_params {
387 struct cpt_request_info *req;
388 phys_addr_t meta_buf;
392 * Parameters for digest
394 * Only src_iov, op, ctx_buf, mac_buf, prep_req
395 * meta_buf, auth_data_len are used for digest gen.
397 typedef struct fc_params digest_params_t;
399 /* Cipher Algorithms */
400 typedef mc_cipher_type_t cipher_type_t;
402 /* Auth Algorithms */
403 typedef mc_hash_type_t auth_type_t;
407 #define CPT_P_ENC_CTRL(fctx) fctx->enc.enc_ctrl.e
409 #define SRC_IOV_SIZE \
410 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
411 #define DST_IOV_SIZE \
412 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
414 #define SESS_PRIV(__sess) \
415 (void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
418 * Get the session size
423 static __rte_always_inline unsigned int
424 cpt_get_session_size(void)
426 unsigned int ctx_len = sizeof(struct cpt_ctx);
427 return (sizeof(struct cpt_sess_misc) + RTE_ALIGN_CEIL(ctx_len, 8));
429 #endif /* _CPT_MCODE_DEFINES_H_ */