18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * K3 SA2UL crypto accelerator driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2018-2020 Texas Instruments Incorporated - http://www.ti.com 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Authors: Keerthy 88c2ecf20Sopenharmony_ci * Vitaly Andrianov 98c2ecf20Sopenharmony_ci * Tero Kristo 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef _K3_SA2UL_ 138c2ecf20Sopenharmony_ci#define _K3_SA2UL_ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 168c2ecf20Sopenharmony_ci#include <linux/skbuff.h> 178c2ecf20Sopenharmony_ci#include <linux/hw_random.h> 188c2ecf20Sopenharmony_ci#include <crypto/aes.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define SA_ENGINE_ENABLE_CONTROL 0x1000 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct sa_tfm_ctx; 238c2ecf20Sopenharmony_ci/* 248c2ecf20Sopenharmony_ci * SA_ENGINE_ENABLE_CONTROL register bits 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci#define SA_EEC_ENCSS_EN 0x00000001 278c2ecf20Sopenharmony_ci#define SA_EEC_AUTHSS_EN 0x00000002 288c2ecf20Sopenharmony_ci#define SA_EEC_TRNG_EN 0x00000008 298c2ecf20Sopenharmony_ci#define SA_EEC_PKA_EN 0x00000010 308c2ecf20Sopenharmony_ci#define SA_EEC_CTXCACH_EN 0x00000080 318c2ecf20Sopenharmony_ci#define SA_EEC_CPPI_PORT_IN_EN 0x00000200 328c2ecf20Sopenharmony_ci#define SA_EEC_CPPI_PORT_OUT_EN 0x00000800 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* 358c2ecf20Sopenharmony_ci * Encoding used to identify the typo of crypto operation 368c2ecf20Sopenharmony_ci * performed on the packet when the packet is returned 378c2ecf20Sopenharmony_ci * by SA 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci#define SA_REQ_SUBTYPE_ENC 0x0001 408c2ecf20Sopenharmony_ci#define SA_REQ_SUBTYPE_DEC 0x0002 418c2ecf20Sopenharmony_ci#define SA_REQ_SUBTYPE_SHIFT 16 428c2ecf20Sopenharmony_ci#define SA_REQ_SUBTYPE_MASK 0xffff 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Number of 32 bit words in EPIB */ 458c2ecf20Sopenharmony_ci#define SA_DMA_NUM_EPIB_WORDS 4 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* Number of 32 bit words in PS data */ 488c2ecf20Sopenharmony_ci#define SA_DMA_NUM_PS_WORDS 16 498c2ecf20Sopenharmony_ci#define NKEY_SZ 3 508c2ecf20Sopenharmony_ci#define MCI_SZ 27 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * Maximum number of simultaeneous security contexts 548c2ecf20Sopenharmony_ci * supported by the driver 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_ci#define SA_MAX_NUM_CTX 512 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci/* 598c2ecf20Sopenharmony_ci * Assumption: CTX size is multiple of 32 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci#define SA_CTX_SIZE_TO_DMA_SIZE(ctx_sz) \ 628c2ecf20Sopenharmony_ci ((ctx_sz) ? ((ctx_sz) / 32 - 1) : 0) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define SA_CTX_ENC_KEY_OFFSET 32 658c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX1_OFFSET 64 668c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX2_OFFSET 96 678c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX3_OFFSET 112 688c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX4_OFFSET 128 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Next Engine Select code in CP_ACE */ 718c2ecf20Sopenharmony_ci#define SA_ENG_ID_EM1 2 /* Enc/Dec engine with AES/DEC core */ 728c2ecf20Sopenharmony_ci#define SA_ENG_ID_EM2 3 /* Encryption/Decryption enginefor pass 2 */ 738c2ecf20Sopenharmony_ci#define SA_ENG_ID_AM1 4 /* Auth. engine with SHA1/MD5/SHA2 core */ 748c2ecf20Sopenharmony_ci#define SA_ENG_ID_AM2 5 /* Authentication engine for pass 2 */ 758c2ecf20Sopenharmony_ci#define SA_ENG_ID_OUTPORT2 20 /* Egress module 2 */ 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* 788c2ecf20Sopenharmony_ci * Command Label Definitions 798c2ecf20Sopenharmony_ci */ 808c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_NESC 0 /* Next Engine Select Code */ 818c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_LABEL_LEN 1 /* Engine Command Label Length */ 828c2ecf20Sopenharmony_ci/* 16-bit Length of Data to be processed */ 838c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_DATA_LEN 2 848c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_DATA_OFFSET 4 /* Stat Data Offset */ 858c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_OPTION_CTRL1 5 /* Option Control Byte 1 */ 868c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_OPTION_CTRL2 6 /* Option Control Byte 2 */ 878c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_OPTION_CTRL3 7 /* Option Control Byte 3 */ 888c2ecf20Sopenharmony_ci#define SA_CMDL_OFFSET_OPTION_BYTE 8 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#define SA_CMDL_HEADER_SIZE_BYTES 8 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define SA_CMDL_OPTION_BYTES_MAX_SIZE 72 938c2ecf20Sopenharmony_ci#define SA_CMDL_MAX_SIZE_BYTES (SA_CMDL_HEADER_SIZE_BYTES + \ 948c2ecf20Sopenharmony_ci SA_CMDL_OPTION_BYTES_MAX_SIZE) 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* SWINFO word-0 flags */ 978c2ecf20Sopenharmony_ci#define SA_SW_INFO_FLAG_EVICT 0x0001 988c2ecf20Sopenharmony_ci#define SA_SW_INFO_FLAG_TEAR 0x0002 998c2ecf20Sopenharmony_ci#define SA_SW_INFO_FLAG_NOPD 0x0004 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* 1028c2ecf20Sopenharmony_ci * This type represents the various packet types to be processed 1038c2ecf20Sopenharmony_ci * by the PHP engine in SA. 1048c2ecf20Sopenharmony_ci * It is used to identify the corresponding PHP processing function. 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_ci#define SA_CTX_PE_PKT_TYPE_3GPP_AIR 0 /* 3GPP Air Cipher */ 1078c2ecf20Sopenharmony_ci#define SA_CTX_PE_PKT_TYPE_SRTP 1 /* SRTP */ 1088c2ecf20Sopenharmony_ci#define SA_CTX_PE_PKT_TYPE_IPSEC_AH 2 /* IPSec Authentication Header */ 1098c2ecf20Sopenharmony_ci/* IPSec Encapsulating Security Payload */ 1108c2ecf20Sopenharmony_ci#define SA_CTX_PE_PKT_TYPE_IPSEC_ESP 3 1118c2ecf20Sopenharmony_ci/* Indicates that it is in data mode, It may not be used by PHP */ 1128c2ecf20Sopenharmony_ci#define SA_CTX_PE_PKT_TYPE_NONE 4 1138c2ecf20Sopenharmony_ci#define SA_CTX_ENC_TYPE1_SZ 64 /* Encryption SC with Key only */ 1148c2ecf20Sopenharmony_ci#define SA_CTX_ENC_TYPE2_SZ 96 /* Encryption SC with Key and Aux1 */ 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#define SA_CTX_AUTH_TYPE1_SZ 64 /* Auth SC with Key only */ 1178c2ecf20Sopenharmony_ci#define SA_CTX_AUTH_TYPE2_SZ 96 /* Auth SC with Key and Aux1 */ 1188c2ecf20Sopenharmony_ci/* Size of security context for PHP engine */ 1198c2ecf20Sopenharmony_ci#define SA_CTX_PHP_PE_CTX_SZ 64 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define SA_CTX_MAX_SZ (64 + SA_CTX_ENC_TYPE2_SZ + SA_CTX_AUTH_TYPE2_SZ) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * Encoding of F/E control in SCCTL 1258c2ecf20Sopenharmony_ci * Bit 0-1: Fetch PHP Bytes 1268c2ecf20Sopenharmony_ci * Bit 2-3: Fetch Encryption/Air Ciphering Bytes 1278c2ecf20Sopenharmony_ci * Bit 4-5: Fetch Authentication Bytes or Encr pass 2 1288c2ecf20Sopenharmony_ci * Bit 6-7: Evict PHP Bytes 1298c2ecf20Sopenharmony_ci * 1308c2ecf20Sopenharmony_ci * where 00 = 0 bytes 1318c2ecf20Sopenharmony_ci * 01 = 64 bytes 1328c2ecf20Sopenharmony_ci * 10 = 96 bytes 1338c2ecf20Sopenharmony_ci * 11 = 128 bytes 1348c2ecf20Sopenharmony_ci */ 1358c2ecf20Sopenharmony_ci#define SA_CTX_DMA_SIZE_0 0 1368c2ecf20Sopenharmony_ci#define SA_CTX_DMA_SIZE_64 1 1378c2ecf20Sopenharmony_ci#define SA_CTX_DMA_SIZE_96 2 1388c2ecf20Sopenharmony_ci#define SA_CTX_DMA_SIZE_128 3 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/* 1418c2ecf20Sopenharmony_ci * Byte offset of the owner word in SCCTL 1428c2ecf20Sopenharmony_ci * in the security context 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ci#define SA_CTX_SCCTL_OWNER_OFFSET 0 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci#define SA_CTX_ENC_KEY_OFFSET 32 1478c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX1_OFFSET 64 1488c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX2_OFFSET 96 1498c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX3_OFFSET 112 1508c2ecf20Sopenharmony_ci#define SA_CTX_ENC_AUX4_OFFSET 128 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define SA_SCCTL_FE_AUTH_ENC 0x65 1538c2ecf20Sopenharmony_ci#define SA_SCCTL_FE_ENC 0x8D 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#define SA_ALIGN_MASK (sizeof(u32) - 1) 1568c2ecf20Sopenharmony_ci#define SA_ALIGNED __aligned(32) 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_MD5 1 1598c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_SHA1 2 1608c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_SHA224 3 1618c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_SHA256 4 1628c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_SHA384 5 1638c2ecf20Sopenharmony_ci#define SA_AUTH_SW_CTRL_SHA512 6 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/* SA2UL can only handle maximum data size of 64KB */ 1668c2ecf20Sopenharmony_ci#define SA_MAX_DATA_SZ U16_MAX 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci/* 1698c2ecf20Sopenharmony_ci * SA2UL can provide unpredictable results with packet sizes that fall 1708c2ecf20Sopenharmony_ci * the following range, so avoid using it. 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_ci#define SA_UNSAFE_DATA_SZ_MIN 240 1738c2ecf20Sopenharmony_ci#define SA_UNSAFE_DATA_SZ_MAX 256 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/** 1768c2ecf20Sopenharmony_ci * struct sa_crypto_data - Crypto driver instance data 1778c2ecf20Sopenharmony_ci * @base: Base address of the register space 1788c2ecf20Sopenharmony_ci * @pdev: Platform device pointer 1798c2ecf20Sopenharmony_ci * @sc_pool: security context pool 1808c2ecf20Sopenharmony_ci * @dev: Device pointer 1818c2ecf20Sopenharmony_ci * @scid_lock: secure context ID lock 1828c2ecf20Sopenharmony_ci * @sc_id_start: starting index for SC ID 1838c2ecf20Sopenharmony_ci * @sc_id_end: Ending index for SC ID 1848c2ecf20Sopenharmony_ci * @sc_id: Security Context ID 1858c2ecf20Sopenharmony_ci * @ctx_bm: Bitmap to keep track of Security context ID's 1868c2ecf20Sopenharmony_ci * @ctx: SA tfm context pointer 1878c2ecf20Sopenharmony_ci * @dma_rx1: Pointer to DMA rx channel for sizes < 256 Bytes 1888c2ecf20Sopenharmony_ci * @dma_rx2: Pointer to DMA rx channel for sizes > 256 Bytes 1898c2ecf20Sopenharmony_ci * @dma_tx: Pointer to DMA TX channel 1908c2ecf20Sopenharmony_ci */ 1918c2ecf20Sopenharmony_cistruct sa_crypto_data { 1928c2ecf20Sopenharmony_ci void __iomem *base; 1938c2ecf20Sopenharmony_ci struct platform_device *pdev; 1948c2ecf20Sopenharmony_ci struct dma_pool *sc_pool; 1958c2ecf20Sopenharmony_ci struct device *dev; 1968c2ecf20Sopenharmony_ci spinlock_t scid_lock; /* lock for SC-ID allocation */ 1978c2ecf20Sopenharmony_ci /* Security context data */ 1988c2ecf20Sopenharmony_ci u16 sc_id_start; 1998c2ecf20Sopenharmony_ci u16 sc_id_end; 2008c2ecf20Sopenharmony_ci u16 sc_id; 2018c2ecf20Sopenharmony_ci unsigned long ctx_bm[DIV_ROUND_UP(SA_MAX_NUM_CTX, 2028c2ecf20Sopenharmony_ci BITS_PER_LONG)]; 2038c2ecf20Sopenharmony_ci struct sa_tfm_ctx *ctx; 2048c2ecf20Sopenharmony_ci struct dma_chan *dma_rx1; 2058c2ecf20Sopenharmony_ci struct dma_chan *dma_rx2; 2068c2ecf20Sopenharmony_ci struct dma_chan *dma_tx; 2078c2ecf20Sopenharmony_ci}; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci/** 2108c2ecf20Sopenharmony_ci * struct sa_cmdl_param_info: Command label parameters info 2118c2ecf20Sopenharmony_ci * @index: Index of the parameter in the command label format 2128c2ecf20Sopenharmony_ci * @offset: the offset of the parameter 2138c2ecf20Sopenharmony_ci * @size: Size of the parameter 2148c2ecf20Sopenharmony_ci */ 2158c2ecf20Sopenharmony_cistruct sa_cmdl_param_info { 2168c2ecf20Sopenharmony_ci u16 index; 2178c2ecf20Sopenharmony_ci u16 offset; 2188c2ecf20Sopenharmony_ci u16 size; 2198c2ecf20Sopenharmony_ci}; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/* Maximum length of Auxiliary data in 32bit words */ 2228c2ecf20Sopenharmony_ci#define SA_MAX_AUX_DATA_WORDS 8 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci/** 2258c2ecf20Sopenharmony_ci * struct sa_cmdl_upd_info: Command label updation info 2268c2ecf20Sopenharmony_ci * @flags: flags in command label 2278c2ecf20Sopenharmony_ci * @submode: Encryption submodes 2288c2ecf20Sopenharmony_ci * @enc_size: Size of first pass encryption size 2298c2ecf20Sopenharmony_ci * @enc_size2: Size of second pass encryption size 2308c2ecf20Sopenharmony_ci * @enc_offset: Encryption payload offset in the packet 2318c2ecf20Sopenharmony_ci * @enc_iv: Encryption initialization vector for pass2 2328c2ecf20Sopenharmony_ci * @enc_iv2: Encryption initialization vector for pass2 2338c2ecf20Sopenharmony_ci * @aad: Associated data 2348c2ecf20Sopenharmony_ci * @payload: Payload info 2358c2ecf20Sopenharmony_ci * @auth_size: Authentication size for pass 1 2368c2ecf20Sopenharmony_ci * @auth_size2: Authentication size for pass 2 2378c2ecf20Sopenharmony_ci * @auth_offset: Authentication payload offset 2388c2ecf20Sopenharmony_ci * @auth_iv: Authentication initialization vector 2398c2ecf20Sopenharmony_ci * @aux_key_info: Authentication aux key information 2408c2ecf20Sopenharmony_ci * @aux_key: Aux key for authentication 2418c2ecf20Sopenharmony_ci */ 2428c2ecf20Sopenharmony_cistruct sa_cmdl_upd_info { 2438c2ecf20Sopenharmony_ci u16 flags; 2448c2ecf20Sopenharmony_ci u16 submode; 2458c2ecf20Sopenharmony_ci struct sa_cmdl_param_info enc_size; 2468c2ecf20Sopenharmony_ci struct sa_cmdl_param_info enc_size2; 2478c2ecf20Sopenharmony_ci struct sa_cmdl_param_info enc_offset; 2488c2ecf20Sopenharmony_ci struct sa_cmdl_param_info enc_iv; 2498c2ecf20Sopenharmony_ci struct sa_cmdl_param_info enc_iv2; 2508c2ecf20Sopenharmony_ci struct sa_cmdl_param_info aad; 2518c2ecf20Sopenharmony_ci struct sa_cmdl_param_info payload; 2528c2ecf20Sopenharmony_ci struct sa_cmdl_param_info auth_size; 2538c2ecf20Sopenharmony_ci struct sa_cmdl_param_info auth_size2; 2548c2ecf20Sopenharmony_ci struct sa_cmdl_param_info auth_offset; 2558c2ecf20Sopenharmony_ci struct sa_cmdl_param_info auth_iv; 2568c2ecf20Sopenharmony_ci struct sa_cmdl_param_info aux_key_info; 2578c2ecf20Sopenharmony_ci u32 aux_key[SA_MAX_AUX_DATA_WORDS]; 2588c2ecf20Sopenharmony_ci}; 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci/* 2618c2ecf20Sopenharmony_ci * Number of 32bit words appended after the command label 2628c2ecf20Sopenharmony_ci * in PSDATA to identify the crypto request context. 2638c2ecf20Sopenharmony_ci * word-0: Request type 2648c2ecf20Sopenharmony_ci * word-1: pointer to request 2658c2ecf20Sopenharmony_ci */ 2668c2ecf20Sopenharmony_ci#define SA_PSDATA_CTX_WORDS 4 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci/* Maximum size of Command label in 32 words */ 2698c2ecf20Sopenharmony_ci#define SA_MAX_CMDL_WORDS (SA_DMA_NUM_PS_WORDS - SA_PSDATA_CTX_WORDS) 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci/** 2728c2ecf20Sopenharmony_ci * struct sa_ctx_info: SA context information 2738c2ecf20Sopenharmony_ci * @sc: Pointer to security context 2748c2ecf20Sopenharmony_ci * @sc_phys: Security context physical address that is passed on to SA2UL 2758c2ecf20Sopenharmony_ci * @sc_id: Security context ID 2768c2ecf20Sopenharmony_ci * @cmdl_size: Command label size 2778c2ecf20Sopenharmony_ci * @cmdl: Command label for a particular iteration 2788c2ecf20Sopenharmony_ci * @cmdl_upd_info: structure holding command label updation info 2798c2ecf20Sopenharmony_ci * @epib: Extended protocol information block words 2808c2ecf20Sopenharmony_ci */ 2818c2ecf20Sopenharmony_cistruct sa_ctx_info { 2828c2ecf20Sopenharmony_ci u8 *sc; 2838c2ecf20Sopenharmony_ci dma_addr_t sc_phys; 2848c2ecf20Sopenharmony_ci u16 sc_id; 2858c2ecf20Sopenharmony_ci u16 cmdl_size; 2868c2ecf20Sopenharmony_ci u32 cmdl[SA_MAX_CMDL_WORDS]; 2878c2ecf20Sopenharmony_ci struct sa_cmdl_upd_info cmdl_upd_info; 2888c2ecf20Sopenharmony_ci /* Store Auxiliary data such as K2/K3 subkeys in AES-XCBC */ 2898c2ecf20Sopenharmony_ci u32 epib[SA_DMA_NUM_EPIB_WORDS]; 2908c2ecf20Sopenharmony_ci}; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci/** 2938c2ecf20Sopenharmony_ci * struct sa_tfm_ctx: TFM context structure 2948c2ecf20Sopenharmony_ci * @dev_data: struct sa_crypto_data pointer 2958c2ecf20Sopenharmony_ci * @enc: struct sa_ctx_info for encryption 2968c2ecf20Sopenharmony_ci * @dec: struct sa_ctx_info for decryption 2978c2ecf20Sopenharmony_ci * @keylen: encrption/decryption keylength 2988c2ecf20Sopenharmony_ci * @iv_idx: Initialization vector index 2998c2ecf20Sopenharmony_ci * @key: encryption key 3008c2ecf20Sopenharmony_ci * @fallback: SW fallback algorithm 3018c2ecf20Sopenharmony_ci */ 3028c2ecf20Sopenharmony_cistruct sa_tfm_ctx { 3038c2ecf20Sopenharmony_ci struct sa_crypto_data *dev_data; 3048c2ecf20Sopenharmony_ci struct sa_ctx_info enc; 3058c2ecf20Sopenharmony_ci struct sa_ctx_info dec; 3068c2ecf20Sopenharmony_ci struct sa_ctx_info auth; 3078c2ecf20Sopenharmony_ci int keylen; 3088c2ecf20Sopenharmony_ci int iv_idx; 3098c2ecf20Sopenharmony_ci u32 key[AES_KEYSIZE_256 / sizeof(u32)]; 3108c2ecf20Sopenharmony_ci u8 authkey[SHA512_BLOCK_SIZE]; 3118c2ecf20Sopenharmony_ci struct crypto_shash *shash; 3128c2ecf20Sopenharmony_ci /* for fallback */ 3138c2ecf20Sopenharmony_ci union { 3148c2ecf20Sopenharmony_ci struct crypto_sync_skcipher *skcipher; 3158c2ecf20Sopenharmony_ci struct crypto_ahash *ahash; 3168c2ecf20Sopenharmony_ci struct crypto_aead *aead; 3178c2ecf20Sopenharmony_ci } fallback; 3188c2ecf20Sopenharmony_ci}; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci/** 3218c2ecf20Sopenharmony_ci * struct sa_sha_req_ctx: Structure used for sha request 3228c2ecf20Sopenharmony_ci * @dev_data: struct sa_crypto_data pointer 3238c2ecf20Sopenharmony_ci * @cmdl: Complete command label with psdata and epib included 3248c2ecf20Sopenharmony_ci * @fallback_req: SW fallback request container 3258c2ecf20Sopenharmony_ci */ 3268c2ecf20Sopenharmony_cistruct sa_sha_req_ctx { 3278c2ecf20Sopenharmony_ci struct sa_crypto_data *dev_data; 3288c2ecf20Sopenharmony_ci u32 cmdl[SA_MAX_CMDL_WORDS + SA_PSDATA_CTX_WORDS]; 3298c2ecf20Sopenharmony_ci struct ahash_request fallback_req; 3308c2ecf20Sopenharmony_ci}; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_cienum sa_submode { 3338c2ecf20Sopenharmony_ci SA_MODE_GEN = 0, 3348c2ecf20Sopenharmony_ci SA_MODE_CCM, 3358c2ecf20Sopenharmony_ci SA_MODE_GCM, 3368c2ecf20Sopenharmony_ci SA_MODE_GMAC 3378c2ecf20Sopenharmony_ci}; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci/* Encryption algorithms */ 3408c2ecf20Sopenharmony_cienum sa_ealg_id { 3418c2ecf20Sopenharmony_ci SA_EALG_ID_NONE = 0, /* No encryption */ 3428c2ecf20Sopenharmony_ci SA_EALG_ID_NULL, /* NULL encryption */ 3438c2ecf20Sopenharmony_ci SA_EALG_ID_AES_CTR, /* AES Counter mode */ 3448c2ecf20Sopenharmony_ci SA_EALG_ID_AES_F8, /* AES F8 mode */ 3458c2ecf20Sopenharmony_ci SA_EALG_ID_AES_CBC, /* AES CBC mode */ 3468c2ecf20Sopenharmony_ci SA_EALG_ID_DES_CBC, /* DES CBC mode */ 3478c2ecf20Sopenharmony_ci SA_EALG_ID_3DES_CBC, /* 3DES CBC mode */ 3488c2ecf20Sopenharmony_ci SA_EALG_ID_CCM, /* Counter with CBC-MAC mode */ 3498c2ecf20Sopenharmony_ci SA_EALG_ID_GCM, /* Galois Counter mode */ 3508c2ecf20Sopenharmony_ci SA_EALG_ID_AES_ECB, 3518c2ecf20Sopenharmony_ci SA_EALG_ID_LAST 3528c2ecf20Sopenharmony_ci}; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci/* Authentication algorithms */ 3558c2ecf20Sopenharmony_cienum sa_aalg_id { 3568c2ecf20Sopenharmony_ci SA_AALG_ID_NONE = 0, /* No Authentication */ 3578c2ecf20Sopenharmony_ci SA_AALG_ID_NULL = SA_EALG_ID_LAST, /* NULL Authentication */ 3588c2ecf20Sopenharmony_ci SA_AALG_ID_MD5, /* MD5 mode */ 3598c2ecf20Sopenharmony_ci SA_AALG_ID_SHA1, /* SHA1 mode */ 3608c2ecf20Sopenharmony_ci SA_AALG_ID_SHA2_224, /* 224-bit SHA2 mode */ 3618c2ecf20Sopenharmony_ci SA_AALG_ID_SHA2_256, /* 256-bit SHA2 mode */ 3628c2ecf20Sopenharmony_ci SA_AALG_ID_SHA2_512, /* 512-bit SHA2 mode */ 3638c2ecf20Sopenharmony_ci SA_AALG_ID_HMAC_MD5, /* HMAC with MD5 mode */ 3648c2ecf20Sopenharmony_ci SA_AALG_ID_HMAC_SHA1, /* HMAC with SHA1 mode */ 3658c2ecf20Sopenharmony_ci SA_AALG_ID_HMAC_SHA2_224, /* HMAC with 224-bit SHA2 mode */ 3668c2ecf20Sopenharmony_ci SA_AALG_ID_HMAC_SHA2_256, /* HMAC with 256-bit SHA2 mode */ 3678c2ecf20Sopenharmony_ci SA_AALG_ID_GMAC, /* Galois Message Auth. Code mode */ 3688c2ecf20Sopenharmony_ci SA_AALG_ID_CMAC, /* Cipher-based Mes. Auth. Code mode */ 3698c2ecf20Sopenharmony_ci SA_AALG_ID_CBC_MAC, /* Cipher Block Chaining */ 3708c2ecf20Sopenharmony_ci SA_AALG_ID_AES_XCBC /* AES Extended Cipher Block Chaining */ 3718c2ecf20Sopenharmony_ci}; 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci/* 3748c2ecf20Sopenharmony_ci * Mode control engine algorithms used to index the 3758c2ecf20Sopenharmony_ci * mode control instruction tables 3768c2ecf20Sopenharmony_ci */ 3778c2ecf20Sopenharmony_cienum sa_eng_algo_id { 3788c2ecf20Sopenharmony_ci SA_ENG_ALGO_ECB = 0, 3798c2ecf20Sopenharmony_ci SA_ENG_ALGO_CBC, 3808c2ecf20Sopenharmony_ci SA_ENG_ALGO_CFB, 3818c2ecf20Sopenharmony_ci SA_ENG_ALGO_OFB, 3828c2ecf20Sopenharmony_ci SA_ENG_ALGO_CTR, 3838c2ecf20Sopenharmony_ci SA_ENG_ALGO_F8, 3848c2ecf20Sopenharmony_ci SA_ENG_ALGO_F8F9, 3858c2ecf20Sopenharmony_ci SA_ENG_ALGO_GCM, 3868c2ecf20Sopenharmony_ci SA_ENG_ALGO_GMAC, 3878c2ecf20Sopenharmony_ci SA_ENG_ALGO_CCM, 3888c2ecf20Sopenharmony_ci SA_ENG_ALGO_CMAC, 3898c2ecf20Sopenharmony_ci SA_ENG_ALGO_CBCMAC, 3908c2ecf20Sopenharmony_ci SA_NUM_ENG_ALGOS 3918c2ecf20Sopenharmony_ci}; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci/** 3948c2ecf20Sopenharmony_ci * struct sa_eng_info: Security accelerator engine info 3958c2ecf20Sopenharmony_ci * @eng_id: Engine ID 3968c2ecf20Sopenharmony_ci * @sc_size: security context size 3978c2ecf20Sopenharmony_ci */ 3988c2ecf20Sopenharmony_cistruct sa_eng_info { 3998c2ecf20Sopenharmony_ci u8 eng_id; 4008c2ecf20Sopenharmony_ci u16 sc_size; 4018c2ecf20Sopenharmony_ci}; 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci#endif /* _K3_SA2UL_ */ 404