Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Chelsio T6 Crypto driver for Linux. |
| 3 | * |
| 4 | * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved. |
| 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #ifndef __CHCR_CRYPTO_H__ |
| 37 | #define __CHCR_CRYPTO_H__ |
| 38 | |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 39 | #define GHASH_BLOCK_SIZE 16 |
| 40 | #define GHASH_DIGEST_SIZE 16 |
| 41 | |
| 42 | #define CCM_B0_SIZE 16 |
| 43 | #define CCM_AAD_FIELD_SIZE 2 |
| 44 | #define T5_MAX_AAD_SIZE 512 |
| 45 | |
| 46 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 47 | /* Define following if h/w is not dropping the AAD and IV data before |
| 48 | * giving the processed data |
| 49 | */ |
| 50 | |
Harsh Jain | 8f06601 | 2017-01-27 16:09:10 +0530 | [diff] [blame] | 51 | #define CHCR_CRA_PRIORITY 3000 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 52 | |
| 53 | #define CHCR_AES_MAX_KEY_LEN (2 * (AES_MAX_KEY_SIZE)) /* consider xts */ |
| 54 | #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */ |
| 55 | |
| 56 | #define CHCR_MAX_AUTHENC_AES_KEY_LEN 32 /* max aes key length*/ |
| 57 | #define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128 /* max sha key length*/ |
| 58 | |
| 59 | #define CHCR_GIVENCRYPT_OP 2 |
| 60 | /* CPL/SCMD parameters */ |
| 61 | |
| 62 | #define CHCR_ENCRYPT_OP 0 |
| 63 | #define CHCR_DECRYPT_OP 1 |
| 64 | |
| 65 | #define CHCR_SCMD_SEQ_NO_CTRL_32BIT 1 |
| 66 | #define CHCR_SCMD_SEQ_NO_CTRL_48BIT 2 |
| 67 | #define CHCR_SCMD_SEQ_NO_CTRL_64BIT 3 |
| 68 | |
| 69 | #define CHCR_SCMD_PROTO_VERSION_GENERIC 4 |
| 70 | |
| 71 | #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0 |
| 72 | #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1 |
| 73 | |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 74 | #define CHCR_SCMD_CIPHER_MODE_NOP 0 |
| 75 | #define CHCR_SCMD_CIPHER_MODE_AES_CBC 1 |
| 76 | #define CHCR_SCMD_CIPHER_MODE_AES_GCM 2 |
| 77 | #define CHCR_SCMD_CIPHER_MODE_AES_CTR 3 |
| 78 | #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4 |
| 79 | #define CHCR_SCMD_CIPHER_MODE_AES_XTS 6 |
| 80 | #define CHCR_SCMD_CIPHER_MODE_AES_CCM 7 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 81 | |
| 82 | #define CHCR_SCMD_AUTH_MODE_NOP 0 |
| 83 | #define CHCR_SCMD_AUTH_MODE_SHA1 1 |
| 84 | #define CHCR_SCMD_AUTH_MODE_SHA224 2 |
| 85 | #define CHCR_SCMD_AUTH_MODE_SHA256 3 |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 86 | #define CHCR_SCMD_AUTH_MODE_GHASH 4 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 87 | #define CHCR_SCMD_AUTH_MODE_SHA512_224 5 |
| 88 | #define CHCR_SCMD_AUTH_MODE_SHA512_256 6 |
| 89 | #define CHCR_SCMD_AUTH_MODE_SHA512_384 7 |
| 90 | #define CHCR_SCMD_AUTH_MODE_SHA512_512 8 |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 91 | #define CHCR_SCMD_AUTH_MODE_CBCMAC 9 |
| 92 | #define CHCR_SCMD_AUTH_MODE_CMAC 10 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 93 | |
| 94 | #define CHCR_SCMD_HMAC_CTRL_NOP 0 |
| 95 | #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1 |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 96 | #define CHCR_SCMD_HMAC_CTRL_TRUNC_RFC4366 2 |
| 97 | #define CHCR_SCMD_HMAC_CTRL_IPSEC_96BIT 3 |
| 98 | #define CHCR_SCMD_HMAC_CTRL_PL1 4 |
| 99 | #define CHCR_SCMD_HMAC_CTRL_PL2 5 |
| 100 | #define CHCR_SCMD_HMAC_CTRL_PL3 6 |
| 101 | #define CHCR_SCMD_HMAC_CTRL_DIV2 7 |
| 102 | #define VERIFY_HW 0 |
| 103 | #define VERIFY_SW 1 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 104 | |
| 105 | #define CHCR_SCMD_IVGEN_CTRL_HW 0 |
| 106 | #define CHCR_SCMD_IVGEN_CTRL_SW 1 |
| 107 | /* This are not really mac key size. They are intermediate values |
| 108 | * of sha engine and its size |
| 109 | */ |
| 110 | #define CHCR_KEYCTX_MAC_KEY_SIZE_128 0 |
| 111 | #define CHCR_KEYCTX_MAC_KEY_SIZE_160 1 |
| 112 | #define CHCR_KEYCTX_MAC_KEY_SIZE_192 2 |
| 113 | #define CHCR_KEYCTX_MAC_KEY_SIZE_256 3 |
| 114 | #define CHCR_KEYCTX_MAC_KEY_SIZE_512 4 |
| 115 | #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0 |
| 116 | #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1 |
| 117 | #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2 |
| 118 | #define CHCR_KEYCTX_NO_KEY 15 |
| 119 | |
| 120 | #define CHCR_CPL_FW4_PLD_IV_OFFSET (5 * 64) /* bytes. flt #5 and #6 */ |
| 121 | #define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64) /* bytes. flt #7 */ |
| 122 | #define CHCR_CPL_FW4_PLD_DATA_SIZE (4 * 64) /* bytes. flt #4 to #7 */ |
| 123 | |
| 124 | #define KEY_CONTEXT_HDR_SALT_AND_PAD 16 |
| 125 | #define flits_to_bytes(x) (x * 8) |
| 126 | |
| 127 | #define IV_NOP 0 |
| 128 | #define IV_IMMEDIATE 1 |
| 129 | #define IV_DSGL 2 |
| 130 | |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 131 | #define AEAD_H_SIZE 16 |
| 132 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 133 | #define CRYPTO_ALG_SUB_TYPE_MASK 0x0f000000 |
| 134 | #define CRYPTO_ALG_SUB_TYPE_HASH_HMAC 0x01000000 |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 135 | #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4106 0x02000000 |
| 136 | #define CRYPTO_ALG_SUB_TYPE_AEAD_GCM 0x03000000 |
| 137 | #define CRYPTO_ALG_SUB_TYPE_AEAD_AUTHENC 0x04000000 |
| 138 | #define CRYPTO_ALG_SUB_TYPE_AEAD_CCM 0x05000000 |
| 139 | #define CRYPTO_ALG_SUB_TYPE_AEAD_RFC4309 0x06000000 |
| 140 | #define CRYPTO_ALG_SUB_TYPE_AEAD_NULL 0x07000000 |
| 141 | #define CRYPTO_ALG_SUB_TYPE_CTR 0x08000000 |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 142 | #define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\ |
| 143 | CRYPTO_ALG_SUB_TYPE_HASH_HMAC) |
| 144 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 145 | #define MAX_SCRATCH_PAD_SIZE 32 |
| 146 | |
| 147 | #define CHCR_HASH_MAX_BLOCK_SIZE_64 64 |
| 148 | #define CHCR_HASH_MAX_BLOCK_SIZE_128 128 |
| 149 | |
| 150 | /* Aligned to 128 bit boundary */ |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 151 | |
| 152 | struct ablk_ctx { |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 153 | __be32 key_ctx_hdr; |
| 154 | unsigned int enckey_len; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 155 | u8 key[CHCR_AES_MAX_KEY_LEN]; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 156 | unsigned char ciph_mode; |
Harsh Jain | 5c86a8f | 2016-11-29 19:00:42 +0530 | [diff] [blame] | 157 | u8 rrkey[AES_MAX_KEY_SIZE]; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 158 | }; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 159 | struct chcr_aead_reqctx { |
| 160 | struct sk_buff *skb; |
Harsh Jain | 94e1dab | 2017-01-24 10:34:32 +0530 | [diff] [blame] | 161 | struct scatterlist *dst; |
| 162 | struct scatterlist srcffwd[2]; |
| 163 | struct scatterlist dstffwd[2]; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 164 | short int dst_nents; |
| 165 | u16 verify; |
| 166 | u8 iv[CHCR_MAX_CRYPTO_IV_LEN]; |
| 167 | unsigned char scratch_pad[MAX_SCRATCH_PAD_SIZE]; |
| 168 | }; |
| 169 | |
| 170 | struct chcr_gcm_ctx { |
| 171 | u8 ghash_h[AEAD_H_SIZE]; |
| 172 | }; |
| 173 | |
| 174 | struct chcr_authenc_ctx { |
| 175 | u8 dec_rrkey[AES_MAX_KEY_SIZE]; |
| 176 | u8 h_iopad[2 * CHCR_HASH_MAX_DIGEST_SIZE]; |
| 177 | unsigned char auth_mode; |
| 178 | }; |
| 179 | |
| 180 | struct __aead_ctx { |
| 181 | struct chcr_gcm_ctx gcm[0]; |
| 182 | struct chcr_authenc_ctx authenc[0]; |
| 183 | }; |
| 184 | |
| 185 | |
| 186 | |
| 187 | struct chcr_aead_ctx { |
| 188 | __be32 key_ctx_hdr; |
| 189 | unsigned int enckey_len; |
| 190 | struct crypto_skcipher *null; |
| 191 | u8 salt[MAX_SALT]; |
| 192 | u8 key[CHCR_AES_MAX_KEY_LEN]; |
| 193 | u16 hmac_ctrl; |
| 194 | u16 mayverify; |
| 195 | struct __aead_ctx ctx[0]; |
| 196 | }; |
| 197 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 198 | |
Harsh Jain | 5c86a8f | 2016-11-29 19:00:42 +0530 | [diff] [blame] | 199 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 200 | struct hmac_ctx { |
Harsh Jain | e792272 | 2016-11-29 19:00:41 +0530 | [diff] [blame] | 201 | struct crypto_shash *base_hash; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 202 | u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128]; |
| 203 | u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128]; |
| 204 | }; |
| 205 | |
| 206 | struct __crypto_ctx { |
| 207 | struct hmac_ctx hmacctx[0]; |
| 208 | struct ablk_ctx ablkctx[0]; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 209 | struct chcr_aead_ctx aeadctx[0]; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | struct chcr_context { |
| 213 | struct chcr_dev *dev; |
| 214 | unsigned char tx_channel_id; |
| 215 | struct __crypto_ctx crypto_ctx[0]; |
| 216 | }; |
| 217 | |
| 218 | struct chcr_ahash_req_ctx { |
| 219 | u32 result; |
Harsh Jain | 44fce12 | 2016-11-29 19:00:38 +0530 | [diff] [blame] | 220 | u8 bfr1[CHCR_HASH_MAX_BLOCK_SIZE_128]; |
| 221 | u8 bfr2[CHCR_HASH_MAX_BLOCK_SIZE_128]; |
| 222 | u8 *reqbfr; |
| 223 | u8 *skbfr; |
| 224 | u8 reqlen; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 225 | /* DMA the partial hash in it */ |
| 226 | u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE]; |
| 227 | u64 data_len; /* Data len till time */ |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 228 | /* SKB which is being sent to the hardware for processing */ |
| 229 | struct sk_buff *skb; |
| 230 | }; |
| 231 | |
| 232 | struct chcr_blkcipher_req_ctx { |
| 233 | struct sk_buff *skb; |
Harsh Jain | 5c86a8f | 2016-11-29 19:00:42 +0530 | [diff] [blame] | 234 | unsigned int dst_nents; |
| 235 | u8 iv[CHCR_MAX_CRYPTO_IV_LEN]; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | struct chcr_alg_template { |
| 239 | u32 type; |
| 240 | u32 is_registered; |
| 241 | union { |
| 242 | struct crypto_alg crypto; |
| 243 | struct ahash_alg hash; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 244 | struct aead_alg aead; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 245 | } alg; |
| 246 | }; |
| 247 | |
| 248 | struct chcr_req_ctx { |
| 249 | union { |
| 250 | struct ahash_request *ahash_req; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 251 | struct aead_request *aead_req; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 252 | struct ablkcipher_request *ablk_req; |
| 253 | } req; |
| 254 | union { |
| 255 | struct chcr_ahash_req_ctx *ahash_ctx; |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 256 | struct chcr_aead_reqctx *reqctx; |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 257 | struct chcr_blkcipher_req_ctx *ablk_ctx; |
| 258 | } ctx; |
| 259 | }; |
| 260 | |
| 261 | struct sge_opaque_hdr { |
| 262 | void *dev; |
| 263 | dma_addr_t addr[MAX_SKB_FRAGS + 1]; |
| 264 | }; |
| 265 | |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 266 | typedef struct sk_buff *(*create_wr_t)(struct aead_request *req, |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 267 | unsigned short qid, |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 268 | int size, |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 269 | unsigned short op_type); |
| 270 | |
Harsh Jain | 2debd33 | 2016-11-29 19:00:43 +0530 | [diff] [blame] | 271 | static int chcr_aead_op(struct aead_request *req_base, |
| 272 | unsigned short op_type, |
| 273 | int size, |
| 274 | create_wr_t create_wr_fn); |
| 275 | static inline int get_aead_subtype(struct crypto_aead *aead); |
| 276 | |
Hariprasad Shenai | 324429d | 2016-08-17 12:33:05 +0530 | [diff] [blame] | 277 | #endif /* __CHCR_CRYPTO_H__ */ |