xref: /freebsd/sys/dev/qat/include/icp_qat_hw.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1*78ee8d1cSJulian Grajkowski /* SPDX-License-Identifier: BSD-3-Clause */
2*78ee8d1cSJulian Grajkowski /* Copyright(c) 2007-2022 Intel Corporation */
3*78ee8d1cSJulian Grajkowski #ifndef _ICP_QAT_HW_H_
4*78ee8d1cSJulian Grajkowski #define _ICP_QAT_HW_H_
5*78ee8d1cSJulian Grajkowski 
6*78ee8d1cSJulian Grajkowski enum icp_qat_hw_ae_id {
7*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_0 = 0,
8*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_1 = 1,
9*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_2 = 2,
10*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_3 = 3,
11*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_4 = 4,
12*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_5 = 5,
13*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_6 = 6,
14*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_7 = 7,
15*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_8 = 8,
16*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_9 = 9,
17*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_10 = 10,
18*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_11 = 11,
19*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AE_DELIMITER = 12
20*78ee8d1cSJulian Grajkowski };
21*78ee8d1cSJulian Grajkowski 
22*78ee8d1cSJulian Grajkowski enum icp_qat_hw_qat_id {
23*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_0 = 0,
24*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_1 = 1,
25*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_2 = 2,
26*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_3 = 3,
27*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_4 = 4,
28*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_5 = 5,
29*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_QAT_DELIMITER = 6
30*78ee8d1cSJulian Grajkowski };
31*78ee8d1cSJulian Grajkowski 
32*78ee8d1cSJulian Grajkowski enum icp_qat_hw_auth_algo {
33*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_NULL = 0,
34*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA1 = 1,
35*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_MD5 = 2,
36*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA224 = 3,
37*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA256 = 4,
38*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA384 = 5,
39*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA512 = 6,
40*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC = 7,
41*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC = 8,
42*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_AES_F9 = 9,
43*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_GALOIS_128 = 10,
44*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_GALOIS_64 = 11,
45*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 = 12,
46*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 = 13,
47*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3 = 14,
48*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_RESERVED_1 = 15,
49*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_RESERVED_2 = 16,
50*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA3_256 = 17,
51*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_RESERVED_3 = 18,
52*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_SHA3_512 = 19,
53*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_ALGO_DELIMITER = 20
54*78ee8d1cSJulian Grajkowski };
55*78ee8d1cSJulian Grajkowski 
56*78ee8d1cSJulian Grajkowski enum icp_qat_hw_auth_mode {
57*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_MODE0 = 0,
58*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_MODE1 = 1,
59*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_MODE2 = 2,
60*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_AUTH_MODE_DELIMITER = 3
61*78ee8d1cSJulian Grajkowski };
62*78ee8d1cSJulian Grajkowski 
63*78ee8d1cSJulian Grajkowski struct icp_qat_hw_auth_config {
64*78ee8d1cSJulian Grajkowski 	uint32_t config;
65*78ee8d1cSJulian Grajkowski 	uint32_t reserved;
66*78ee8d1cSJulian Grajkowski };
67*78ee8d1cSJulian Grajkowski enum icp_qat_slice_mask {
68*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_CIPHER_SLICE = 0x01,
69*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_AUTH_SLICE = 0x02,
70*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_PKE_SLICE = 0x04,
71*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_COMPRESS_SLICE = 0x08,
72*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_DEPRECATED = 0x10,
73*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_EIA3_SLICE = 0x20,
74*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_SHA3_SLICE = 0x40,
75*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_CRYPTO0_SLICE = 0x80,
76*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_CRYPTO1_SLICE = 0x100,
77*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_CRYPTO2_SLICE = 0x200,
78*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_SM3_SLICE = 0x400,
79*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_MASK_SM4_SLICE = 0x800
80*78ee8d1cSJulian Grajkowski };
81*78ee8d1cSJulian Grajkowski 
82*78ee8d1cSJulian Grajkowski enum icp_qat_capabilities_mask {
83*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC = BIT(0),
84*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC = BIT(1),
85*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CIPHER = BIT(2),
86*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_AUTHENTICATION = BIT(3),
87*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_RESERVED_1 = BIT(4),
88*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_COMPRESSION = BIT(5),
89*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_DEPRECATED = BIT(6),
90*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_RAND = BIT(7),
91*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_ZUC = BIT(8),
92*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_SHA3 = BIT(9),
93*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_KPT = BIT(10),
94*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_RL = BIT(11),
95*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_HKDF = BIT(12),
96*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_ECEDMONT = BIT(13),
97*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_EXT_ALGCHAIN = BIT(14),
98*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_SHA3_EXT = BIT(15),
99*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_AESGCM_SPC = BIT(16),
100*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CHACHA_POLY = BIT(17),
101*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_SM2 = BIT(18),
102*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_SM3 = BIT(19),
103*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_SM4 = BIT(20),
104*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_INLINE = BIT(21),
105*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CNV_INTEGRITY = BIT(22),
106*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_CNV_INTEGRITY64 = BIT(23),
107*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_LZ4_COMPRESSION = BIT(24),
108*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_LZ4S_COMPRESSION = BIT(25),
109*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_AES_V2 = BIT(26),
110*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_KPT2 = BIT(27),
111*78ee8d1cSJulian Grajkowski };
112*78ee8d1cSJulian Grajkowski 
113*78ee8d1cSJulian Grajkowski enum icp_qat_extended_dc_capabilities_mask {
114*78ee8d1cSJulian Grajkowski 	ICP_ACCEL_CAPABILITIES_ADVANCED_COMPRESSION = 0x101
115*78ee8d1cSJulian Grajkowski };
116*78ee8d1cSJulian Grajkowski 
117*78ee8d1cSJulian Grajkowski #define QAT_AUTH_MODE_BITPOS 4
118*78ee8d1cSJulian Grajkowski #define QAT_AUTH_MODE_MASK 0xF
119*78ee8d1cSJulian Grajkowski #define QAT_AUTH_ALGO_BITPOS 0
120*78ee8d1cSJulian Grajkowski #define QAT_AUTH_ALGO_MASK 0xF
121*78ee8d1cSJulian Grajkowski #define QAT_AUTH_CMP_BITPOS 8
122*78ee8d1cSJulian Grajkowski #define QAT_AUTH_HIGH_BIT 4
123*78ee8d1cSJulian Grajkowski #define QAT_AUTH_CMP_MASK 0x7F
124*78ee8d1cSJulian Grajkowski #define QAT_AUTH_SHA3_PADDING_BITPOS 16
125*78ee8d1cSJulian Grajkowski #define QAT_AUTH_SHA3_PADDING_MASK 0x1
126*78ee8d1cSJulian Grajkowski #define QAT_AUTH_ALGO_SHA3_BITPOS 22
127*78ee8d1cSJulian Grajkowski #define QAT_AUTH_ALGO_SHA3_MASK 0x3
128*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AUTH_CONFIG_BUILD(mode, algo, cmp_len)                      \
129*78ee8d1cSJulian Grajkowski 	(((mode & QAT_AUTH_MODE_MASK) << QAT_AUTH_MODE_BITPOS) |               \
130*78ee8d1cSJulian Grajkowski 	 ((algo & QAT_AUTH_ALGO_MASK) << QAT_AUTH_ALGO_BITPOS) |               \
131*78ee8d1cSJulian Grajkowski 	 (((algo >> 4) & QAT_AUTH_ALGO_SHA3_MASK)                              \
132*78ee8d1cSJulian Grajkowski 	  << QAT_AUTH_ALGO_SHA3_BITPOS) |                                      \
133*78ee8d1cSJulian Grajkowski 	 (((((algo == ICP_QAT_HW_AUTH_ALGO_SHA3_256) ||                        \
134*78ee8d1cSJulian Grajkowski 	     (algo == ICP_QAT_HW_AUTH_ALGO_SHA3_512)) ?                        \
135*78ee8d1cSJulian Grajkowski 		1 :                                                            \
136*78ee8d1cSJulian Grajkowski 		0) &                                                           \
137*78ee8d1cSJulian Grajkowski 	   QAT_AUTH_SHA3_PADDING_MASK)                                         \
138*78ee8d1cSJulian Grajkowski 	  << QAT_AUTH_SHA3_PADDING_BITPOS) |                                   \
139*78ee8d1cSJulian Grajkowski 	 ((cmp_len & QAT_AUTH_CMP_MASK) << QAT_AUTH_CMP_BITPOS))
140*78ee8d1cSJulian Grajkowski 
141*78ee8d1cSJulian Grajkowski struct icp_qat_hw_auth_counter {
142*78ee8d1cSJulian Grajkowski 	__be32 counter;
143*78ee8d1cSJulian Grajkowski 	uint32_t reserved;
144*78ee8d1cSJulian Grajkowski };
145*78ee8d1cSJulian Grajkowski 
146*78ee8d1cSJulian Grajkowski #define QAT_AUTH_COUNT_MASK 0xFFFFFFFF
147*78ee8d1cSJulian Grajkowski #define QAT_AUTH_COUNT_BITPOS 0
148*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AUTH_COUNT_BUILD(val)                                       \
149*78ee8d1cSJulian Grajkowski 	(((val)&QAT_AUTH_COUNT_MASK) << QAT_AUTH_COUNT_BITPOS)
150*78ee8d1cSJulian Grajkowski 
151*78ee8d1cSJulian Grajkowski struct icp_qat_hw_auth_setup {
152*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_auth_config auth_config;
153*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_auth_counter auth_counter;
154*78ee8d1cSJulian Grajkowski };
155*78ee8d1cSJulian Grajkowski 
156*78ee8d1cSJulian Grajkowski #define QAT_HW_DEFAULT_ALIGNMENT 8
157*78ee8d1cSJulian Grajkowski #define QAT_HW_ROUND_UP(val, n) (((val) + ((n)-1)) & (~(n - 1)))
158*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_NULL_STATE1_SZ 32
159*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_MD5_STATE1_SZ 16
160*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA1_STATE1_SZ 20
161*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA224_STATE1_SZ 32
162*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA256_STATE1_SZ 32
163*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_256_STATE1_SZ 32
164*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA384_STATE1_SZ 64
165*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA512_STATE1_SZ 64
166*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_512_STATE1_SZ 64
167*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_224_STATE1_SZ 28
168*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_384_STATE1_SZ 48
169*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_XCBC_MAC_STATE1_SZ 16
170*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ 16
171*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_F9_STATE1_SZ 32
172*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_KASUMI_F9_STATE1_SZ 16
173*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_128_STATE1_SZ 16
174*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SNOW_3G_UIA2_STATE1_SZ 8
175*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ZUC_3G_EIA3_STATE1_SZ 8
176*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_NULL_STATE2_SZ 32
177*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_MD5_STATE2_SZ 16
178*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA1_STATE2_SZ 20
179*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA224_STATE2_SZ 32
180*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA256_STATE2_SZ 32
181*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_256_STATE2_SZ 0
182*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA384_STATE2_SZ 64
183*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA512_STATE2_SZ 64
184*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_512_STATE2_SZ 0
185*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_224_STATE2_SZ 0
186*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SHA3_384_STATE2_SZ 0
187*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_XCBC_MAC_KEY_SZ 16
188*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_CBC_MAC_KEY_SZ 16
189*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_CCM_CBC_E_CTR0_SZ 16
190*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_F9_IK_SZ 16
191*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_F9_FK_SZ 16
192*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_KASUMI_F9_STATE2_SZ                                         \
193*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_F9_IK_SZ + ICP_QAT_HW_F9_FK_SZ)
194*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_F9_STATE2_SZ ICP_QAT_HW_KASUMI_F9_STATE2_SZ
195*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SNOW_3G_UIA2_STATE2_SZ 24
196*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ZUC_3G_EIA3_STATE2_SZ 32
197*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_H_SZ 16
198*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_LEN_A_SZ 8
199*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_E_CTR0_SZ 16
200*78ee8d1cSJulian Grajkowski 
201*78ee8d1cSJulian Grajkowski struct icp_qat_hw_auth_sha512 {
202*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_auth_setup inner_setup;
203*78ee8d1cSJulian Grajkowski 	uint8_t state1[ICP_QAT_HW_SHA512_STATE1_SZ];
204*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_auth_setup outer_setup;
205*78ee8d1cSJulian Grajkowski 	uint8_t state2[ICP_QAT_HW_SHA512_STATE2_SZ];
206*78ee8d1cSJulian Grajkowski };
207*78ee8d1cSJulian Grajkowski 
208*78ee8d1cSJulian Grajkowski struct icp_qat_hw_auth_algo_blk {
209*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_auth_sha512 sha;
210*78ee8d1cSJulian Grajkowski };
211*78ee8d1cSJulian Grajkowski 
212*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_LEN_A_BITPOS 0
213*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_GALOIS_LEN_A_MASK 0xFFFFFFFF
214*78ee8d1cSJulian Grajkowski 
215*78ee8d1cSJulian Grajkowski enum icp_qat_hw_cipher_algo {
216*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_NULL = 0,
217*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_DES = 1,
218*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_3DES = 2,
219*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_AES128 = 3,
220*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_AES192 = 4,
221*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_AES256 = 5,
222*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_ARC4 = 6,
223*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_KASUMI = 7,
224*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 = 8,
225*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3 = 9,
226*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_SM4 = 10,
227*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ALGO_CHACHA20_POLY1305 = 11,
228*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_DELIMITER = 12
229*78ee8d1cSJulian Grajkowski };
230*78ee8d1cSJulian Grajkowski 
231*78ee8d1cSJulian Grajkowski enum icp_qat_hw_cipher_mode {
232*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ECB_MODE = 0,
233*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_CBC_MODE = 1,
234*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_CTR_MODE = 2,
235*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_F8_MODE = 3,
236*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_AEAD_MODE = 4,
237*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_RESERVED_MODE = 5,
238*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_XTS_MODE = 6,
239*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_MODE_DELIMITER = 7
240*78ee8d1cSJulian Grajkowski };
241*78ee8d1cSJulian Grajkowski 
242*78ee8d1cSJulian Grajkowski struct icp_qat_hw_cipher_config {
243*78ee8d1cSJulian Grajkowski 	uint32_t val;
244*78ee8d1cSJulian Grajkowski 	uint32_t reserved;
245*78ee8d1cSJulian Grajkowski };
246*78ee8d1cSJulian Grajkowski 
247*78ee8d1cSJulian Grajkowski enum icp_qat_hw_cipher_dir {
248*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_ENCRYPT = 0,
249*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_DECRYPT = 1,
250*78ee8d1cSJulian Grajkowski };
251*78ee8d1cSJulian Grajkowski 
252*78ee8d1cSJulian Grajkowski enum icp_qat_hw_cipher_convert {
253*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_NO_CONVERT = 0,
254*78ee8d1cSJulian Grajkowski 	ICP_QAT_HW_CIPHER_KEY_CONVERT = 1,
255*78ee8d1cSJulian Grajkowski };
256*78ee8d1cSJulian Grajkowski 
257*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_MODE_BITPOS 4
258*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_MODE_MASK 0xF
259*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_ALGO_BITPOS 0
260*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_ALGO_MASK 0xF
261*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_CONVERT_BITPOS 9
262*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_CONVERT_MASK 0x1
263*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_DIR_BITPOS 8
264*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_DIR_MASK 0x1
265*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_HASH_CMP_LEN_MASK 0x1F
266*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_HASH_CMP_LEN_BITPOS 10
267*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_AAD_SIZE_LOWER_MASK 0xFF
268*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_AAD_SIZE_UPPER_MASK 0x3F
269*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_AAD_UPPER_SHIFT 8
270*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_AAD_LOWER_SHIFT 24
271*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_AEAD_AAD_SIZE_BITPOS 16
272*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_MODE_F8_KEY_SZ_MULT 2
273*78ee8d1cSJulian Grajkowski #define QAT_CIPHER_MODE_XTS_KEY_SZ_MULT 2
274*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_CIPHER_CONFIG_BUILD(mode, algo, convert, dir)               \
275*78ee8d1cSJulian Grajkowski 	(((mode & QAT_CIPHER_MODE_MASK) << QAT_CIPHER_MODE_BITPOS) |           \
276*78ee8d1cSJulian Grajkowski 	 ((algo & QAT_CIPHER_ALGO_MASK) << QAT_CIPHER_ALGO_BITPOS) |           \
277*78ee8d1cSJulian Grajkowski 	 ((convert & QAT_CIPHER_CONVERT_MASK) << QAT_CIPHER_CONVERT_BITPOS) |  \
278*78ee8d1cSJulian Grajkowski 	 ((dir & QAT_CIPHER_DIR_MASK) << QAT_CIPHER_DIR_BITPOS))
279*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_DES_BLK_SZ 8
280*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_3DES_BLK_SZ 8
281*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_NULL_BLK_SZ 8
282*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_BLK_SZ 16
283*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_KASUMI_BLK_SZ 8
284*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SNOW_3G_BLK_SZ 8
285*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ZUC_3G_BLK_SZ 8
286*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_NULL_KEY_SZ 256
287*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_DES_KEY_SZ 8
288*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_3DES_KEY_SZ 24
289*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_128_KEY_SZ 16
290*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_192_KEY_SZ 24
291*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_256_KEY_SZ 32
292*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_128_F8_KEY_SZ                                           \
293*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_128_KEY_SZ * QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
294*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_192_F8_KEY_SZ                                           \
295*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_192_KEY_SZ * QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
296*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_256_F8_KEY_SZ                                           \
297*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_256_KEY_SZ * QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
298*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_128_XTS_KEY_SZ                                          \
299*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_128_KEY_SZ * QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
300*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_256_XTS_KEY_SZ                                          \
301*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_256_KEY_SZ * QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
302*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_KASUMI_KEY_SZ 16
303*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_KASUMI_F8_KEY_SZ                                            \
304*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_KASUMI_KEY_SZ * QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
305*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_128_XTS_KEY_SZ                                          \
306*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_128_KEY_SZ * QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
307*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_AES_256_XTS_KEY_SZ                                          \
308*78ee8d1cSJulian Grajkowski 	(ICP_QAT_HW_AES_256_KEY_SZ * QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
309*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ARC4_KEY_SZ 256
310*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ 16
311*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ 16
312*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ 16
313*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ 16
314*78ee8d1cSJulian Grajkowski #define ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR 2
315*78ee8d1cSJulian Grajkowski #define INIT_SHRAM_CONSTANTS_TABLE_SZ 1024
316*78ee8d1cSJulian Grajkowski 
317*78ee8d1cSJulian Grajkowski struct icp_qat_hw_cipher_aes256_f8 {
318*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_cipher_config cipher_config;
319*78ee8d1cSJulian Grajkowski 	uint8_t key[ICP_QAT_HW_AES_256_F8_KEY_SZ];
320*78ee8d1cSJulian Grajkowski };
321*78ee8d1cSJulian Grajkowski 
322*78ee8d1cSJulian Grajkowski struct icp_qat_hw_cipher_algo_blk {
323*78ee8d1cSJulian Grajkowski 	struct icp_qat_hw_cipher_aes256_f8 aes;
324*78ee8d1cSJulian Grajkowski } __aligned(64);
325*78ee8d1cSJulian Grajkowski #endif
326