xref: /dpdk/drivers/common/cpt/cpt_mcode_defines.h (revision cb7842f23eadf33e7227ab0fcab2bb7f4dfb2eea)
18846a756SAnoob Joseph /* SPDX-License-Identifier: BSD-3-Clause
28846a756SAnoob Joseph  * Copyright(c) 2018 Cavium, Inc
38846a756SAnoob Joseph  */
48846a756SAnoob Joseph 
58846a756SAnoob Joseph #ifndef _CPT_MCODE_DEFINES_H_
68846a756SAnoob Joseph #define _CPT_MCODE_DEFINES_H_
78846a756SAnoob Joseph 
843d01767SNithin Dabilpuram #include <rte_byteorder.h>
933bcaae5SKanaka Durga Kotamarthy #include <rte_crypto_asym.h>
1043d01767SNithin Dabilpuram #include <rte_memory.h>
1143d01767SNithin Dabilpuram 
128846a756SAnoob Joseph /*
138846a756SAnoob Joseph  * This file defines macros and structures according to microcode spec
148846a756SAnoob Joseph  *
158846a756SAnoob Joseph  */
169be415daSNithin Dabilpuram /* SE opcodes */
179be415daSNithin Dabilpuram #define CPT_MAJOR_OP_FC		0x33
189be415daSNithin Dabilpuram #define CPT_MAJOR_OP_HASH	0x34
199be415daSNithin Dabilpuram #define CPT_MAJOR_OP_HMAC	0x35
209be415daSNithin Dabilpuram #define CPT_MAJOR_OP_ZUC_SNOW3G	0x37
219be415daSNithin Dabilpuram #define CPT_MAJOR_OP_KASUMI	0x38
22351fbee2SSrisivasubramanian S #define CPT_MAJOR_OP_MISC	0x01
238846a756SAnoob Joseph 
24e9a356e2SSunila Sahu /* AE opcodes */
25e9a356e2SSunila Sahu #define CPT_MAJOR_OP_MODEX	0x03
26aa2cbd32SSunila Sahu #define CPT_MAJOR_OP_ECDSA	0x04
2799faef83SSunila Sahu #define CPT_MAJOR_OP_ECC	0x05
28e9a356e2SSunila Sahu #define CPT_MINOR_OP_MODEX	0x01
29e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_ENC	0x02
30e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
31e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_DEC	0x04
32e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_DEC_CRT	0x05
33e9a356e2SSunila Sahu #define CPT_MINOR_OP_MODEX_CRT	0x06
34aa2cbd32SSunila Sahu #define CPT_MINOR_OP_ECDSA_SIGN	0x01
35aa2cbd32SSunila Sahu #define CPT_MINOR_OP_ECDSA_VERIFY	0x02
3699faef83SSunila Sahu #define CPT_MINOR_OP_ECC_UMP	0x03
37e9a356e2SSunila Sahu 
38e9a356e2SSunila Sahu #define CPT_BLOCK_TYPE1 0
39e9a356e2SSunila Sahu #define CPT_BLOCK_TYPE2 1
40e9a356e2SSunila Sahu 
418846a756SAnoob Joseph #define CPT_BYTE_16		16
428846a756SAnoob Joseph #define CPT_BYTE_24		24
438846a756SAnoob Joseph #define CPT_BYTE_32		32
448846a756SAnoob Joseph #define CPT_MAX_SG_IN_OUT_CNT	32
458846a756SAnoob Joseph #define CPT_MAX_SG_CNT		(CPT_MAX_SG_IN_OUT_CNT/2)
468846a756SAnoob Joseph 
478846a756SAnoob Joseph #define COMPLETION_CODE_SIZE	8
488846a756SAnoob Joseph #define COMPLETION_CODE_INIT	0
498846a756SAnoob Joseph 
508846a756SAnoob Joseph #define SG_LIST_HDR_SIZE	(8u)
518846a756SAnoob Joseph #define SG_ENTRY_SIZE		sizeof(sg_comp_t)
528846a756SAnoob Joseph 
536cc54096SNithin Dabilpuram #define CPT_DMA_MODE		(1 << 7)
546cc54096SNithin Dabilpuram 
556cc54096SNithin Dabilpuram #define CPT_FROM_CTX		0
566cc54096SNithin Dabilpuram #define CPT_FROM_DPTR		1
576cc54096SNithin Dabilpuram 
586cc54096SNithin Dabilpuram #define FC_GEN			0x1
596cc54096SNithin Dabilpuram #define ZUC_SNOW3G		0x2
606cc54096SNithin Dabilpuram #define KASUMI			0x3
616cc54096SNithin Dabilpuram #define HASH_HMAC		0x4
626cc54096SNithin Dabilpuram 
636cc54096SNithin Dabilpuram #define ZS_EA			0x1
646cc54096SNithin Dabilpuram #define ZS_IA			0x2
656cc54096SNithin Dabilpuram #define K_F8			0x4
666cc54096SNithin Dabilpuram #define K_F9			0x8
676cc54096SNithin Dabilpuram 
686cc54096SNithin Dabilpuram #define CPT_OP_CIPHER_ENCRYPT	0x1
696cc54096SNithin Dabilpuram #define CPT_OP_CIPHER_DECRYPT	0x2
706cc54096SNithin Dabilpuram #define CPT_OP_CIPHER_MASK	0x3
716cc54096SNithin Dabilpuram 
726cc54096SNithin Dabilpuram #define CPT_OP_AUTH_VERIFY	0x4
736cc54096SNithin Dabilpuram #define CPT_OP_AUTH_GENERATE	0x8
746cc54096SNithin Dabilpuram #define CPT_OP_AUTH_MASK	0xC
756cc54096SNithin Dabilpuram 
766cc54096SNithin Dabilpuram #define CPT_OP_ENCODE	(CPT_OP_CIPHER_ENCRYPT | CPT_OP_AUTH_GENERATE)
776cc54096SNithin Dabilpuram #define CPT_OP_DECODE	(CPT_OP_CIPHER_DECRYPT | CPT_OP_AUTH_VERIFY)
786cc54096SNithin Dabilpuram 
798846a756SAnoob Joseph /* #define CPT_ALWAYS_USE_SG_MODE */
808846a756SAnoob Joseph #define CPT_ALWAYS_USE_SEPARATE_BUF
818846a756SAnoob Joseph 
829be415daSNithin Dabilpuram /*
839be415daSNithin Dabilpuram  * Parameters for Flexi Crypto
849be415daSNithin Dabilpuram  * requests
859be415daSNithin Dabilpuram  */
869be415daSNithin Dabilpuram #define VALID_AAD_BUF 0x01
879be415daSNithin Dabilpuram #define VALID_MAC_BUF 0x02
889be415daSNithin Dabilpuram #define VALID_IV_BUF 0x04
899be415daSNithin Dabilpuram #define SINGLE_BUF_INPLACE 0x08
909be415daSNithin Dabilpuram #define SINGLE_BUF_HEADTAILROOM 0x10
919be415daSNithin Dabilpuram 
929be415daSNithin Dabilpuram #define ENCR_IV_OFFSET(__d_offs) ((__d_offs >> 32) & 0xffff)
939be415daSNithin Dabilpuram #define ENCR_OFFSET(__d_offs) ((__d_offs >> 16) & 0xffff)
949be415daSNithin Dabilpuram #define AUTH_OFFSET(__d_offs) (__d_offs & 0xffff)
959be415daSNithin Dabilpuram #define ENCR_DLEN(__d_lens) (__d_lens >> 32)
969be415daSNithin Dabilpuram #define AUTH_DLEN(__d_lens) (__d_lens & 0xffffffff)
979be415daSNithin Dabilpuram 
989be415daSNithin Dabilpuram /* FC offset_control at start of DPTR in bytes */
999be415daSNithin Dabilpuram #define OFF_CTRL_LEN  8 /**< bytes */
1009be415daSNithin Dabilpuram 
1016cc54096SNithin Dabilpuram typedef enum {
1026cc54096SNithin Dabilpuram 	MD5_TYPE        = 1,
1036cc54096SNithin Dabilpuram 	SHA1_TYPE       = 2,
1046cc54096SNithin Dabilpuram 	SHA2_SHA224     = 3,
1056cc54096SNithin Dabilpuram 	SHA2_SHA256     = 4,
1066cc54096SNithin Dabilpuram 	SHA2_SHA384     = 5,
1076cc54096SNithin Dabilpuram 	SHA2_SHA512     = 6,
1086cc54096SNithin Dabilpuram 	GMAC_TYPE       = 7,
109*cb7842f2STejasree Kondoj 	POLY1305        = 8,
1106cc54096SNithin Dabilpuram 	SHA3_SHA224     = 10,
1116cc54096SNithin Dabilpuram 	SHA3_SHA256     = 11,
1126cc54096SNithin Dabilpuram 	SHA3_SHA384     = 12,
1136cc54096SNithin Dabilpuram 	SHA3_SHA512     = 13,
1146cc54096SNithin Dabilpuram 	SHA3_SHAKE256   = 14,
1156cc54096SNithin Dabilpuram 	SHA3_SHAKE512   = 15,
1166cc54096SNithin Dabilpuram 
1176cc54096SNithin Dabilpuram 	/* These are only for software use */
1186cc54096SNithin Dabilpuram 	ZUC_EIA3        = 0x90,
1196cc54096SNithin Dabilpuram 	SNOW3G_UIA2     = 0x91,
1206cc54096SNithin Dabilpuram 	KASUMI_F9_CBC   = 0x92,
1216cc54096SNithin Dabilpuram 	KASUMI_F9_ECB   = 0x93,
1226cc54096SNithin Dabilpuram } mc_hash_type_t;
1236cc54096SNithin Dabilpuram 
1246cc54096SNithin Dabilpuram typedef enum {
1256cc54096SNithin Dabilpuram 	/* To support passthrough */
1266cc54096SNithin Dabilpuram 	PASSTHROUGH  = 0x0,
1276cc54096SNithin Dabilpuram 	/*
1286cc54096SNithin Dabilpuram 	 * These are defined by MC for Flexi crypto
1296cc54096SNithin Dabilpuram 	 * for field of 4 bits
1306cc54096SNithin Dabilpuram 	 */
1316cc54096SNithin Dabilpuram 	DES3_CBC    = 0x1,
1326cc54096SNithin Dabilpuram 	DES3_ECB    = 0x2,
1336cc54096SNithin Dabilpuram 	AES_CBC     = 0x3,
1346cc54096SNithin Dabilpuram 	AES_ECB     = 0x4,
1356cc54096SNithin Dabilpuram 	AES_CFB     = 0x5,
1366cc54096SNithin Dabilpuram 	AES_CTR     = 0x6,
1376cc54096SNithin Dabilpuram 	AES_GCM     = 0x7,
1386cc54096SNithin Dabilpuram 	AES_XTS     = 0x8,
139*cb7842f2STejasree Kondoj 	CHACHA20    = 0x9,
1406cc54096SNithin Dabilpuram 
1416cc54096SNithin Dabilpuram 	/* These are only for software use */
1426cc54096SNithin Dabilpuram 	ZUC_EEA3        = 0x90,
1436cc54096SNithin Dabilpuram 	SNOW3G_UEA2     = 0x91,
1446cc54096SNithin Dabilpuram 	KASUMI_F8_CBC   = 0x92,
1456cc54096SNithin Dabilpuram 	KASUMI_F8_ECB   = 0x93,
1466cc54096SNithin Dabilpuram } mc_cipher_type_t;
1476cc54096SNithin Dabilpuram 
1486cc54096SNithin Dabilpuram typedef enum {
1496cc54096SNithin Dabilpuram 	AES_128_BIT = 0x1,
1506cc54096SNithin Dabilpuram 	AES_192_BIT = 0x2,
1516cc54096SNithin Dabilpuram 	AES_256_BIT = 0x3
1526cc54096SNithin Dabilpuram } mc_aes_type_t;
1536cc54096SNithin Dabilpuram 
1549be415daSNithin Dabilpuram typedef enum {
1559be415daSNithin Dabilpuram 	/* Microcode errors */
1569be415daSNithin Dabilpuram 	NO_ERR = 0x00,
1579be415daSNithin Dabilpuram 	ERR_OPCODE_UNSUPPORTED = 0x01,
1589be415daSNithin Dabilpuram 
1599be415daSNithin Dabilpuram 	/* SCATTER GATHER */
1609be415daSNithin Dabilpuram 	ERR_SCATTER_GATHER_WRITE_LENGTH = 0x02,
1619be415daSNithin Dabilpuram 	ERR_SCATTER_GATHER_LIST = 0x03,
1629be415daSNithin Dabilpuram 	ERR_SCATTER_GATHER_NOT_SUPPORTED = 0x04,
1639be415daSNithin Dabilpuram 
1649be415daSNithin Dabilpuram 	/* SE GC */
1659be415daSNithin Dabilpuram 	ERR_GC_LENGTH_INVALID = 0x41,
1669be415daSNithin Dabilpuram 	ERR_GC_RANDOM_LEN_INVALID = 0x42,
1679be415daSNithin Dabilpuram 	ERR_GC_DATA_LEN_INVALID = 0x43,
1689be415daSNithin Dabilpuram 	ERR_GC_DRBG_TYPE_INVALID = 0x44,
1699be415daSNithin Dabilpuram 	ERR_GC_CTX_LEN_INVALID = 0x45,
1709be415daSNithin Dabilpuram 	ERR_GC_CIPHER_UNSUPPORTED = 0x46,
1719be415daSNithin Dabilpuram 	ERR_GC_AUTH_UNSUPPORTED = 0x47,
1729be415daSNithin Dabilpuram 	ERR_GC_OFFSET_INVALID = 0x48,
1739be415daSNithin Dabilpuram 	ERR_GC_HASH_MODE_UNSUPPORTED = 0x49,
1749be415daSNithin Dabilpuram 	ERR_GC_DRBG_ENTROPY_LEN_INVALID = 0x4a,
1759be415daSNithin Dabilpuram 	ERR_GC_DRBG_ADDNL_LEN_INVALID = 0x4b,
1769be415daSNithin Dabilpuram 	ERR_GC_ICV_MISCOMPARE = 0x4c,
1779be415daSNithin Dabilpuram 	ERR_GC_DATA_UNALIGNED = 0x4d,
1789be415daSNithin Dabilpuram 
1799be415daSNithin Dabilpuram 	/* API Layer */
1809be415daSNithin Dabilpuram 	ERR_BAD_ALT_CCODE = 0xfd,
1819be415daSNithin Dabilpuram 	ERR_REQ_PENDING = 0xfe,
1829be415daSNithin Dabilpuram 	ERR_REQ_TIMEOUT = 0xff,
1839be415daSNithin Dabilpuram 
1849be415daSNithin Dabilpuram 	ERR_BAD_INPUT_LENGTH = (0x40000000 | 384),    /* 0x40000180 */
1859be415daSNithin Dabilpuram 	ERR_BAD_KEY_LENGTH,
1869be415daSNithin Dabilpuram 	ERR_BAD_KEY_HANDLE,
1879be415daSNithin Dabilpuram 	ERR_BAD_CONTEXT_HANDLE,
1889be415daSNithin Dabilpuram 	ERR_BAD_SCALAR_LENGTH,
1899be415daSNithin Dabilpuram 	ERR_BAD_DIGEST_LENGTH,
1909be415daSNithin Dabilpuram 	ERR_BAD_INPUT_ARG,
1919be415daSNithin Dabilpuram 	ERR_BAD_RECORD_PADDING,
1929be415daSNithin Dabilpuram 	ERR_NB_REQUEST_PENDING,
1939be415daSNithin Dabilpuram 	ERR_EIO,
1949be415daSNithin Dabilpuram 	ERR_ENODEV,
1959be415daSNithin Dabilpuram } mc_error_code_t;
1966cc54096SNithin Dabilpuram 
19789f1a8d6STejasree Kondoj /**
19889f1a8d6STejasree Kondoj  * Enumeration cpt_comp_e
19989f1a8d6STejasree Kondoj  *
20089f1a8d6STejasree Kondoj  * CPT Completion Enumeration
20189f1a8d6STejasree Kondoj  * Enumerates the values of CPT_RES_S[COMPCODE].
20289f1a8d6STejasree Kondoj  */
20389f1a8d6STejasree Kondoj typedef enum {
20489f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_NOTDONE    = (0x00),
20589f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_GOOD       = (0x01),
20689f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_FAULT      = (0x02),
20789f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_SWERR      = (0x03),
20889f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_HWERR      = (0x04),
20989f1a8d6STejasree Kondoj 	CPT_8X_COMP_E_LAST_ENTRY = (0xFF)
21089f1a8d6STejasree Kondoj } cpt_comp_e_t;
21189f1a8d6STejasree Kondoj 
212aa2cbd32SSunila Sahu /**
213aa2cbd32SSunila Sahu  * Enumeration cpt_ec_id
214aa2cbd32SSunila Sahu  *
215aa2cbd32SSunila Sahu  * Enumerates supported elliptic curves
216aa2cbd32SSunila Sahu  */
217aa2cbd32SSunila Sahu typedef enum {
218aa2cbd32SSunila Sahu 	CPT_EC_ID_P192 = 0,
219aa2cbd32SSunila Sahu 	CPT_EC_ID_P224 = 1,
220aa2cbd32SSunila Sahu 	CPT_EC_ID_P256 = 2,
221aa2cbd32SSunila Sahu 	CPT_EC_ID_P384 = 3,
222aa2cbd32SSunila Sahu 	CPT_EC_ID_P521 = 4,
223aa2cbd32SSunila Sahu 	CPT_EC_ID_PMAX = 5
224aa2cbd32SSunila Sahu } cpt_ec_id_t;
225aa2cbd32SSunila Sahu 
2268846a756SAnoob Joseph typedef struct sglist_comp {
2278846a756SAnoob Joseph 	union {
2288846a756SAnoob Joseph 		uint64_t len;
2298846a756SAnoob Joseph 		struct {
2308846a756SAnoob Joseph 			uint16_t len[4];
2318846a756SAnoob Joseph 		} s;
2328846a756SAnoob Joseph 	} u;
2338846a756SAnoob Joseph 	uint64_t ptr[4];
2348846a756SAnoob Joseph } sg_comp_t;
2358846a756SAnoob Joseph 
23643d01767SNithin Dabilpuram struct cpt_sess_misc {
23743d01767SNithin Dabilpuram 	/** CPT opcode */
23843d01767SNithin Dabilpuram 	uint16_t cpt_op:4;
23943d01767SNithin Dabilpuram 	/** ZUC, SNOW3G &  KASUMI flags */
24043d01767SNithin Dabilpuram 	uint16_t zsk_flag:4;
24143d01767SNithin Dabilpuram 	/** Flag for AES GCM */
24243d01767SNithin Dabilpuram 	uint16_t aes_gcm:1;
24343d01767SNithin Dabilpuram 	/** Flag for AES CTR */
24443d01767SNithin Dabilpuram 	uint16_t aes_ctr:1;
245*cb7842f2STejasree Kondoj 	/** Flag for CHACHA POLY */
246*cb7842f2STejasree Kondoj 	uint16_t chacha_poly:1;
24743d01767SNithin Dabilpuram 	/** Flag for NULL cipher/auth */
24843d01767SNithin Dabilpuram 	uint16_t is_null:1;
24943d01767SNithin Dabilpuram 	/** Flag for GMAC */
25043d01767SNithin Dabilpuram 	uint16_t is_gmac:1;
2513e725488SAnkur Dwivedi 	/** Engine group */
2523e725488SAnkur Dwivedi 	uint16_t egrp:3;
25343d01767SNithin Dabilpuram 	/** AAD length */
25443d01767SNithin Dabilpuram 	uint16_t aad_length;
25543d01767SNithin Dabilpuram 	/** MAC len in bytes */
25643d01767SNithin Dabilpuram 	uint8_t mac_len;
25743d01767SNithin Dabilpuram 	/** IV length in bytes */
25843d01767SNithin Dabilpuram 	uint8_t iv_length;
25943d01767SNithin Dabilpuram 	/** Auth IV length in bytes */
26043d01767SNithin Dabilpuram 	uint8_t auth_iv_length;
26143d01767SNithin Dabilpuram 	/** Reserved field */
26243d01767SNithin Dabilpuram 	uint8_t rsvd1;
26343d01767SNithin Dabilpuram 	/** IV offset in bytes */
26443d01767SNithin Dabilpuram 	uint16_t iv_offset;
26543d01767SNithin Dabilpuram 	/** Auth IV offset in bytes */
26643d01767SNithin Dabilpuram 	uint16_t auth_iv_offset;
26743d01767SNithin Dabilpuram 	/** Salt */
26843d01767SNithin Dabilpuram 	uint32_t salt;
26943d01767SNithin Dabilpuram 	/** Context DMA address */
27043d01767SNithin Dabilpuram 	phys_addr_t ctx_dma_addr;
27143d01767SNithin Dabilpuram };
27243d01767SNithin Dabilpuram 
27343d01767SNithin Dabilpuram typedef struct {
274c3d0bc45SAnoob Joseph 	uint64_t iv_source      : 1;
275c3d0bc45SAnoob Joseph 	uint64_t aes_key        : 2;
276c3d0bc45SAnoob Joseph 	uint64_t rsvd_60        : 1;
277c3d0bc45SAnoob Joseph 	uint64_t enc_cipher     : 4;
278c3d0bc45SAnoob Joseph 	uint64_t auth_input_type : 1;
279c3d0bc45SAnoob Joseph 	uint64_t rsvd_52_54     : 3;
280c3d0bc45SAnoob Joseph 	uint64_t hash_type      : 4;
281c3d0bc45SAnoob Joseph 	uint64_t mac_len        : 8;
282c3d0bc45SAnoob Joseph 	uint64_t rsvd_39_0      : 40;
28343d01767SNithin Dabilpuram 	uint8_t  encr_key[32];
28443d01767SNithin Dabilpuram 	uint8_t  encr_iv[16];
28543d01767SNithin Dabilpuram } mc_enc_context_t;
28643d01767SNithin Dabilpuram 
28743d01767SNithin Dabilpuram typedef struct {
28843d01767SNithin Dabilpuram 	uint8_t  ipad[64];
28943d01767SNithin Dabilpuram 	uint8_t  opad[64];
29043d01767SNithin Dabilpuram } mc_fc_hmac_context_t;
29143d01767SNithin Dabilpuram 
29243d01767SNithin Dabilpuram typedef struct {
29343d01767SNithin Dabilpuram 	mc_enc_context_t     enc;
29443d01767SNithin Dabilpuram 	mc_fc_hmac_context_t hmac;
29543d01767SNithin Dabilpuram } mc_fc_context_t;
29643d01767SNithin Dabilpuram 
29743d01767SNithin Dabilpuram typedef struct {
29843d01767SNithin Dabilpuram 	uint8_t encr_auth_iv[16];
29943d01767SNithin Dabilpuram 	uint8_t ci_key[16];
30043d01767SNithin Dabilpuram 	uint8_t zuc_const[32];
30143d01767SNithin Dabilpuram } mc_zuc_snow3g_ctx_t;
30243d01767SNithin Dabilpuram 
30343d01767SNithin Dabilpuram typedef struct {
30443d01767SNithin Dabilpuram 	uint8_t reg_A[8];
30543d01767SNithin Dabilpuram 	uint8_t ci_key[16];
30643d01767SNithin Dabilpuram } mc_kasumi_ctx_t;
30743d01767SNithin Dabilpuram 
30843d01767SNithin Dabilpuram struct cpt_ctx {
30943d01767SNithin Dabilpuram 	/* Below fields are accessed by sw */
31043d01767SNithin Dabilpuram 	uint64_t enc_cipher	:8;
31143d01767SNithin Dabilpuram 	uint64_t hash_type	:8;
31243d01767SNithin Dabilpuram 	uint64_t mac_len	:8;
31343d01767SNithin Dabilpuram 	uint64_t auth_key_len	:8;
31443d01767SNithin Dabilpuram 	uint64_t fc_type	:4;
31543d01767SNithin Dabilpuram 	uint64_t hmac		:1;
31643d01767SNithin Dabilpuram 	uint64_t zsk_flags	:3;
31743d01767SNithin Dabilpuram 	uint64_t k_ecb		:1;
318131966f8SAnkur Dwivedi 	uint64_t snow3g		:2;
319131966f8SAnkur Dwivedi 	uint64_t rsvd		:21;
32043d01767SNithin Dabilpuram 	/* Below fields are accessed by hardware */
32143d01767SNithin Dabilpuram 	union {
32243d01767SNithin Dabilpuram 		mc_fc_context_t fctx;
32343d01767SNithin Dabilpuram 		mc_zuc_snow3g_ctx_t zs_ctx;
32443d01767SNithin Dabilpuram 		mc_kasumi_ctx_t k_ctx;
32543d01767SNithin Dabilpuram 	};
3262839a8abSSucharitha Sarananaga 	uint8_t  auth_key[1024];
32743d01767SNithin Dabilpuram };
32843d01767SNithin Dabilpuram 
329aa2cbd32SSunila Sahu /* Prime and order fields of built-in elliptic curves */
330aa2cbd32SSunila Sahu struct cpt_ec_group {
331aa2cbd32SSunila Sahu 	struct {
332aa2cbd32SSunila Sahu 		/* P521 maximum length */
333aa2cbd32SSunila Sahu 		uint8_t data[66];
334aa2cbd32SSunila Sahu 		unsigned int length;
335aa2cbd32SSunila Sahu 	} prime;
336aa2cbd32SSunila Sahu 
337aa2cbd32SSunila Sahu 	struct {
338aa2cbd32SSunila Sahu 		/* P521 maximum length */
339aa2cbd32SSunila Sahu 		uint8_t data[66];
340aa2cbd32SSunila Sahu 		unsigned int length;
341aa2cbd32SSunila Sahu 	} order;
342aa2cbd32SSunila Sahu };
343aa2cbd32SSunila Sahu 
344aa2cbd32SSunila Sahu struct cpt_asym_ec_ctx {
345aa2cbd32SSunila Sahu 	/* Prime length defined by microcode for EC operations */
346aa2cbd32SSunila Sahu 	uint8_t curveid;
347aa2cbd32SSunila Sahu };
348aa2cbd32SSunila Sahu 
34933bcaae5SKanaka Durga Kotamarthy struct cpt_asym_sess_misc {
35033bcaae5SKanaka Durga Kotamarthy 	enum rte_crypto_asym_xform_type xfrm_type;
35133bcaae5SKanaka Durga Kotamarthy 	union {
35233bcaae5SKanaka Durga Kotamarthy 		struct rte_crypto_rsa_xform rsa_ctx;
35333bcaae5SKanaka Durga Kotamarthy 		struct rte_crypto_modex_xform mod_ctx;
354aa2cbd32SSunila Sahu 		struct cpt_asym_ec_ctx ec_ctx;
35533bcaae5SKanaka Durga Kotamarthy 	};
35633bcaae5SKanaka Durga Kotamarthy };
35733bcaae5SKanaka Durga Kotamarthy 
3589be415daSNithin Dabilpuram /* Buffer pointer */
3599be415daSNithin Dabilpuram typedef struct buf_ptr {
3609be415daSNithin Dabilpuram 	void *vaddr;
3619be415daSNithin Dabilpuram 	phys_addr_t dma_addr;
3629be415daSNithin Dabilpuram 	uint32_t size;
3639be415daSNithin Dabilpuram 	uint32_t resv;
3649be415daSNithin Dabilpuram } buf_ptr_t;
3659be415daSNithin Dabilpuram 
3669be415daSNithin Dabilpuram /* IOV Pointer */
3679be415daSNithin Dabilpuram typedef struct{
3689be415daSNithin Dabilpuram 	int buf_cnt;
3699be415daSNithin Dabilpuram 	buf_ptr_t bufs[0];
3709be415daSNithin Dabilpuram } iov_ptr_t;
3719be415daSNithin Dabilpuram 
3729be415daSNithin Dabilpuram typedef union opcode_info {
3739be415daSNithin Dabilpuram 	uint16_t flags;
3749be415daSNithin Dabilpuram 	struct {
3759be415daSNithin Dabilpuram 		uint8_t major;
3769be415daSNithin Dabilpuram 		uint8_t minor;
3779be415daSNithin Dabilpuram 	} s;
3789be415daSNithin Dabilpuram } opcode_info_t;
3799be415daSNithin Dabilpuram 
3809be415daSNithin Dabilpuram typedef struct fc_params {
3819be415daSNithin Dabilpuram 	/* 0th cache line */
3829be415daSNithin Dabilpuram 	union {
3839be415daSNithin Dabilpuram 		buf_ptr_t bufs[1];
3849be415daSNithin Dabilpuram 		struct {
3859be415daSNithin Dabilpuram 			iov_ptr_t *src_iov;
3869be415daSNithin Dabilpuram 			iov_ptr_t *dst_iov;
3879be415daSNithin Dabilpuram 		};
3889be415daSNithin Dabilpuram 	};
3899be415daSNithin Dabilpuram 	void *iv_buf;
3909be415daSNithin Dabilpuram 	void *auth_iv_buf;
3919be415daSNithin Dabilpuram 	buf_ptr_t meta_buf;
3929be415daSNithin Dabilpuram 	buf_ptr_t ctx_buf;
3939be415daSNithin Dabilpuram 	uint64_t rsvd2;
3949be415daSNithin Dabilpuram 
3959be415daSNithin Dabilpuram 	/* 1st cache line */
3969be415daSNithin Dabilpuram 	buf_ptr_t aad_buf;
3979be415daSNithin Dabilpuram 	buf_ptr_t mac_buf;
3989be415daSNithin Dabilpuram 
3999be415daSNithin Dabilpuram } fc_params_t;
4009be415daSNithin Dabilpuram 
401351fbee2SSrisivasubramanian S /*
402e9a356e2SSunila Sahu  * Parameters for asymmetric operations
403e9a356e2SSunila Sahu  */
404e9a356e2SSunila Sahu struct asym_op_params {
405e9a356e2SSunila Sahu 	struct cpt_request_info *req;
406e9a356e2SSunila Sahu 	phys_addr_t meta_buf;
407e9a356e2SSunila Sahu };
408e9a356e2SSunila Sahu 
409e9a356e2SSunila Sahu /*
410351fbee2SSrisivasubramanian S  * Parameters for digest
411351fbee2SSrisivasubramanian S  * generate requests
412351fbee2SSrisivasubramanian S  * Only src_iov, op, ctx_buf, mac_buf, prep_req
413351fbee2SSrisivasubramanian S  * meta_buf, auth_data_len are used for digest gen.
414351fbee2SSrisivasubramanian S  */
4156cc54096SNithin Dabilpuram typedef struct fc_params digest_params_t;
4166cc54096SNithin Dabilpuram 
4176cc54096SNithin Dabilpuram /* Cipher Algorithms */
4186cc54096SNithin Dabilpuram typedef mc_cipher_type_t cipher_type_t;
4196cc54096SNithin Dabilpuram 
4206cc54096SNithin Dabilpuram /* Auth Algorithms */
4216cc54096SNithin Dabilpuram typedef mc_hash_type_t auth_type_t;
4226cc54096SNithin Dabilpuram 
4239be415daSNithin Dabilpuram /* Helper macros */
4249be415daSNithin Dabilpuram 
4259be415daSNithin Dabilpuram #define SRC_IOV_SIZE \
4269be415daSNithin Dabilpuram 	(sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
4279be415daSNithin Dabilpuram #define DST_IOV_SIZE \
4289be415daSNithin Dabilpuram 	(sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
4299be415daSNithin Dabilpuram 
4306cc54096SNithin Dabilpuram #define SESS_PRIV(__sess) \
4316cc54096SNithin Dabilpuram 	(void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
4326cc54096SNithin Dabilpuram 
433f194f198SAnoob Joseph /*
434f194f198SAnoob Joseph  * Get the session size
435f194f198SAnoob Joseph  *
436f194f198SAnoob Joseph  * @return
437f194f198SAnoob Joseph  *   - session size
438f194f198SAnoob Joseph  */
439f194f198SAnoob Joseph static __rte_always_inline unsigned int
440f194f198SAnoob Joseph cpt_get_session_size(void)
441f194f198SAnoob Joseph {
442f194f198SAnoob Joseph 	unsigned int ctx_len = sizeof(struct cpt_ctx);
443f194f198SAnoob Joseph 	return (sizeof(struct cpt_sess_misc) + RTE_ALIGN_CEIL(ctx_len, 8));
444f194f198SAnoob Joseph }
4458846a756SAnoob Joseph #endif /* _CPT_MCODE_DEFINES_H_ */
446