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
23 #define CPT_HMAC_FIRST_BIT_POS 0x4
24 #define CPT_FC_MINOR_OP_ENCRYPT 0x0
25 #define CPT_FC_MINOR_OP_DECRYPT 0x1
28 #define CPT_MAJOR_OP_MODEX 0x03
29 #define CPT_MAJOR_OP_ECDSA 0x04
30 #define CPT_MAJOR_OP_ECC 0x05
31 #define CPT_MINOR_OP_MODEX 0x01
32 #define CPT_MINOR_OP_PKCS_ENC 0x02
33 #define CPT_MINOR_OP_PKCS_ENC_CRT 0x03
34 #define CPT_MINOR_OP_PKCS_DEC 0x04
35 #define CPT_MINOR_OP_PKCS_DEC_CRT 0x05
36 #define CPT_MINOR_OP_MODEX_CRT 0x06
37 #define CPT_MINOR_OP_ECDSA_SIGN 0x01
38 #define CPT_MINOR_OP_ECDSA_VERIFY 0x02
39 #define CPT_MINOR_OP_ECC_UMP 0x03
41 #define CPT_BLOCK_TYPE1 0
42 #define CPT_BLOCK_TYPE2 1
44 #define CPT_MAX_SG_IN_OUT_CNT 32
45 #define CPT_MAX_SG_CNT (CPT_MAX_SG_IN_OUT_CNT/2)
47 #define COMPLETION_CODE_SIZE 8
48 #define COMPLETION_CODE_INIT 0
50 #define SG_LIST_HDR_SIZE (8u)
51 #define SG_ENTRY_SIZE sizeof(sg_comp_t)
53 #define CPT_DMA_MODE (1 << 7)
55 #define CPT_FROM_CTX 0
56 #define CPT_FROM_DPTR 1
59 #define ZUC_SNOW3G 0x2
68 #define CPT_OP_CIPHER_ENCRYPT 0x1
69 #define CPT_OP_CIPHER_DECRYPT 0x2
70 #define CPT_OP_CIPHER_MASK 0x3
72 #define CPT_OP_AUTH_VERIFY 0x4
73 #define CPT_OP_AUTH_GENERATE 0x8
74 #define CPT_OP_AUTH_MASK 0xC
76 #define CPT_OP_ENCODE (CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
77 #define CPT_OP_DECODE (CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
79 /* #define CPT_ALWAYS_USE_SG_MODE */
80 #define CPT_ALWAYS_USE_SEPARATE_BUF
83 * Parameters for Flexi Crypto
86 #define VALID_AAD_BUF 0x01
87 #define VALID_MAC_BUF 0x02
88 #define VALID_IV_BUF 0x04
89 #define SINGLE_BUF_INPLACE 0x08
90 #define SINGLE_BUF_HEADTAILROOM 0x10
92 #define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff)
93 #define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff)
94 #define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff)
95 #define ENCR_DLEN(__d_lens) (__d_lens >> 32)
96 #define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff)
98 /* FC offset_control at start of DPTR in bytes */
99 #define OFF_CTRL_LEN 8 /**< bytes */
117 /* These are only for software use */
120 KASUMI_F9_CBC = 0x92,
121 KASUMI_F9_ECB = 0x93,
125 /* To support passthrough */
128 * These are defined by MC for Flexi crypto
129 * for field of 4 bits
141 /* These are only for software use */
144 KASUMI_F8_CBC = 0x92,
145 KASUMI_F8_ECB = 0x93,
155 /* Microcode errors */
157 ERR_OPCODE_UNSUPPORTED = 0x01,
160 ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
161 ERR_SCATTER_GATHER_LIST = 0x03,
162 ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
165 ERR_GC_LENGTH_INVALID = 0x41,
166 ERR_GC_RANDOM_LEN_INVALID = 0x42,
167 ERR_GC_DATA_LEN_INVALID = 0x43,
168 ERR_GC_DRBG_TYPE_INVALID = 0x44,
169 ERR_GC_CTX_LEN_INVALID = 0x45,
170 ERR_GC_CIPHER_UNSUPPORTED = 0x46,
171 ERR_GC_AUTH_UNSUPPORTED = 0x47,
172 ERR_GC_OFFSET_INVALID = 0x48,
173 ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
174 ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
175 ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
176 ERR_GC_ICV_MISCOMPARE = 0x4c,
177 ERR_GC_DATA_UNALIGNED = 0x4d,
180 ERR_BAD_ALT_CCODE = 0xfd,
181 ERR_REQ_PENDING = 0xfe,
182 ERR_REQ_TIMEOUT = 0xff,
184 ERR_BAD_INPUT_LENGTH = (0x40000000 | 384), /* 0x40000180 */
187 ERR_BAD_CONTEXT_HANDLE,
188 ERR_BAD_SCALAR_LENGTH,
189 ERR_BAD_DIGEST_LENGTH,
191 ERR_BAD_RECORD_PADDING,
192 ERR_NB_REQUEST_PENDING,
198 * Enumeration cpt_comp_e
200 * CPT Completion Enumeration
201 * Enumerates the values of CPT_RES_S[COMPCODE].
204 CPT_8X_COMP_E_NOTDONE = (0x00),
205 CPT_8X_COMP_E_GOOD = (0x01),
206 CPT_8X_COMP_E_FAULT = (0x02),
207 CPT_8X_COMP_E_SWERR = (0x03),
208 CPT_8X_COMP_E_HWERR = (0x04),
209 CPT_8X_COMP_E_LAST_ENTRY = (0xFF)
213 * Enumeration cpt_ec_id
215 * Enumerates supported elliptic curves
226 typedef struct sglist_comp {
236 struct cpt_sess_misc {
239 /** ZUC, SNOW3G & KASUMI flags */
241 /** Flag for AES GCM */
243 /** Flag for AES CTR */
245 /** Flag for CHACHA POLY */
246 uint16_t chacha_poly:1;
247 /** Flag for NULL cipher/auth */
255 /** MAC len in bytes */
257 /** IV length in bytes */
259 /** Auth IV length in bytes */
260 uint8_t auth_iv_length;
263 /** IV offset in bytes */
265 /** Auth IV offset in bytes */
266 uint16_t auth_iv_offset;
269 /** CPT inst word 7 */
270 uint64_t cpt_inst_w7;
271 /** Context DMA address */
272 phys_addr_t ctx_dma_addr;
276 uint64_t iv_source : 1;
277 uint64_t aes_key : 2;
278 uint64_t rsvd_60 : 1;
279 uint64_t enc_cipher : 4;
280 uint64_t auth_input_type : 1;
281 uint64_t rsvd_52_54 : 3;
282 uint64_t hash_type : 4;
283 uint64_t mac_len : 8;
284 uint64_t rsvd_39_0 : 40;
285 uint8_t encr_key[32];
292 } mc_fc_hmac_context_t;
295 mc_enc_context_t enc;
296 mc_fc_hmac_context_t hmac;
300 uint8_t encr_auth_iv[16];
302 uint8_t zuc_const[32];
303 } mc_zuc_snow3g_ctx_t;
311 /* Below fields are accessed by sw */
312 uint64_t enc_cipher :8;
313 uint64_t hash_type :8;
315 uint64_t auth_key_len :8;
318 uint64_t zsk_flags :3;
320 uint64_t auth_enc :1;
321 uint64_t dec_auth :1;
324 /* Below fields are accessed by hardware */
326 mc_fc_context_t fctx;
327 mc_zuc_snow3g_ctx_t zs_ctx;
328 mc_kasumi_ctx_t k_ctx;
330 uint8_t auth_key[1024];
333 /* Prime and order fields of built-in elliptic curves */
334 struct cpt_ec_group {
336 /* P521 maximum length */
342 /* P521 maximum length */
348 struct cpt_asym_ec_ctx {
349 /* Prime length defined by microcode for EC operations */
353 struct cpt_asym_sess_misc {
354 enum rte_crypto_asym_xform_type xfrm_type;
356 struct rte_crypto_rsa_xform rsa_ctx;
357 struct rte_crypto_modex_xform mod_ctx;
358 struct cpt_asym_ec_ctx ec_ctx;
360 uint64_t cpt_inst_w7;
364 typedef struct buf_ptr {
366 phys_addr_t dma_addr;
377 typedef struct fc_params {
399 * Parameters for asymmetric operations
401 struct asym_op_params {
402 struct cpt_request_info *req;
403 phys_addr_t meta_buf;
407 * Parameters for digest
409 * Only src_iov, op, ctx_buf, mac_buf, prep_req
410 * meta_buf, auth_data_len are used for digest gen.
412 typedef struct fc_params digest_params_t;
414 /* Cipher Algorithms */
415 typedef mc_cipher_type_t cipher_type_t;
417 /* Auth Algorithms */
418 typedef mc_hash_type_t auth_type_t;
422 #define SRC_IOV_SIZE \
423 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
424 #define DST_IOV_SIZE \
425 (sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
427 #define SESS_PRIV(__sess) \
428 (void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
430 #define GET_SESS_FC_TYPE(__sess) \
431 (((struct cpt_ctx *)(SESS_PRIV(__sess)))->fc_type)
434 * Get the session size
439 static __rte_always_inline unsigned int
440 cpt_get_session_size(void)
442 unsigned int ctx_len = sizeof(struct cpt_ctx);
443 return (sizeof(struct cpt_sess_misc) + RTE_ALIGN_CEIL(ctx_len, 8));
445 #endif /* _CPT_MCODE_DEFINES_H_ */