]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - drivers/crypto/chelsio/chcr_crypto.h
977d20520f532142b4c0c8dee1f3039ecd5b894d
[mirror_ubuntu-focal-kernel.git] / drivers / crypto / chelsio / chcr_crypto.h
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
39 /* Define following if h/w is not dropping the AAD and IV data before
40 * giving the processed data
41 */
42
43 #define CHCR_CRA_PRIORITY 300
44
45 #define CHCR_AES_MAX_KEY_LEN (2 * (AES_MAX_KEY_SIZE)) /* consider xts */
46 #define CHCR_MAX_CRYPTO_IV_LEN 16 /* AES IV len */
47
48 #define CHCR_MAX_AUTHENC_AES_KEY_LEN 32 /* max aes key length*/
49 #define CHCR_MAX_AUTHENC_SHA_KEY_LEN 128 /* max sha key length*/
50
51 #define CHCR_GIVENCRYPT_OP 2
52 /* CPL/SCMD parameters */
53
54 #define CHCR_ENCRYPT_OP 0
55 #define CHCR_DECRYPT_OP 1
56
57 #define CHCR_SCMD_SEQ_NO_CTRL_32BIT 1
58 #define CHCR_SCMD_SEQ_NO_CTRL_48BIT 2
59 #define CHCR_SCMD_SEQ_NO_CTRL_64BIT 3
60
61 #define CHCR_SCMD_PROTO_VERSION_GENERIC 4
62
63 #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
64 #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
65
66 #define CHCR_SCMD_CIPHER_MODE_NOP 0
67 #define CHCR_SCMD_CIPHER_MODE_AES_CBC 1
68 #define CHCR_SCMD_CIPHER_MODE_GENERIC_AES 4
69 #define CHCR_SCMD_CIPHER_MODE_AES_XTS 6
70
71 #define CHCR_SCMD_AUTH_MODE_NOP 0
72 #define CHCR_SCMD_AUTH_MODE_SHA1 1
73 #define CHCR_SCMD_AUTH_MODE_SHA224 2
74 #define CHCR_SCMD_AUTH_MODE_SHA256 3
75 #define CHCR_SCMD_AUTH_MODE_SHA512_224 5
76 #define CHCR_SCMD_AUTH_MODE_SHA512_256 6
77 #define CHCR_SCMD_AUTH_MODE_SHA512_384 7
78 #define CHCR_SCMD_AUTH_MODE_SHA512_512 8
79
80 #define CHCR_SCMD_HMAC_CTRL_NOP 0
81 #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1
82
83 #define CHCR_SCMD_IVGEN_CTRL_HW 0
84 #define CHCR_SCMD_IVGEN_CTRL_SW 1
85 /* This are not really mac key size. They are intermediate values
86 * of sha engine and its size
87 */
88 #define CHCR_KEYCTX_MAC_KEY_SIZE_128 0
89 #define CHCR_KEYCTX_MAC_KEY_SIZE_160 1
90 #define CHCR_KEYCTX_MAC_KEY_SIZE_192 2
91 #define CHCR_KEYCTX_MAC_KEY_SIZE_256 3
92 #define CHCR_KEYCTX_MAC_KEY_SIZE_512 4
93 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_128 0
94 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_192 1
95 #define CHCR_KEYCTX_CIPHER_KEY_SIZE_256 2
96 #define CHCR_KEYCTX_NO_KEY 15
97
98 #define CHCR_CPL_FW4_PLD_IV_OFFSET (5 * 64) /* bytes. flt #5 and #6 */
99 #define CHCR_CPL_FW4_PLD_HASH_RESULT_OFFSET (7 * 64) /* bytes. flt #7 */
100 #define CHCR_CPL_FW4_PLD_DATA_SIZE (4 * 64) /* bytes. flt #4 to #7 */
101
102 #define KEY_CONTEXT_HDR_SALT_AND_PAD 16
103 #define flits_to_bytes(x) (x * 8)
104
105 #define IV_NOP 0
106 #define IV_IMMEDIATE 1
107 #define IV_DSGL 2
108
109 #define CRYPTO_ALG_SUB_TYPE_MASK 0x0f000000
110 #define CRYPTO_ALG_SUB_TYPE_HASH_HMAC 0x01000000
111 #define CRYPTO_ALG_TYPE_HMAC (CRYPTO_ALG_TYPE_AHASH |\
112 CRYPTO_ALG_SUB_TYPE_HASH_HMAC)
113
114 #define MAX_SALT 4
115 #define MAX_SCRATCH_PAD_SIZE 32
116
117 #define CHCR_HASH_MAX_BLOCK_SIZE_64 64
118 #define CHCR_HASH_MAX_BLOCK_SIZE_128 128
119
120 /* Aligned to 128 bit boundary */
121
122 struct ablk_ctx {
123 u8 enc;
124 unsigned int processed_len;
125 __be32 key_ctx_hdr;
126 unsigned int enckey_len;
127 unsigned int dst_nents;
128 u8 key[CHCR_AES_MAX_KEY_LEN];
129 u8 rrkey[AES_MAX_KEY_SIZE];
130 u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
131 unsigned char ciph_mode;
132 };
133
134 struct hmac_ctx {
135 struct crypto_shash *base_hash;
136 u8 ipad[CHCR_HASH_MAX_BLOCK_SIZE_128];
137 u8 opad[CHCR_HASH_MAX_BLOCK_SIZE_128];
138 };
139
140 struct __crypto_ctx {
141 struct hmac_ctx hmacctx[0];
142 struct ablk_ctx ablkctx[0];
143 };
144
145 struct chcr_context {
146 struct chcr_dev *dev;
147 unsigned char tx_channel_id;
148 struct __crypto_ctx crypto_ctx[0];
149 };
150
151 struct chcr_ahash_req_ctx {
152 u32 result;
153 u8 bfr1[CHCR_HASH_MAX_BLOCK_SIZE_128];
154 u8 bfr2[CHCR_HASH_MAX_BLOCK_SIZE_128];
155 u8 *reqbfr;
156 u8 *skbfr;
157 u8 reqlen;
158 /* DMA the partial hash in it */
159 u8 partial_hash[CHCR_HASH_MAX_DIGEST_SIZE];
160 u64 data_len; /* Data len till time */
161 /* SKB which is being sent to the hardware for processing */
162 struct sk_buff *skb;
163 };
164
165 struct chcr_blkcipher_req_ctx {
166 struct sk_buff *skb;
167 };
168
169 struct chcr_alg_template {
170 u32 type;
171 u32 is_registered;
172 union {
173 struct crypto_alg crypto;
174 struct ahash_alg hash;
175 } alg;
176 };
177
178 struct chcr_req_ctx {
179 union {
180 struct ahash_request *ahash_req;
181 struct ablkcipher_request *ablk_req;
182 } req;
183 union {
184 struct chcr_ahash_req_ctx *ahash_ctx;
185 struct chcr_blkcipher_req_ctx *ablk_ctx;
186 } ctx;
187 };
188
189 struct sge_opaque_hdr {
190 void *dev;
191 dma_addr_t addr[MAX_SKB_FRAGS + 1];
192 };
193
194 typedef struct sk_buff *(*create_wr_t)(struct crypto_async_request *req,
195 struct chcr_context *ctx,
196 unsigned short qid,
197 unsigned short op_type);
198
199 #endif /* __CHCR_CRYPTO_H__ */