xref: /dpdk/drivers/common/cpt/cpt_mcode_defines.h (revision badc0c6f6d6aa0d160c40e9d7d8f212411f5033e)
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
23de5eb0a6STejasree Kondoj #define CPT_HMAC_FIRST_BIT_POS	0x4
24de5eb0a6STejasree Kondoj #define CPT_FC_MINOR_OP_ENCRYPT	0x0
25de5eb0a6STejasree Kondoj #define CPT_FC_MINOR_OP_DECRYPT	0x1
268846a756SAnoob Joseph 
27e9a356e2SSunila Sahu /* AE opcodes */
28e9a356e2SSunila Sahu #define CPT_MAJOR_OP_MODEX	0x03
29aa2cbd32SSunila Sahu #define CPT_MAJOR_OP_ECDSA	0x04
3099faef83SSunila Sahu #define CPT_MAJOR_OP_ECC	0x05
31e9a356e2SSunila Sahu #define CPT_MINOR_OP_MODEX	0x01
32e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_ENC	0x02
33e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_ENC_CRT	0x03
34e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_DEC	0x04
35e9a356e2SSunila Sahu #define CPT_MINOR_OP_PKCS_DEC_CRT	0x05
36e9a356e2SSunila Sahu #define CPT_MINOR_OP_MODEX_CRT	0x06
37aa2cbd32SSunila Sahu #define CPT_MINOR_OP_ECDSA_SIGN	0x01
38aa2cbd32SSunila Sahu #define CPT_MINOR_OP_ECDSA_VERIFY	0x02
3999faef83SSunila Sahu #define CPT_MINOR_OP_ECC_UMP	0x03
40e9a356e2SSunila Sahu 
41e9a356e2SSunila Sahu #define CPT_BLOCK_TYPE1 0
42e9a356e2SSunila Sahu #define CPT_BLOCK_TYPE2 1
43e9a356e2SSunila Sahu 
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,
109cb7842f2STejasree 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,
139cb7842f2STejasree 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,
2238cd5064cSKiran Kumar K 	CPT_EC_ID_P160 = 5,
2248cd5064cSKiran Kumar K 	CPT_EC_ID_P320 = 6,
2258cd5064cSKiran Kumar K 	CPT_EC_ID_P512 = 7,
2268cd5064cSKiran Kumar K 	CPT_EC_ID_PMAX = 8
227aa2cbd32SSunila Sahu } cpt_ec_id_t;
228aa2cbd32SSunila Sahu 
2298846a756SAnoob Joseph typedef struct sglist_comp {
2308846a756SAnoob Joseph 	union {
2318846a756SAnoob Joseph 		uint64_t len;
2328846a756SAnoob Joseph 		struct {
2338846a756SAnoob Joseph 			uint16_t len[4];
2348846a756SAnoob Joseph 		} s;
2358846a756SAnoob Joseph 	} u;
2368846a756SAnoob Joseph 	uint64_t ptr[4];
2378846a756SAnoob Joseph } sg_comp_t;
2388846a756SAnoob Joseph 
23943d01767SNithin Dabilpuram struct cpt_sess_misc {
24043d01767SNithin Dabilpuram 	/** CPT opcode */
24143d01767SNithin Dabilpuram 	uint16_t cpt_op:4;
24243d01767SNithin Dabilpuram 	/** ZUC, SNOW3G &  KASUMI flags */
24343d01767SNithin Dabilpuram 	uint16_t zsk_flag:4;
24443d01767SNithin Dabilpuram 	/** Flag for AES GCM */
24543d01767SNithin Dabilpuram 	uint16_t aes_gcm:1;
24643d01767SNithin Dabilpuram 	/** Flag for AES CTR */
24743d01767SNithin Dabilpuram 	uint16_t aes_ctr:1;
248cb7842f2STejasree Kondoj 	/** Flag for CHACHA POLY */
249cb7842f2STejasree Kondoj 	uint16_t chacha_poly:1;
25043d01767SNithin Dabilpuram 	/** Flag for NULL cipher/auth */
25143d01767SNithin Dabilpuram 	uint16_t is_null:1;
25243d01767SNithin Dabilpuram 	/** Flag for GMAC */
25343d01767SNithin Dabilpuram 	uint16_t is_gmac:1;
2546045c06aSArchana Muniganti 	/** Unused field */
2556045c06aSArchana Muniganti 	uint16_t rsvd1:3;
25643d01767SNithin Dabilpuram 	/** AAD length */
25743d01767SNithin Dabilpuram 	uint16_t aad_length;
25843d01767SNithin Dabilpuram 	/** MAC len in bytes */
25943d01767SNithin Dabilpuram 	uint8_t mac_len;
26043d01767SNithin Dabilpuram 	/** IV length in bytes */
26143d01767SNithin Dabilpuram 	uint8_t iv_length;
26243d01767SNithin Dabilpuram 	/** Auth IV length in bytes */
26343d01767SNithin Dabilpuram 	uint8_t auth_iv_length;
2646045c06aSArchana Muniganti 	/** Unused field */
2656045c06aSArchana Muniganti 	uint8_t rsvd2;
26643d01767SNithin Dabilpuram 	/** IV offset in bytes */
26743d01767SNithin Dabilpuram 	uint16_t iv_offset;
26843d01767SNithin Dabilpuram 	/** Auth IV offset in bytes */
26943d01767SNithin Dabilpuram 	uint16_t auth_iv_offset;
27043d01767SNithin Dabilpuram 	/** Salt */
27143d01767SNithin Dabilpuram 	uint32_t salt;
2726045c06aSArchana Muniganti 	/** CPT inst word 7 */
2736045c06aSArchana Muniganti 	uint64_t cpt_inst_w7;
27443d01767SNithin Dabilpuram 	/** Context DMA address */
27543d01767SNithin Dabilpuram 	phys_addr_t ctx_dma_addr;
27643d01767SNithin Dabilpuram };
27743d01767SNithin Dabilpuram 
27843d01767SNithin Dabilpuram typedef struct {
279c3d0bc45SAnoob Joseph 	uint64_t iv_source      : 1;
280c3d0bc45SAnoob Joseph 	uint64_t aes_key        : 2;
281c3d0bc45SAnoob Joseph 	uint64_t rsvd_60        : 1;
282c3d0bc45SAnoob Joseph 	uint64_t enc_cipher     : 4;
283c3d0bc45SAnoob Joseph 	uint64_t auth_input_type : 1;
284c3d0bc45SAnoob Joseph 	uint64_t rsvd_52_54     : 3;
285c3d0bc45SAnoob Joseph 	uint64_t hash_type      : 4;
286c3d0bc45SAnoob Joseph 	uint64_t mac_len        : 8;
287c3d0bc45SAnoob Joseph 	uint64_t rsvd_39_0      : 40;
28843d01767SNithin Dabilpuram 	uint8_t  encr_key[32];
28943d01767SNithin Dabilpuram 	uint8_t  encr_iv[16];
29043d01767SNithin Dabilpuram } mc_enc_context_t;
29143d01767SNithin Dabilpuram 
29243d01767SNithin Dabilpuram typedef struct {
29343d01767SNithin Dabilpuram 	uint8_t  ipad[64];
29443d01767SNithin Dabilpuram 	uint8_t  opad[64];
29543d01767SNithin Dabilpuram } mc_fc_hmac_context_t;
29643d01767SNithin Dabilpuram 
29743d01767SNithin Dabilpuram typedef struct {
29843d01767SNithin Dabilpuram 	mc_enc_context_t     enc;
29943d01767SNithin Dabilpuram 	mc_fc_hmac_context_t hmac;
30043d01767SNithin Dabilpuram } mc_fc_context_t;
30143d01767SNithin Dabilpuram 
30243d01767SNithin Dabilpuram typedef struct {
30343d01767SNithin Dabilpuram 	uint8_t encr_auth_iv[16];
30443d01767SNithin Dabilpuram 	uint8_t ci_key[16];
30543d01767SNithin Dabilpuram 	uint8_t zuc_const[32];
30643d01767SNithin Dabilpuram } mc_zuc_snow3g_ctx_t;
30743d01767SNithin Dabilpuram 
30843d01767SNithin Dabilpuram typedef struct {
30943d01767SNithin Dabilpuram 	uint8_t reg_A[8];
31043d01767SNithin Dabilpuram 	uint8_t ci_key[16];
31143d01767SNithin Dabilpuram } mc_kasumi_ctx_t;
31243d01767SNithin Dabilpuram 
31343d01767SNithin Dabilpuram struct cpt_ctx {
31443d01767SNithin Dabilpuram 	/* Below fields are accessed by sw */
31543d01767SNithin Dabilpuram 	uint64_t enc_cipher	:8;
31643d01767SNithin Dabilpuram 	uint64_t hash_type	:8;
31743d01767SNithin Dabilpuram 	uint64_t mac_len	:8;
31843d01767SNithin Dabilpuram 	uint64_t auth_key_len	:8;
31943d01767SNithin Dabilpuram 	uint64_t fc_type	:4;
32043d01767SNithin Dabilpuram 	uint64_t hmac		:1;
32143d01767SNithin Dabilpuram 	uint64_t zsk_flags	:3;
32243d01767SNithin Dabilpuram 	uint64_t k_ecb		:1;
323de5eb0a6STejasree Kondoj 	uint64_t auth_enc	:1;
324de5eb0a6STejasree Kondoj 	uint64_t dec_auth	:1;
325131966f8SAnkur Dwivedi 	uint64_t snow3g		:2;
326de5eb0a6STejasree Kondoj 	uint64_t rsvd		:19;
32743d01767SNithin Dabilpuram 	/* Below fields are accessed by hardware */
32843d01767SNithin Dabilpuram 	union {
32943d01767SNithin Dabilpuram 		mc_fc_context_t fctx;
33043d01767SNithin Dabilpuram 		mc_zuc_snow3g_ctx_t zs_ctx;
33143d01767SNithin Dabilpuram 		mc_kasumi_ctx_t k_ctx;
3326045c06aSArchana Muniganti 	} mc_ctx;
333db06451bSAnoob Joseph 	uint8_t *auth_key;
334db06451bSAnoob Joseph 	uint64_t auth_key_iova;
33543d01767SNithin Dabilpuram };
33643d01767SNithin Dabilpuram 
337aa2cbd32SSunila Sahu /* Prime and order fields of built-in elliptic curves */
338aa2cbd32SSunila Sahu struct cpt_ec_group {
339aa2cbd32SSunila Sahu 	struct {
340aa2cbd32SSunila Sahu 		/* P521 maximum length */
341aa2cbd32SSunila Sahu 		uint8_t data[66];
342aa2cbd32SSunila Sahu 		unsigned int length;
343aa2cbd32SSunila Sahu 	} prime;
344aa2cbd32SSunila Sahu 
345aa2cbd32SSunila Sahu 	struct {
346aa2cbd32SSunila Sahu 		/* P521 maximum length */
347aa2cbd32SSunila Sahu 		uint8_t data[66];
348aa2cbd32SSunila Sahu 		unsigned int length;
349aa2cbd32SSunila Sahu 	} order;
3508cd5064cSKiran Kumar K 
3518cd5064cSKiran Kumar K 	struct {
3528cd5064cSKiran Kumar K 		/* P521 maximum length */
3538cd5064cSKiran Kumar K 		uint8_t data[66];
3548cd5064cSKiran Kumar K 		unsigned int length;
3558cd5064cSKiran Kumar K 	} consta;
3568cd5064cSKiran Kumar K 
3578cd5064cSKiran Kumar K 	struct {
3588cd5064cSKiran Kumar K 		/* P521 maximum length */
3598cd5064cSKiran Kumar K 		uint8_t data[66];
3608cd5064cSKiran Kumar K 		unsigned int length;
3618cd5064cSKiran Kumar K 	} constb;
362aa2cbd32SSunila Sahu };
363aa2cbd32SSunila Sahu 
364aa2cbd32SSunila Sahu struct cpt_asym_ec_ctx {
365aa2cbd32SSunila Sahu 	/* Prime length defined by microcode for EC operations */
366aa2cbd32SSunila Sahu 	uint8_t curveid;
367*badc0c6fSGowrishankar Muthukrishnan 
368*badc0c6fSGowrishankar Muthukrishnan 	/* Private key */
369*badc0c6fSGowrishankar Muthukrishnan 	struct {
370*badc0c6fSGowrishankar Muthukrishnan 		uint8_t data[66];
371*badc0c6fSGowrishankar Muthukrishnan 		unsigned int length;
372*badc0c6fSGowrishankar Muthukrishnan 	} pkey;
373*badc0c6fSGowrishankar Muthukrishnan 
374*badc0c6fSGowrishankar Muthukrishnan 	/* Public key */
375*badc0c6fSGowrishankar Muthukrishnan 	struct {
376*badc0c6fSGowrishankar Muthukrishnan 		struct {
377*badc0c6fSGowrishankar Muthukrishnan 			uint8_t data[66];
378*badc0c6fSGowrishankar Muthukrishnan 			unsigned int length;
379*badc0c6fSGowrishankar Muthukrishnan 		} x;
380*badc0c6fSGowrishankar Muthukrishnan 		struct {
381*badc0c6fSGowrishankar Muthukrishnan 			uint8_t data[66];
382*badc0c6fSGowrishankar Muthukrishnan 			unsigned int length;
383*badc0c6fSGowrishankar Muthukrishnan 		} y;
384*badc0c6fSGowrishankar Muthukrishnan 	} q;
385aa2cbd32SSunila Sahu };
386aa2cbd32SSunila Sahu 
38733bcaae5SKanaka Durga Kotamarthy struct cpt_asym_sess_misc {
38833bcaae5SKanaka Durga Kotamarthy 	enum rte_crypto_asym_xform_type xfrm_type;
38933bcaae5SKanaka Durga Kotamarthy 	union {
39033bcaae5SKanaka Durga Kotamarthy 		struct rte_crypto_rsa_xform rsa_ctx;
39133bcaae5SKanaka Durga Kotamarthy 		struct rte_crypto_modex_xform mod_ctx;
392aa2cbd32SSunila Sahu 		struct cpt_asym_ec_ctx ec_ctx;
39333bcaae5SKanaka Durga Kotamarthy 	};
3946045c06aSArchana Muniganti 	uint64_t cpt_inst_w7;
39533bcaae5SKanaka Durga Kotamarthy };
39633bcaae5SKanaka Durga Kotamarthy 
3979be415daSNithin Dabilpuram /* Buffer pointer */
3989be415daSNithin Dabilpuram typedef struct buf_ptr {
3999be415daSNithin Dabilpuram 	void *vaddr;
4009be415daSNithin Dabilpuram 	phys_addr_t dma_addr;
4019be415daSNithin Dabilpuram 	uint32_t size;
4029be415daSNithin Dabilpuram 	uint32_t resv;
4039be415daSNithin Dabilpuram } buf_ptr_t;
4049be415daSNithin Dabilpuram 
4059be415daSNithin Dabilpuram /* IOV Pointer */
4069be415daSNithin Dabilpuram typedef struct{
4079be415daSNithin Dabilpuram 	int buf_cnt;
4083aa16821SAnkur Dwivedi 	buf_ptr_t bufs[];
4099be415daSNithin Dabilpuram } iov_ptr_t;
4109be415daSNithin Dabilpuram 
4119be415daSNithin Dabilpuram typedef struct fc_params {
4129be415daSNithin Dabilpuram 	/* 0th cache line */
4139be415daSNithin Dabilpuram 	union {
4149be415daSNithin Dabilpuram 		buf_ptr_t bufs[1];
4159be415daSNithin Dabilpuram 		struct {
4169be415daSNithin Dabilpuram 			iov_ptr_t *src_iov;
4179be415daSNithin Dabilpuram 			iov_ptr_t *dst_iov;
4189be415daSNithin Dabilpuram 		};
4199be415daSNithin Dabilpuram 	};
4209be415daSNithin Dabilpuram 	void *iv_buf;
4219be415daSNithin Dabilpuram 	void *auth_iv_buf;
4229be415daSNithin Dabilpuram 	buf_ptr_t meta_buf;
4239be415daSNithin Dabilpuram 	buf_ptr_t ctx_buf;
4249be415daSNithin Dabilpuram 	uint64_t rsvd2;
4259be415daSNithin Dabilpuram 
4269be415daSNithin Dabilpuram 	/* 1st cache line */
4279be415daSNithin Dabilpuram 	buf_ptr_t aad_buf;
4289be415daSNithin Dabilpuram 	buf_ptr_t mac_buf;
4299be415daSNithin Dabilpuram 
4309be415daSNithin Dabilpuram } fc_params_t;
4319be415daSNithin Dabilpuram 
432351fbee2SSrisivasubramanian S /*
433e9a356e2SSunila Sahu  * Parameters for asymmetric operations
434e9a356e2SSunila Sahu  */
435e9a356e2SSunila Sahu struct asym_op_params {
436e9a356e2SSunila Sahu 	struct cpt_request_info *req;
437e9a356e2SSunila Sahu 	phys_addr_t meta_buf;
438e9a356e2SSunila Sahu };
439e9a356e2SSunila Sahu 
440e9a356e2SSunila Sahu /*
441351fbee2SSrisivasubramanian S  * Parameters for digest
442351fbee2SSrisivasubramanian S  * generate requests
443351fbee2SSrisivasubramanian S  * Only src_iov, op, ctx_buf, mac_buf, prep_req
444351fbee2SSrisivasubramanian S  * meta_buf, auth_data_len are used for digest gen.
445351fbee2SSrisivasubramanian S  */
4466cc54096SNithin Dabilpuram typedef struct fc_params digest_params_t;
4476cc54096SNithin Dabilpuram 
4486cc54096SNithin Dabilpuram /* Cipher Algorithms */
4496cc54096SNithin Dabilpuram typedef mc_cipher_type_t cipher_type_t;
4506cc54096SNithin Dabilpuram 
4516cc54096SNithin Dabilpuram /* Auth Algorithms */
4526cc54096SNithin Dabilpuram typedef mc_hash_type_t auth_type_t;
4536cc54096SNithin Dabilpuram 
4549be415daSNithin Dabilpuram /* Helper macros */
4559be415daSNithin Dabilpuram 
4569be415daSNithin Dabilpuram #define SRC_IOV_SIZE \
4579be415daSNithin Dabilpuram 	(sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
4589be415daSNithin Dabilpuram #define DST_IOV_SIZE \
4599be415daSNithin Dabilpuram 	(sizeof(iov_ptr_t) + (sizeof(buf_ptr_t) * CPT_MAX_SG_CNT))
4609be415daSNithin Dabilpuram 
4616cc54096SNithin Dabilpuram #define SESS_PRIV(__sess) \
4626cc54096SNithin Dabilpuram 	(void *)((uint8_t *)__sess + sizeof(struct cpt_sess_misc))
4636cc54096SNithin Dabilpuram 
4647293bae1SArchana Muniganti #define GET_SESS_FC_TYPE(__sess) \
4657293bae1SArchana Muniganti 	(((struct cpt_ctx *)(SESS_PRIV(__sess)))->fc_type)
4667293bae1SArchana Muniganti 
467f194f198SAnoob Joseph /*
468f194f198SAnoob Joseph  * Get the session size
469f194f198SAnoob Joseph  *
470f194f198SAnoob Joseph  * @return
471f194f198SAnoob Joseph  *   - session size
472f194f198SAnoob Joseph  */
473f194f198SAnoob Joseph static __rte_always_inline unsigned int
cpt_get_session_size(void)474f194f198SAnoob Joseph cpt_get_session_size(void)
475f194f198SAnoob Joseph {
476f194f198SAnoob Joseph 	unsigned int ctx_len = sizeof(struct cpt_ctx);
477f194f198SAnoob Joseph 	return (sizeof(struct cpt_sess_misc) + RTE_ALIGN_CEIL(ctx_len, 8));
478f194f198SAnoob Joseph }
4798846a756SAnoob Joseph #endif /* _CPT_MCODE_DEFINES_H_ */
480