18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci#ifndef __NX_CSBCPB_H__
48c2ecf20Sopenharmony_ci#define __NX_CSBCPB_H__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_cistruct cop_symcpb_aes_ecb {
78c2ecf20Sopenharmony_ci	u8 key[32];
88c2ecf20Sopenharmony_ci	u8 __rsvd[80];
98c2ecf20Sopenharmony_ci} __packed;
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct cop_symcpb_aes_cbc {
128c2ecf20Sopenharmony_ci	u8 iv[16];
138c2ecf20Sopenharmony_ci	u8 key[32];
148c2ecf20Sopenharmony_ci	u8 cv[16];
158c2ecf20Sopenharmony_ci	u32 spbc;
168c2ecf20Sopenharmony_ci	u8 __rsvd[44];
178c2ecf20Sopenharmony_ci} __packed;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct cop_symcpb_aes_gca {
208c2ecf20Sopenharmony_ci	u8 in_pat[16];
218c2ecf20Sopenharmony_ci	u8 key[32];
228c2ecf20Sopenharmony_ci	u8 out_pat[16];
238c2ecf20Sopenharmony_ci	u32 spbc;
248c2ecf20Sopenharmony_ci	u8 __rsvd[44];
258c2ecf20Sopenharmony_ci} __packed;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct cop_symcpb_aes_gcm {
288c2ecf20Sopenharmony_ci	u8 in_pat_or_aad[16];
298c2ecf20Sopenharmony_ci	u8 iv_or_cnt[16];
308c2ecf20Sopenharmony_ci	u64 bit_length_aad;
318c2ecf20Sopenharmony_ci	u64 bit_length_data;
328c2ecf20Sopenharmony_ci	u8 in_s0[16];
338c2ecf20Sopenharmony_ci	u8 key[32];
348c2ecf20Sopenharmony_ci	u8 __rsvd1[16];
358c2ecf20Sopenharmony_ci	u8 out_pat_or_mac[16];
368c2ecf20Sopenharmony_ci	u8 out_s0[16];
378c2ecf20Sopenharmony_ci	u8 out_cnt[16];
388c2ecf20Sopenharmony_ci	u32 spbc;
398c2ecf20Sopenharmony_ci	u8 __rsvd2[12];
408c2ecf20Sopenharmony_ci} __packed;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct cop_symcpb_aes_ctr {
438c2ecf20Sopenharmony_ci	u8 iv[16];
448c2ecf20Sopenharmony_ci	u8 key[32];
458c2ecf20Sopenharmony_ci	u8 cv[16];
468c2ecf20Sopenharmony_ci	u32 spbc;
478c2ecf20Sopenharmony_ci	u8 __rsvd2[44];
488c2ecf20Sopenharmony_ci} __packed;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct cop_symcpb_aes_cca {
518c2ecf20Sopenharmony_ci	u8 b0[16];
528c2ecf20Sopenharmony_ci	u8 b1[16];
538c2ecf20Sopenharmony_ci	u8 key[16];
548c2ecf20Sopenharmony_ci	u8 out_pat_or_b0[16];
558c2ecf20Sopenharmony_ci	u32 spbc;
568c2ecf20Sopenharmony_ci	u8 __rsvd[44];
578c2ecf20Sopenharmony_ci} __packed;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistruct cop_symcpb_aes_ccm {
608c2ecf20Sopenharmony_ci	u8 in_pat_or_b0[16];
618c2ecf20Sopenharmony_ci	u8 iv_or_ctr[16];
628c2ecf20Sopenharmony_ci	u8 in_s0[16];
638c2ecf20Sopenharmony_ci	u8 key[16];
648c2ecf20Sopenharmony_ci	u8 __rsvd1[48];
658c2ecf20Sopenharmony_ci	u8 out_pat_or_mac[16];
668c2ecf20Sopenharmony_ci	u8 out_s0[16];
678c2ecf20Sopenharmony_ci	u8 out_ctr[16];
688c2ecf20Sopenharmony_ci	u32 spbc;
698c2ecf20Sopenharmony_ci	u8 __rsvd2[12];
708c2ecf20Sopenharmony_ci} __packed;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct cop_symcpb_aes_xcbc {
738c2ecf20Sopenharmony_ci	u8 cv[16];
748c2ecf20Sopenharmony_ci	u8 key[16];
758c2ecf20Sopenharmony_ci	u8 __rsvd1[16];
768c2ecf20Sopenharmony_ci	u8 out_cv_mac[16];
778c2ecf20Sopenharmony_ci	u32 spbc;
788c2ecf20Sopenharmony_ci	u8 __rsvd2[44];
798c2ecf20Sopenharmony_ci} __packed;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct cop_symcpb_sha256 {
828c2ecf20Sopenharmony_ci	u64 message_bit_length;
838c2ecf20Sopenharmony_ci	u64 __rsvd1;
848c2ecf20Sopenharmony_ci	u8 input_partial_digest[32];
858c2ecf20Sopenharmony_ci	u8 message_digest[32];
868c2ecf20Sopenharmony_ci	u32 spbc;
878c2ecf20Sopenharmony_ci	u8 __rsvd2[44];
888c2ecf20Sopenharmony_ci} __packed;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistruct cop_symcpb_sha512 {
918c2ecf20Sopenharmony_ci	u64 message_bit_length_hi;
928c2ecf20Sopenharmony_ci	u64 message_bit_length_lo;
938c2ecf20Sopenharmony_ci	u8 input_partial_digest[64];
948c2ecf20Sopenharmony_ci	u8 __rsvd1[32];
958c2ecf20Sopenharmony_ci	u8 message_digest[64];
968c2ecf20Sopenharmony_ci	u32 spbc;
978c2ecf20Sopenharmony_ci	u8 __rsvd2[76];
988c2ecf20Sopenharmony_ci} __packed;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define NX_FDM_INTERMEDIATE		0x01
1018c2ecf20Sopenharmony_ci#define NX_FDM_CONTINUATION		0x02
1028c2ecf20Sopenharmony_ci#define NX_FDM_ENDE_ENCRYPT		0x80
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define NX_CPB_FDM(c)			((c)->cpb.hdr.fdm)
1058c2ecf20Sopenharmony_ci#define NX_CPB_KS_DS(c)			((c)->cpb.hdr.ks_ds)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define NX_CPB_KEY_SIZE(c)		(NX_CPB_KS_DS(c) >> 4)
1088c2ecf20Sopenharmony_ci#define NX_CPB_SET_KEY_SIZE(c, x)	NX_CPB_KS_DS(c) |= ((x) << 4)
1098c2ecf20Sopenharmony_ci#define NX_CPB_SET_DIGEST_SIZE(c, x)	NX_CPB_KS_DS(c) |= (x)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct cop_symcpb_header {
1128c2ecf20Sopenharmony_ci	u8 mode;
1138c2ecf20Sopenharmony_ci	u8 fdm;
1148c2ecf20Sopenharmony_ci	u8 ks_ds;
1158c2ecf20Sopenharmony_ci	u8 pad_byte;
1168c2ecf20Sopenharmony_ci	u8 __rsvd[12];
1178c2ecf20Sopenharmony_ci} __packed;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_cistruct cop_parameter_block {
1208c2ecf20Sopenharmony_ci	struct cop_symcpb_header hdr;
1218c2ecf20Sopenharmony_ci	union {
1228c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_ecb  aes_ecb;
1238c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_cbc  aes_cbc;
1248c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_gca  aes_gca;
1258c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_gcm  aes_gcm;
1268c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_cca  aes_cca;
1278c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_ccm  aes_ccm;
1288c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_ctr  aes_ctr;
1298c2ecf20Sopenharmony_ci		struct cop_symcpb_aes_xcbc aes_xcbc;
1308c2ecf20Sopenharmony_ci		struct cop_symcpb_sha256   sha256;
1318c2ecf20Sopenharmony_ci		struct cop_symcpb_sha512   sha512;
1328c2ecf20Sopenharmony_ci	};
1338c2ecf20Sopenharmony_ci} __packed;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define NX_CSB_VALID_BIT	0x80
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/* co-processor status block */
1388c2ecf20Sopenharmony_cistruct cop_status_block {
1398c2ecf20Sopenharmony_ci	u8 valid;
1408c2ecf20Sopenharmony_ci	u8 crb_seq_number;
1418c2ecf20Sopenharmony_ci	u8 completion_code;
1428c2ecf20Sopenharmony_ci	u8 completion_extension;
1438c2ecf20Sopenharmony_ci	u32 processed_byte_count;
1448c2ecf20Sopenharmony_ci	u64 address;
1458c2ecf20Sopenharmony_ci} __packed;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci/* Nest accelerator workbook section 4.4 */
1488c2ecf20Sopenharmony_cistruct nx_csbcpb {
1498c2ecf20Sopenharmony_ci	unsigned char __rsvd[112];
1508c2ecf20Sopenharmony_ci	struct cop_status_block csb;
1518c2ecf20Sopenharmony_ci	struct cop_parameter_block cpb;
1528c2ecf20Sopenharmony_ci} __packed;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* nx_csbcpb related definitions */
1558c2ecf20Sopenharmony_ci#define NX_MODE_AES_ECB			0
1568c2ecf20Sopenharmony_ci#define NX_MODE_AES_CBC			1
1578c2ecf20Sopenharmony_ci#define NX_MODE_AES_GMAC		2
1588c2ecf20Sopenharmony_ci#define NX_MODE_AES_GCA			3
1598c2ecf20Sopenharmony_ci#define NX_MODE_AES_GCM			4
1608c2ecf20Sopenharmony_ci#define NX_MODE_AES_CCA			5
1618c2ecf20Sopenharmony_ci#define NX_MODE_AES_CCM			6
1628c2ecf20Sopenharmony_ci#define NX_MODE_AES_CTR			7
1638c2ecf20Sopenharmony_ci#define NX_MODE_AES_XCBC_MAC		20
1648c2ecf20Sopenharmony_ci#define NX_MODE_SHA			0
1658c2ecf20Sopenharmony_ci#define NX_MODE_SHA_HMAC		1
1668c2ecf20Sopenharmony_ci#define NX_MODE_AES_CBC_HMAC_ETA	8
1678c2ecf20Sopenharmony_ci#define NX_MODE_AES_CBC_HMAC_ATE	9
1688c2ecf20Sopenharmony_ci#define NX_MODE_AES_CBC_HMAC_EAA	10
1698c2ecf20Sopenharmony_ci#define NX_MODE_AES_CTR_HMAC_ETA	12
1708c2ecf20Sopenharmony_ci#define NX_MODE_AES_CTR_HMAC_ATE	13
1718c2ecf20Sopenharmony_ci#define NX_MODE_AES_CTR_HMAC_EAA	14
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define NX_FDM_CI_FULL		0
1748c2ecf20Sopenharmony_ci#define NX_FDM_CI_FIRST		1
1758c2ecf20Sopenharmony_ci#define NX_FDM_CI_LAST		2
1768c2ecf20Sopenharmony_ci#define NX_FDM_CI_MIDDLE	3
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define NX_FDM_PR_NONE		0
1798c2ecf20Sopenharmony_ci#define NX_FDM_PR_PAD		1
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define NX_KS_AES_128		1
1828c2ecf20Sopenharmony_ci#define NX_KS_AES_192		2
1838c2ecf20Sopenharmony_ci#define NX_KS_AES_256		3
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#define NX_DS_SHA256		2
1868c2ecf20Sopenharmony_ci#define NX_DS_SHA512		3
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define NX_FC_AES		0
1898c2ecf20Sopenharmony_ci#define NX_FC_SHA		2
1908c2ecf20Sopenharmony_ci#define NX_FC_AES_HMAC		6
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#define NX_MAX_FC		(NX_FC_AES_HMAC + 1)
1938c2ecf20Sopenharmony_ci#define NX_MAX_MODE		(NX_MODE_AES_XCBC_MAC + 1)
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define HCOP_FC_AES          NX_FC_AES
1968c2ecf20Sopenharmony_ci#define HCOP_FC_SHA          NX_FC_SHA
1978c2ecf20Sopenharmony_ci#define HCOP_FC_AES_HMAC     NX_FC_AES_HMAC
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci/* indices into the array of algorithm properties */
2008c2ecf20Sopenharmony_ci#define NX_PROPS_AES_128		0
2018c2ecf20Sopenharmony_ci#define NX_PROPS_AES_192		1
2028c2ecf20Sopenharmony_ci#define NX_PROPS_AES_256		2
2038c2ecf20Sopenharmony_ci#define NX_PROPS_SHA256			1
2048c2ecf20Sopenharmony_ci#define NX_PROPS_SHA512			2
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci#endif
207