18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci * Marvell OcteonTX CPT driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2019 Marvell International Ltd. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as 88c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef __OTX_CPT_ALGS_H 128c2ecf20Sopenharmony_ci#define __OTX_CPT_ALGS_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <crypto/hash.h> 158c2ecf20Sopenharmony_ci#include "otx_cpt_common.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define OTX_CPT_MAX_ENC_KEY_SIZE 32 188c2ecf20Sopenharmony_ci#define OTX_CPT_MAX_HASH_KEY_SIZE 64 198c2ecf20Sopenharmony_ci#define OTX_CPT_MAX_KEY_SIZE (OTX_CPT_MAX_ENC_KEY_SIZE + \ 208c2ecf20Sopenharmony_ci OTX_CPT_MAX_HASH_KEY_SIZE) 218c2ecf20Sopenharmony_cienum otx_cpt_request_type { 228c2ecf20Sopenharmony_ci OTX_CPT_ENC_DEC_REQ = 0x1, 238c2ecf20Sopenharmony_ci OTX_CPT_AEAD_ENC_DEC_REQ = 0x2, 248c2ecf20Sopenharmony_ci OTX_CPT_AEAD_ENC_DEC_NULL_REQ = 0x3, 258c2ecf20Sopenharmony_ci OTX_CPT_PASSTHROUGH_REQ = 0x4 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cienum otx_cpt_major_opcodes { 298c2ecf20Sopenharmony_ci OTX_CPT_MAJOR_OP_MISC = 0x01, 308c2ecf20Sopenharmony_ci OTX_CPT_MAJOR_OP_FC = 0x33, 318c2ecf20Sopenharmony_ci OTX_CPT_MAJOR_OP_HMAC = 0x35, 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cienum otx_cpt_req_type { 358c2ecf20Sopenharmony_ci OTX_CPT_AE_CORE_REQ, 368c2ecf20Sopenharmony_ci OTX_CPT_SE_CORE_REQ 378c2ecf20Sopenharmony_ci}; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cienum otx_cpt_cipher_type { 408c2ecf20Sopenharmony_ci OTX_CPT_CIPHER_NULL = 0x0, 418c2ecf20Sopenharmony_ci OTX_CPT_DES3_CBC = 0x1, 428c2ecf20Sopenharmony_ci OTX_CPT_DES3_ECB = 0x2, 438c2ecf20Sopenharmony_ci OTX_CPT_AES_CBC = 0x3, 448c2ecf20Sopenharmony_ci OTX_CPT_AES_ECB = 0x4, 458c2ecf20Sopenharmony_ci OTX_CPT_AES_CFB = 0x5, 468c2ecf20Sopenharmony_ci OTX_CPT_AES_CTR = 0x6, 478c2ecf20Sopenharmony_ci OTX_CPT_AES_GCM = 0x7, 488c2ecf20Sopenharmony_ci OTX_CPT_AES_XTS = 0x8 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cienum otx_cpt_mac_type { 528c2ecf20Sopenharmony_ci OTX_CPT_MAC_NULL = 0x0, 538c2ecf20Sopenharmony_ci OTX_CPT_MD5 = 0x1, 548c2ecf20Sopenharmony_ci OTX_CPT_SHA1 = 0x2, 558c2ecf20Sopenharmony_ci OTX_CPT_SHA224 = 0x3, 568c2ecf20Sopenharmony_ci OTX_CPT_SHA256 = 0x4, 578c2ecf20Sopenharmony_ci OTX_CPT_SHA384 = 0x5, 588c2ecf20Sopenharmony_ci OTX_CPT_SHA512 = 0x6, 598c2ecf20Sopenharmony_ci OTX_CPT_GMAC = 0x7 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cienum otx_cpt_aes_key_len { 638c2ecf20Sopenharmony_ci OTX_CPT_AES_128_BIT = 0x1, 648c2ecf20Sopenharmony_ci OTX_CPT_AES_192_BIT = 0x2, 658c2ecf20Sopenharmony_ci OTX_CPT_AES_256_BIT = 0x3 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciunion otx_cpt_encr_ctrl { 698c2ecf20Sopenharmony_ci __be64 flags; 708c2ecf20Sopenharmony_ci u64 cflags; 718c2ecf20Sopenharmony_ci struct { 728c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD) 738c2ecf20Sopenharmony_ci u64 enc_cipher:4; 748c2ecf20Sopenharmony_ci u64 reserved1:1; 758c2ecf20Sopenharmony_ci u64 aes_key:2; 768c2ecf20Sopenharmony_ci u64 iv_source:1; 778c2ecf20Sopenharmony_ci u64 mac_type:4; 788c2ecf20Sopenharmony_ci u64 reserved2:3; 798c2ecf20Sopenharmony_ci u64 auth_input_type:1; 808c2ecf20Sopenharmony_ci u64 mac_len:8; 818c2ecf20Sopenharmony_ci u64 reserved3:8; 828c2ecf20Sopenharmony_ci u64 encr_offset:16; 838c2ecf20Sopenharmony_ci u64 iv_offset:8; 848c2ecf20Sopenharmony_ci u64 auth_offset:8; 858c2ecf20Sopenharmony_ci#else 868c2ecf20Sopenharmony_ci u64 auth_offset:8; 878c2ecf20Sopenharmony_ci u64 iv_offset:8; 888c2ecf20Sopenharmony_ci u64 encr_offset:16; 898c2ecf20Sopenharmony_ci u64 reserved3:8; 908c2ecf20Sopenharmony_ci u64 mac_len:8; 918c2ecf20Sopenharmony_ci u64 auth_input_type:1; 928c2ecf20Sopenharmony_ci u64 reserved2:3; 938c2ecf20Sopenharmony_ci u64 mac_type:4; 948c2ecf20Sopenharmony_ci u64 iv_source:1; 958c2ecf20Sopenharmony_ci u64 aes_key:2; 968c2ecf20Sopenharmony_ci u64 reserved1:1; 978c2ecf20Sopenharmony_ci u64 enc_cipher:4; 988c2ecf20Sopenharmony_ci#endif 998c2ecf20Sopenharmony_ci } e; 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistruct otx_cpt_cipher { 1038c2ecf20Sopenharmony_ci const char *name; 1048c2ecf20Sopenharmony_ci u8 value; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_cistruct otx_cpt_enc_context { 1088c2ecf20Sopenharmony_ci union otx_cpt_encr_ctrl enc_ctrl; 1098c2ecf20Sopenharmony_ci u8 encr_key[32]; 1108c2ecf20Sopenharmony_ci u8 encr_iv[16]; 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciunion otx_cpt_fchmac_ctx { 1148c2ecf20Sopenharmony_ci struct { 1158c2ecf20Sopenharmony_ci u8 ipad[64]; 1168c2ecf20Sopenharmony_ci u8 opad[64]; 1178c2ecf20Sopenharmony_ci } e; 1188c2ecf20Sopenharmony_ci struct { 1198c2ecf20Sopenharmony_ci u8 hmac_calc[64]; /* HMAC calculated */ 1208c2ecf20Sopenharmony_ci u8 hmac_recv[64]; /* HMAC received */ 1218c2ecf20Sopenharmony_ci } s; 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistruct otx_cpt_fc_ctx { 1258c2ecf20Sopenharmony_ci struct otx_cpt_enc_context enc; 1268c2ecf20Sopenharmony_ci union otx_cpt_fchmac_ctx hmac; 1278c2ecf20Sopenharmony_ci}; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistruct otx_cpt_enc_ctx { 1308c2ecf20Sopenharmony_ci u32 key_len; 1318c2ecf20Sopenharmony_ci u8 enc_key[OTX_CPT_MAX_KEY_SIZE]; 1328c2ecf20Sopenharmony_ci u8 cipher_type; 1338c2ecf20Sopenharmony_ci u8 key_type; 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistruct otx_cpt_des3_ctx { 1378c2ecf20Sopenharmony_ci u32 key_len; 1388c2ecf20Sopenharmony_ci u8 des3_key[OTX_CPT_MAX_KEY_SIZE]; 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ciunion otx_cpt_offset_ctrl_word { 1428c2ecf20Sopenharmony_ci __be64 flags; 1438c2ecf20Sopenharmony_ci u64 cflags; 1448c2ecf20Sopenharmony_ci struct { 1458c2ecf20Sopenharmony_ci#if defined(__BIG_ENDIAN_BITFIELD) 1468c2ecf20Sopenharmony_ci u64 reserved:32; 1478c2ecf20Sopenharmony_ci u64 enc_data_offset:16; 1488c2ecf20Sopenharmony_ci u64 iv_offset:8; 1498c2ecf20Sopenharmony_ci u64 auth_offset:8; 1508c2ecf20Sopenharmony_ci#else 1518c2ecf20Sopenharmony_ci u64 auth_offset:8; 1528c2ecf20Sopenharmony_ci u64 iv_offset:8; 1538c2ecf20Sopenharmony_ci u64 enc_data_offset:16; 1548c2ecf20Sopenharmony_ci u64 reserved:32; 1558c2ecf20Sopenharmony_ci#endif 1568c2ecf20Sopenharmony_ci } e; 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistruct otx_cpt_req_ctx { 1608c2ecf20Sopenharmony_ci struct otx_cpt_req_info cpt_req; 1618c2ecf20Sopenharmony_ci union otx_cpt_offset_ctrl_word ctrl_word; 1628c2ecf20Sopenharmony_ci struct otx_cpt_fc_ctx fctx; 1638c2ecf20Sopenharmony_ci}; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_cistruct otx_cpt_sdesc { 1668c2ecf20Sopenharmony_ci struct shash_desc shash; 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistruct otx_cpt_aead_ctx { 1708c2ecf20Sopenharmony_ci u8 key[OTX_CPT_MAX_KEY_SIZE]; 1718c2ecf20Sopenharmony_ci struct crypto_shash *hashalg; 1728c2ecf20Sopenharmony_ci struct otx_cpt_sdesc *sdesc; 1738c2ecf20Sopenharmony_ci u8 *ipad; 1748c2ecf20Sopenharmony_ci u8 *opad; 1758c2ecf20Sopenharmony_ci u32 enc_key_len; 1768c2ecf20Sopenharmony_ci u32 auth_key_len; 1778c2ecf20Sopenharmony_ci u8 cipher_type; 1788c2ecf20Sopenharmony_ci u8 mac_type; 1798c2ecf20Sopenharmony_ci u8 key_type; 1808c2ecf20Sopenharmony_ci u8 is_trunc_hmac; 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ciint otx_cpt_crypto_init(struct pci_dev *pdev, struct module *mod, 1838c2ecf20Sopenharmony_ci enum otx_cptpf_type pf_type, 1848c2ecf20Sopenharmony_ci enum otx_cptvf_type engine_type, 1858c2ecf20Sopenharmony_ci int num_queues, int num_devices); 1868c2ecf20Sopenharmony_civoid otx_cpt_crypto_exit(struct pci_dev *pdev, struct module *mod, 1878c2ecf20Sopenharmony_ci enum otx_cptvf_type engine_type); 1888c2ecf20Sopenharmony_civoid otx_cpt_callback(int status, void *arg, void *req); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci#endif /* __OTX_CPT_ALGS_H */ 191