Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is part of the Chelsio T6 Crypto driver for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * licenses.  You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *     Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *     without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *     conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *      - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *        disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *      - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *        copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *        disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *        provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #ifndef __CHCR_CRYPTO_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define __CHCR_CRYPTO_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define GHASH_BLOCK_SIZE    16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define GHASH_DIGEST_SIZE   16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define CCM_B0_SIZE             16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define CCM_AAD_FIELD_SIZE      2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) // 511 - 16(For IV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define T6_MAX_AAD_SIZE 495
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) /* Define following if h/w is not dropping the AAD and IV data before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * giving the processed data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define CHCR_CRA_PRIORITY 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define CHCR_AEAD_PRIORITY 6000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define CHCR_AES_MAX_KEY_LEN  (2 * (AES_MAX_KEY_SIZE)) /* consider xts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define CHCR_MAX_AUTHENC_AES_KEY_LEN 32 /* max aes key length*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128 /* max sha key length*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define CHCR_GIVENCRYPT_OP 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /* CPL/SCMD parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define CHCR_ENCRYPT_OP 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define CHCR_DECRYPT_OP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define CHCR_SCMD_SEQ_NO_CTRL_32BIT     1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define CHCR_SCMD_SEQ_NO_CTRL_48BIT     2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define CHCR_SCMD_SEQ_NO_CTRL_64BIT     3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define CHCR_SCMD_PROTO_VERSION_GENERIC 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define CHCR_SCMD_CIPHER_MODE_NOP               0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define CHCR_SCMD_CIPHER_MODE_AES_CBC           1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define CHCR_SCMD_CIPHER_MODE_AES_GCM           2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define CHCR_SCMD_CIPHER_MODE_AES_CTR           3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES       4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define CHCR_SCMD_CIPHER_MODE_AES_XTS           6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define CHCR_SCMD_CIPHER_MODE_AES_CCM           7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) #define CHCR_SCMD_AUTH_MODE_NOP             0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define CHCR_SCMD_AUTH_MODE_SHA1            1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define CHCR_SCMD_AUTH_MODE_SHA224          2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define CHCR_SCMD_AUTH_MODE_SHA256          3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define CHCR_SCMD_AUTH_MODE_GHASH           4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define CHCR_SCMD_AUTH_MODE_SHA512_224      5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define CHCR_SCMD_AUTH_MODE_SHA512_256      6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define CHCR_SCMD_AUTH_MODE_SHA512_384      7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define CHCR_SCMD_AUTH_MODE_SHA512_512      8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define CHCR_SCMD_AUTH_MODE_CBCMAC          9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define CHCR_SCMD_AUTH_MODE_CMAC            10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define CHCR_SCMD_HMAC_CTRL_NOP             0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC        1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define CHCR_SCMD_HMAC_CTRL_TRUNC_RFC4366   2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define CHCR_SCMD_HMAC_CTRL_IPSEC_96BIT     3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define CHCR_SCMD_HMAC_CTRL_PL1		    4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define CHCR_SCMD_HMAC_CTRL_PL2		    5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define CHCR_SCMD_HMAC_CTRL_PL3		    6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define CHCR_SCMD_HMAC_CTRL_DIV2	    7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define VERIFY_HW 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define VERIFY_SW 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define CHCR_SCMD_IVGEN_CTRL_HW             0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define CHCR_SCMD_IVGEN_CTRL_SW             1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* This are not really mac key size. They are intermediate values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * of sha engine and its size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define CHCR_KEYCTX_MAC_KEY_SIZE_128        0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define CHCR_KEYCTX_MAC_KEY_SIZE_160        1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define CHCR_KEYCTX_MAC_KEY_SIZE_192        2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define CHCR_KEYCTX_MAC_KEY_SIZE_256        3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define CHCR_KEYCTX_MAC_KEY_SIZE_512        4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128     0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192     1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256     2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define CHCR_KEYCTX_NO_KEY                  15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define CHCR_CPL_FW4_PLD_IV_OFFSET          (5 * 64) /* bytes. flt #5 and #6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64) /* bytes. flt #7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define CHCR_CPL_FW4_PLD_DATA_SIZE          (4 * 64) /* bytes. flt #4 to #7 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define KEY_CONTEXT_HDR_SALT_AND_PAD	    16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define flits_to_bytes(x)  (x * 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define IV_NOP                  0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define IV_IMMEDIATE            1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define IV_DSGL			2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define AEAD_H_SIZE             16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define CRYPTO_ALG_SUB_TYPE_MASK            0x0f000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define CRYPTO_ALG_SUB_TYPE_HASH_HMAC       0x01000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106    0x02000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define CRYPTO_ALG_SUB_TYPE_AEAD_GCM	    0x03000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define CRYPTO_ALG_SUB_TYPE_CBC_SHA	    0x04000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define CRYPTO_ALG_SUB_TYPE_AEAD_CCM        0x05000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4309    0x06000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define CRYPTO_ALG_SUB_TYPE_CBC_NULL	    0x07000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define CRYPTO_ALG_SUB_TYPE_CTR             0x08000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define CRYPTO_ALG_SUB_TYPE_CTR_RFC3686     0x09000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define CRYPTO_ALG_SUB_TYPE_XTS		    0x0a000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define CRYPTO_ALG_SUB_TYPE_CBC		    0x0b000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define CRYPTO_ALG_SUB_TYPE_CTR_SHA	    0x0c000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define CRYPTO_ALG_SUB_TYPE_CTR_NULL   0x0d000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			      CRYPTO_ALG_SUB_TYPE_HASH_HMAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #define MAX_SCRATCH_PAD_SIZE    32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define CHCR_HASH_MAX_BLOCK_SIZE_64  64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define CHCR_HASH_MAX_BLOCK_SIZE_128 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define CHCR_SRC_SG_SIZE (0x10000 - sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #define CHCR_DST_SG_SIZE 2048
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static inline struct chcr_context *a_ctx(struct crypto_aead *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return crypto_aead_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static inline struct chcr_context *c_ctx(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return crypto_skcipher_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline struct chcr_context *h_ctx(struct crypto_ahash *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return crypto_tfm_ctx(crypto_ahash_tfm(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct ablk_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct crypto_skcipher *sw_cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	__be32 key_ctx_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	unsigned int enckey_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	unsigned char ciph_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	u8 key[CHCR_AES_MAX_KEY_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	u8 nonce[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	u8 rrkey[AES_MAX_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct chcr_aead_reqctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct	sk_buff	*skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	dma_addr_t iv_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	dma_addr_t b0_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned int b0_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	unsigned int op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	u16 imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	u16 verify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	u16 txqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	u16 rxqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	u8 iv[CHCR_MAX_CRYPTO_IV_LEN + MAX_SCRATCH_PAD_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	u8 *scratch_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct ulptx_walk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	struct ulptx_sgl *sgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	unsigned int nents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	unsigned int pair_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	unsigned int last_sg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct scatterlist *last_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct ulptx_sge_pair *pair;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct dsgl_walk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	unsigned int nents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	unsigned int last_sg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct scatterlist *last_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct cpl_rx_phys_dsgl *dsgl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct phys_sge_pairs *to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct chcr_gcm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	u8 ghash_h[AEAD_H_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct chcr_authenc_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	u8 dec_rrkey[AES_MAX_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	u8 h_iopad[2 * CHCR_HASH_MAX_DIGEST_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	unsigned char auth_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct __aead_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct chcr_gcm_ctx gcm[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct chcr_authenc_ctx authenc[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct chcr_aead_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	__be32 key_ctx_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	unsigned int enckey_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct crypto_aead *sw_cipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	u8 salt[MAX_SALT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	u8 key[CHCR_AES_MAX_KEY_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	u8 nonce[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	u16 hmac_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	u16 mayverify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct	__aead_ctx ctx[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct hmac_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct crypto_shash *base_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct __crypto_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct hmac_ctx hmacctx[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct ablk_ctx ablkctx[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct chcr_aead_ctx aeadctx[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct chcr_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct chcr_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	unsigned char rxq_perchan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned char txq_perchan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	unsigned int  ntxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	unsigned int  nrxq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct completion cbc_aes_aio_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct __crypto_ctx crypto_ctx[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct chcr_hctx_per_wr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct scatterlist *srcsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	dma_addr_t dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	u32 dma_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	unsigned int src_ofst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	unsigned int processed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	u32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	u8 is_sg_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	u8 imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/*Final callback called. Driver cannot rely on nbytes to decide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * final call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	u8 isfinal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct chcr_ahash_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct chcr_hctx_per_wr hctx_wr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	u8 *reqbfr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	u8 *skbfr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	/* SKB which is being sent to the hardware for processing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	u64 data_len;  /* Data len till time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	u16 txqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	u16 rxqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	u8 reqlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	u8 bfr1[CHCR_HASH_MAX_BLOCK_SIZE_128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	u8 bfr2[CHCR_HASH_MAX_BLOCK_SIZE_128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct chcr_skcipher_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	struct scatterlist *dstsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	unsigned int processed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	unsigned int last_req_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	unsigned int partial_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct scatterlist *srcsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	unsigned int src_ofst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	unsigned int dst_ofst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	unsigned int op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	u16 imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	u8 init_iv[CHCR_MAX_CRYPTO_IV_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	u16 txqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	u16 rxqidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct skcipher_request fallback_req;	// keep at the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct chcr_alg_template {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	u32 is_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		struct skcipher_alg skcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		struct ahash_alg hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		struct aead_alg aead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	} alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) typedef struct sk_buff *(*create_wr_t)(struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				       unsigned short qid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 				       int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) void chcr_verify_tag(struct aead_request *req, u8 *input, int *err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int chcr_aead_dma_map(struct device *dev, struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		      unsigned short op_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) void chcr_aead_dma_unmap(struct device *dev, struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			 unsigned short op_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) void chcr_add_aead_dst_ent(struct aead_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			   struct cpl_rx_phys_dsgl *phys_cpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			   unsigned short qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) void chcr_add_aead_src_ent(struct aead_request *req, struct ulptx_sgl *ulptx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) void chcr_add_cipher_src_ent(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			     void *ulptx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			     struct  cipher_wr_param *wrparam);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int chcr_cipher_dma_map(struct device *dev, struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) void chcr_cipher_dma_unmap(struct device *dev, struct skcipher_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void chcr_add_cipher_dst_ent(struct skcipher_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			     struct cpl_rx_phys_dsgl *phys_cpl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			     struct  cipher_wr_param *wrparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			     unsigned short qid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int sg_nents_len_skip(struct scatterlist *sg, u64 len, u64 skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) void chcr_add_hash_src_ent(struct ahash_request *req, struct ulptx_sgl *ulptx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			   struct hash_wr_param *param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int chcr_hash_dma_map(struct device *dev, struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) void chcr_hash_dma_unmap(struct device *dev, struct ahash_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void chcr_aead_common_exit(struct aead_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #endif /* __CHCR_CRYPTO_H__ */