2 * This file is part of the Chelsio T6 Crypto driver for Linux.
4 * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
36 #ifndef __CHCR_CRYPTO_H__
37 #define __CHCR_CRYPTO_H__
39 /* Define following if h/w is not dropping the AAD and IV data before
40 * giving the processed data
43 #define CHCR_CRA_PRIORITY 300
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 */
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*/
51 #define CHCR_GIVENCRYPT_OP 2
52 /* CPL/SCMD parameters */
54 #define CHCR_ENCRYPT_OP 0
55 #define CHCR_DECRYPT_OP 1
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
61 #define CHCR_SCMD_PROTO_VERSION_GENERIC 4
63 #define CHCR_SCMD_AUTH_CTRL_AUTH_CIPHER 0
64 #define CHCR_SCMD_AUTH_CTRL_CIPHER_AUTH 1
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
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
80 #define CHCR_SCMD_HMAC_CTRL_NOP 0
81 #define CHCR_SCMD_HMAC_CTRL_NO_TRUNC 1
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
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
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 */
102 #define KEY_CONTEXT_HDR_SALT_AND_PAD 16
103 #define flits_to_bytes(x) (x * 8)
106 #define IV_IMMEDIATE 1
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)
115 #define MAX_SCRATCH_PAD_SIZE 32
117 #define CHCR_HASH_MAX_BLOCK_SIZE_64 64
118 #define CHCR_HASH_MAX_BLOCK_SIZE_128 128
120 /* Aligned to 128 bit boundary */
124 unsigned int processed_len
;
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
;
135 struct crypto_shash
*base_hash
;
136 u8 ipad
[CHCR_HASH_MAX_BLOCK_SIZE_128
];
137 u8 opad
[CHCR_HASH_MAX_BLOCK_SIZE_128
];
140 struct __crypto_ctx
{
141 struct hmac_ctx hmacctx
[0];
142 struct ablk_ctx ablkctx
[0];
145 struct chcr_context
{
146 struct chcr_dev
*dev
;
147 unsigned char tx_channel_id
;
148 struct __crypto_ctx crypto_ctx
[0];
151 struct chcr_ahash_req_ctx
{
153 u8 bfr1
[CHCR_HASH_MAX_BLOCK_SIZE_128
];
154 u8 bfr2
[CHCR_HASH_MAX_BLOCK_SIZE_128
];
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 */
165 struct chcr_blkcipher_req_ctx
{
169 struct chcr_alg_template
{
173 struct crypto_alg crypto
;
174 struct ahash_alg hash
;
178 struct chcr_req_ctx
{
180 struct ahash_request
*ahash_req
;
181 struct ablkcipher_request
*ablk_req
;
184 struct chcr_ahash_req_ctx
*ahash_ctx
;
185 struct chcr_blkcipher_req_ctx
*ablk_ctx
;
189 struct sge_opaque_hdr
{
191 dma_addr_t addr
[MAX_SKB_FRAGS
+ 1];
194 typedef struct sk_buff
*(*create_wr_t
)(struct crypto_async_request
*req
,
195 struct chcr_context
*ctx
,
197 unsigned short op_type
);
199 #endif /* __CHCR_CRYPTO_H__ */