xref: /openbmc/linux/drivers/crypto/hisilicon/sec2/sec_crypto.h (revision 060f35a317ef09101b128f399dce7ed13d019461)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2019 HiSilicon Limited. */
3 
4 #ifndef __HISI_SEC_V2_CRYPTO_H
5 #define __HISI_SEC_V2_CRYPTO_H
6 
7 #define SEC_AIV_SIZE		12
8 #define SEC_IV_SIZE		24
9 #define SEC_MAX_KEY_SIZE	64
10 #define SEC_MAX_AKEY_SIZE	128
11 #define SEC_COMM_SCENE		0
12 #define SEC_MIN_BLOCK_SZ	1
13 
14 enum sec_calg {
15 	SEC_CALG_3DES = 0x1,
16 	SEC_CALG_AES  = 0x2,
17 	SEC_CALG_SM4  = 0x3,
18 };
19 
20 enum sec_hash_alg {
21 	SEC_A_HMAC_SHA1   = 0x10,
22 	SEC_A_HMAC_SHA256 = 0x11,
23 	SEC_A_HMAC_SHA512 = 0x15,
24 };
25 
26 enum sec_cmode {
27 	SEC_CMODE_ECB    = 0x0,
28 	SEC_CMODE_CBC    = 0x1,
29 	SEC_CMODE_CFB    = 0x2,
30 	SEC_CMODE_OFB    = 0x3,
31 	SEC_CMODE_CTR    = 0x4,
32 	SEC_CMODE_CCM    = 0x5,
33 	SEC_CMODE_GCM    = 0x6,
34 	SEC_CMODE_XTS    = 0x7,
35 };
36 
37 enum sec_ckey_type {
38 	SEC_CKEY_128BIT = 0x0,
39 	SEC_CKEY_192BIT = 0x1,
40 	SEC_CKEY_256BIT = 0x2,
41 	SEC_CKEY_3DES_3KEY = 0x1,
42 	SEC_CKEY_3DES_2KEY = 0x3,
43 };
44 
45 enum sec_bd_type {
46 	SEC_BD_TYPE1 = 0x1,
47 	SEC_BD_TYPE2 = 0x2,
48 	SEC_BD_TYPE3 = 0x3,
49 };
50 
51 enum sec_auth {
52 	SEC_NO_AUTH = 0x0,
53 	SEC_AUTH_TYPE1 = 0x1,
54 	SEC_AUTH_TYPE2 = 0x2,
55 };
56 
57 enum sec_cipher_dir {
58 	SEC_CIPHER_ENC = 0x1,
59 	SEC_CIPHER_DEC = 0x2,
60 };
61 
62 enum sec_addr_type {
63 	SEC_PBUF = 0x0,
64 	SEC_SGL  = 0x1,
65 	SEC_PRP  = 0x2,
66 };
67 
68 struct bd_status {
69 	u64 tag;
70 	u8 done;
71 	u8 err_type;
72 	u16 flag;
73 	u16 icv;
74 };
75 
76 enum {
77 	AUTHPAD_PAD,
78 	AUTHPAD_NOPAD,
79 };
80 
81 enum {
82 	AIGEN_GEN,
83 	AIGEN_NOGEN,
84 };
85 
86 struct sec_sqe_type2 {
87 	/*
88 	 * mac_len: 0~4 bits
89 	 * a_key_len: 5~10 bits
90 	 * a_alg: 11~16 bits
91 	 */
92 	__le32 mac_key_alg;
93 
94 	/*
95 	 * c_icv_len: 0~5 bits
96 	 * c_width: 6~8 bits
97 	 * c_key_len: 9~11 bits
98 	 * c_mode: 12~15 bits
99 	 */
100 	__le16 icvw_kmode;
101 
102 	/* c_alg: 0~3 bits */
103 	__u8 c_alg;
104 	__u8 rsvd4;
105 
106 	/*
107 	 * a_len: 0~23 bits
108 	 * iv_offset_l: 24~31 bits
109 	 */
110 	__le32 alen_ivllen;
111 
112 	/*
113 	 * c_len: 0~23 bits
114 	 * iv_offset_h: 24~31 bits
115 	 */
116 	__le32 clen_ivhlen;
117 
118 	__le16 auth_src_offset;
119 	__le16 cipher_src_offset;
120 	__le16 cs_ip_header_offset;
121 	__le16 cs_udp_header_offset;
122 	__le16 pass_word_len;
123 	__le16 dk_len;
124 	__u8 salt3;
125 	__u8 salt2;
126 	__u8 salt1;
127 	__u8 salt0;
128 
129 	__le16 tag;
130 	__le16 rsvd5;
131 
132 	/*
133 	 * c_pad_type: 0~3 bits
134 	 * c_pad_len: 4~11 bits
135 	 * c_pad_data_type: 12~15 bits
136 	 */
137 	__le16 cph_pad;
138 
139 	/* c_pad_len_field: 0~1 bits */
140 	__le16 c_pad_len_field;
141 
142 	__le64 long_a_data_len;
143 	__le64 a_ivin_addr;
144 	__le64 a_key_addr;
145 	__le64 mac_addr;
146 	__le64 c_ivin_addr;
147 	__le64 c_key_addr;
148 
149 	__le64 data_src_addr;
150 	__le64 data_dst_addr;
151 
152 	/*
153 	 * done: 0 bit
154 	 * icv: 1~3 bits
155 	 * csc: 4~6 bits
156 	 * flag: 7-10 bits
157 	 * dif_check: 11~13 bits
158 	 */
159 	__le16 done_flag;
160 
161 	__u8 error_type;
162 	__u8 warning_type;
163 	__u8 mac_i3;
164 	__u8 mac_i2;
165 	__u8 mac_i1;
166 	__u8 mac_i0;
167 	__le16 check_sum_i;
168 	__u8 tls_pad_len_i;
169 	__u8 rsvd12;
170 	__le32 counter;
171 };
172 
173 struct sec_sqe {
174 	/*
175 	 * type:	0~3 bits
176 	 * cipher:	4~5 bits
177 	 * auth:	6~7 bit s
178 	 */
179 	__u8 type_cipher_auth;
180 
181 	/*
182 	 * seq:	0 bit
183 	 * de:	1~2 bits
184 	 * scene:	3~6 bits
185 	 * src_addr_type: ~7 bit, with sdm_addr_type 0-1 bits
186 	 */
187 	__u8 sds_sa_type;
188 
189 	/*
190 	 * src_addr_type: 0~1 bits, not used now,
191 	 * if support PRP, set this field, or set zero.
192 	 * dst_addr_type: 2~4 bits
193 	 * mac_addr_type: 5~7 bits
194 	 */
195 	__u8 sdm_addr_type;
196 	__u8 rsvd0;
197 
198 	/*
199 	 * nonce_len(type2): 0~3 bits
200 	 * huk(type2): 4 bit
201 	 * key_s(type2): 5 bit
202 	 * ci_gen: 6~7 bits
203 	 */
204 	__u8 huk_key_ci;
205 
206 	/*
207 	 * ai_gen: 0~1 bits
208 	 * a_pad(type2): 2~3 bits
209 	 * c_s(type2): 4~5 bits
210 	 */
211 	__u8 ai_apd_cs;
212 
213 	/*
214 	 * rhf(type2): 0 bit
215 	 * c_key_type: 1~2 bits
216 	 * a_key_type: 3~4 bits
217 	 * write_frame_len(type2): 5~7 bits
218 	 */
219 	__u8 rca_key_frm;
220 
221 	/*
222 	 * cal_iv_addr_en(type2): 0 bit
223 	 * tls_up(type2): 1 bit
224 	 * inveld: 7 bit
225 	 */
226 	__u8 iv_tls_ld;
227 
228 	/* Just using type2 BD now */
229 	struct sec_sqe_type2 type2;
230 };
231 
232 struct bd3_auth_ivin {
233 	__le64 a_ivin_addr;
234 	__le32 rsvd0;
235 	__le32 rsvd1;
236 } __packed __aligned(4);
237 
238 struct bd3_skip_data {
239 	__le32 rsvd0;
240 
241 	/*
242 	 * gran_num: 0~15 bits
243 	 * reserved: 16~31 bits
244 	 */
245 	__le32 gran_num;
246 
247 	/*
248 	 * src_skip_data_len: 0~24 bits
249 	 * reserved: 25~31 bits
250 	 */
251 	__le32 src_skip_data_len;
252 
253 	/*
254 	 * dst_skip_data_len: 0~24 bits
255 	 * reserved: 25~31 bits
256 	 */
257 	__le32 dst_skip_data_len;
258 };
259 
260 struct bd3_stream_scene {
261 	__le64 c_ivin_addr;
262 	__le64 long_a_data_len;
263 
264 	/*
265 	 * auth_pad: 0~1 bits
266 	 * stream_protocol: 2~4 bits
267 	 * reserved: 5~7 bits
268 	 */
269 	__u8 stream_auth_pad;
270 	__u8 plaintext_type;
271 	__le16 pad_len_1p3;
272 } __packed __aligned(4);
273 
274 struct bd3_no_scene {
275 	__le64 c_ivin_addr;
276 	__le32 rsvd0;
277 	__le32 rsvd1;
278 	__le32 rsvd2;
279 } __packed __aligned(4);
280 
281 struct bd3_check_sum {
282 	__u8 rsvd0;
283 	__u8 hac_sva_status;
284 	__le16 check_sum_i;
285 };
286 
287 struct bd3_tls_type_back {
288 	__u8 tls_1p3_type_back;
289 	__u8 hac_sva_status;
290 	__le16 pad_len_1p3_back;
291 };
292 
293 struct sec_sqe3 {
294 	/*
295 	 * type: 0~3 bit
296 	 * bd_invalid: 4 bit
297 	 * scene: 5~8 bit
298 	 * de: 9~10 bit
299 	 * src_addr_type: 11~13 bit
300 	 * dst_addr_type: 14~16 bit
301 	 * mac_addr_type: 17~19 bit
302 	 * reserved: 20~31 bits
303 	 */
304 	__le32 bd_param;
305 
306 	/*
307 	 * cipher: 0~1 bits
308 	 * ci_gen: 2~3 bit
309 	 * c_icv_len: 4~9 bit
310 	 * c_width: 10~12 bits
311 	 * c_key_len: 13~15 bits
312 	 */
313 	__le16 c_icv_key;
314 
315 	/*
316 	 * c_mode : 0~3 bits
317 	 * c_alg : 4~7 bits
318 	 */
319 	__u8 c_mode_alg;
320 
321 	/*
322 	 * nonce_len : 0~3 bits
323 	 * huk : 4 bits
324 	 * cal_iv_addr_en : 5 bits
325 	 * seq : 6 bits
326 	 * reserved : 7 bits
327 	 */
328 	__u8 huk_iv_seq;
329 
330 	__le64 tag;
331 	__le64 data_src_addr;
332 	__le64 a_key_addr;
333 	union {
334 		struct bd3_auth_ivin auth_ivin;
335 		struct bd3_skip_data skip_data;
336 	};
337 
338 	__le64 c_key_addr;
339 
340 	/*
341 	 * auth: 0~1 bits
342 	 * ai_gen: 2~3 bits
343 	 * mac_len: 4~8 bits
344 	 * akey_len: 9~14 bits
345 	 * a_alg: 15~20 bits
346 	 * key_sel: 21~24 bits
347 	 * ctr_count_mode/sm4_xts: 25~26 bits
348 	 * sva_prefetch: 27 bits
349 	 * key_wrap_num: 28~30 bits
350 	 * update_key: 31 bits
351 	 */
352 	__le32 auth_mac_key;
353 	__le32 salt;
354 	__le16 auth_src_offset;
355 	__le16 cipher_src_offset;
356 
357 	/*
358 	 * auth_len: 0~23 bit
359 	 * auth_key_offset: 24~31 bits
360 	 */
361 	__le32 a_len_key;
362 
363 	/*
364 	 * cipher_len: 0~23 bit
365 	 * auth_ivin_offset: 24~31 bits
366 	 */
367 	__le32 c_len_ivin;
368 	__le64 data_dst_addr;
369 	__le64 mac_addr;
370 	union {
371 		struct bd3_stream_scene stream_scene;
372 		struct bd3_no_scene no_scene;
373 	};
374 
375 	/*
376 	 * done: 0 bit
377 	 * icv: 1~3 bit
378 	 * csc: 4~6 bit
379 	 * flag: 7~10 bit
380 	 * reserved: 11~15 bit
381 	 */
382 	__le16 done_flag;
383 	__u8 error_type;
384 	__u8 warning_type;
385 	union {
386 		__le32 mac_i;
387 		__le32 kek_key_addr_l;
388 	};
389 	union {
390 		__le32 kek_key_addr_h;
391 		struct bd3_check_sum check_sum;
392 		struct bd3_tls_type_back tls_type_back;
393 	};
394 	__le32 counter;
395 } __packed __aligned(4);
396 
397 int sec_register_to_crypto(struct hisi_qm *qm);
398 void sec_unregister_from_crypto(struct hisi_qm *qm);
399 #endif
400