1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
2 /* Copyright(c) 2014 - 2020 Intel Corporation */
3 #ifndef __ICP_QAT_UCLO_H__
4 #define __ICP_QAT_UCLO_H__
5 
6 #define ICP_QAT_AC_895XCC_DEV_TYPE 0x00400000
7 #define ICP_QAT_AC_C62X_DEV_TYPE   0x01000000
8 #define ICP_QAT_AC_C3XXX_DEV_TYPE  0x02000000
9 #define ICP_QAT_AC_4XXX_A_DEV_TYPE 0x08000000
10 #define ICP_QAT_UCLO_MAX_AE       12
11 #define ICP_QAT_UCLO_MAX_CTX      8
12 #define ICP_QAT_UCLO_MAX_UIMAGE   (ICP_QAT_UCLO_MAX_AE * ICP_QAT_UCLO_MAX_CTX)
13 #define ICP_QAT_UCLO_MAX_USTORE   0x4000
14 #define ICP_QAT_UCLO_MAX_XFER_REG 128
15 #define ICP_QAT_UCLO_MAX_GPR_REG  128
16 #define ICP_QAT_UCLO_MAX_LMEM_REG 1024
17 #define ICP_QAT_UCLO_MAX_LMEM_REG_2X 1280
18 #define ICP_QAT_UCLO_AE_ALL_CTX   0xff
19 #define ICP_QAT_UOF_OBJID_LEN     8
20 #define ICP_QAT_UOF_FID 0xc6c2
21 #define ICP_QAT_UOF_MAJVER 0x4
22 #define ICP_QAT_UOF_MINVER 0x11
23 #define ICP_QAT_UOF_OBJS        "UOF_OBJS"
24 #define ICP_QAT_UOF_STRT        "UOF_STRT"
25 #define ICP_QAT_UOF_IMAG        "UOF_IMAG"
26 #define ICP_QAT_UOF_IMEM        "UOF_IMEM"
27 #define ICP_QAT_UOF_LOCAL_SCOPE     1
28 #define ICP_QAT_UOF_INIT_EXPR               0
29 #define ICP_QAT_UOF_INIT_REG                1
30 #define ICP_QAT_UOF_INIT_REG_CTX            2
31 #define ICP_QAT_UOF_INIT_EXPR_ENDIAN_SWAP   3
32 #define ICP_QAT_SUOF_OBJ_ID_LEN             8
33 #define ICP_QAT_SUOF_FID  0x53554f46
34 #define ICP_QAT_SUOF_MAJVER 0x0
35 #define ICP_QAT_SUOF_MINVER 0x1
36 #define ICP_QAT_SUOF_OBJ_NAME_LEN 128
37 #define ICP_QAT_MOF_OBJ_ID_LEN 8
38 #define ICP_QAT_MOF_OBJ_CHUNKID_LEN 8
39 #define ICP_QAT_MOF_FID 0x00666f6d
40 #define ICP_QAT_MOF_MAJVER 0x0
41 #define ICP_QAT_MOF_MINVER 0x1
42 #define ICP_QAT_MOF_SYM_OBJS "SYM_OBJS"
43 #define ICP_QAT_SUOF_OBJS "SUF_OBJS"
44 #define ICP_QAT_SUOF_IMAG "SUF_IMAG"
45 #define ICP_QAT_SIMG_AE_INIT_SEQ_LEN    (50 * sizeof(unsigned long long))
46 #define ICP_QAT_SIMG_AE_INSTS_LEN       (0x4000 * sizeof(unsigned long long))
47 
48 #define DSS_FWSK_MODULUS_LEN    384 /* RSA3K */
49 #define DSS_FWSK_EXPONENT_LEN   4
50 #define DSS_FWSK_PADDING_LEN    380
51 #define DSS_SIGNATURE_LEN       384 /* RSA3K */
52 
53 #define CSS_FWSK_MODULUS_LEN    256 /* RSA2K */
54 #define CSS_FWSK_EXPONENT_LEN   4
55 #define CSS_FWSK_PADDING_LEN    252
56 #define CSS_SIGNATURE_LEN       256 /* RSA2K */
57 
58 #define ICP_QAT_CSS_FWSK_MODULUS_LEN(handle)	((handle)->chip_info->css_3k ? \
59 						DSS_FWSK_MODULUS_LEN  : \
60 						CSS_FWSK_MODULUS_LEN)
61 
62 #define ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle)	((handle)->chip_info->css_3k ? \
63 						DSS_FWSK_EXPONENT_LEN : \
64 						CSS_FWSK_EXPONENT_LEN)
65 
66 #define ICP_QAT_CSS_FWSK_PAD_LEN(handle)	((handle)->chip_info->css_3k ? \
67 						DSS_FWSK_PADDING_LEN : \
68 						CSS_FWSK_PADDING_LEN)
69 
70 #define ICP_QAT_CSS_FWSK_PUB_LEN(handle)	(ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + \
71 						ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle) + \
72 						ICP_QAT_CSS_FWSK_PAD_LEN(handle))
73 
74 #define ICP_QAT_CSS_SIGNATURE_LEN(handle)	((handle)->chip_info->css_3k ? \
75 						DSS_SIGNATURE_LEN : \
76 						CSS_SIGNATURE_LEN)
77 
78 #define ICP_QAT_CSS_AE_IMG_LEN     (sizeof(struct icp_qat_simg_ae_mode) + \
79 				    ICP_QAT_SIMG_AE_INIT_SEQ_LEN +         \
80 				    ICP_QAT_SIMG_AE_INSTS_LEN)
81 #define ICP_QAT_CSS_AE_SIMG_LEN(handle) (sizeof(struct icp_qat_css_hdr) + \
82 					ICP_QAT_CSS_FWSK_PUB_LEN(handle) + \
83 					ICP_QAT_CSS_SIGNATURE_LEN(handle) + \
84 					ICP_QAT_CSS_AE_IMG_LEN)
85 #define ICP_QAT_AE_IMG_OFFSET(handle) (sizeof(struct icp_qat_css_hdr) + \
86 					ICP_QAT_CSS_FWSK_MODULUS_LEN(handle) + \
87 					ICP_QAT_CSS_FWSK_EXPONENT_LEN(handle) + \
88 					ICP_QAT_CSS_SIGNATURE_LEN(handle))
89 #define ICP_QAT_CSS_MAX_IMAGE_LEN   0x40000
90 
91 #define ICP_QAT_CTX_MODE(ae_mode) ((ae_mode) & 0xf)
92 #define ICP_QAT_NN_MODE(ae_mode) (((ae_mode) >> 0x4) & 0xf)
93 #define ICP_QAT_SHARED_USTORE_MODE(ae_mode) (((ae_mode) >> 0xb) & 0x1)
94 #define RELOADABLE_CTX_SHARED_MODE(ae_mode) (((ae_mode) >> 0xc) & 0x1)
95 
96 #define ICP_QAT_LOC_MEM0_MODE(ae_mode) (((ae_mode) >> 0x8) & 0x1)
97 #define ICP_QAT_LOC_MEM1_MODE(ae_mode) (((ae_mode) >> 0x9) & 0x1)
98 #define ICP_QAT_LOC_MEM2_MODE(ae_mode) (((ae_mode) >> 0x6) & 0x1)
99 #define ICP_QAT_LOC_MEM3_MODE(ae_mode) (((ae_mode) >> 0x7) & 0x1)
100 #define ICP_QAT_LOC_TINDEX_MODE(ae_mode) (((ae_mode) >> 0xe) & 0x1)
101 
102 enum icp_qat_uof_mem_region {
103 	ICP_QAT_UOF_SRAM_REGION = 0x0,
104 	ICP_QAT_UOF_LMEM_REGION = 0x3,
105 	ICP_QAT_UOF_UMEM_REGION = 0x5
106 };
107 
108 enum icp_qat_uof_regtype {
109 	ICP_NO_DEST	= 0,
110 	ICP_GPA_REL	= 1,
111 	ICP_GPA_ABS	= 2,
112 	ICP_GPB_REL	= 3,
113 	ICP_GPB_ABS	= 4,
114 	ICP_SR_REL	= 5,
115 	ICP_SR_RD_REL	= 6,
116 	ICP_SR_WR_REL	= 7,
117 	ICP_SR_ABS	= 8,
118 	ICP_SR_RD_ABS	= 9,
119 	ICP_SR_WR_ABS	= 10,
120 	ICP_DR_REL	= 19,
121 	ICP_DR_RD_REL	= 20,
122 	ICP_DR_WR_REL	= 21,
123 	ICP_DR_ABS	= 22,
124 	ICP_DR_RD_ABS	= 23,
125 	ICP_DR_WR_ABS	= 24,
126 	ICP_LMEM	= 26,
127 	ICP_LMEM0	= 27,
128 	ICP_LMEM1	= 28,
129 	ICP_NEIGH_REL	= 31,
130 	ICP_LMEM2	= 61,
131 	ICP_LMEM3	= 62,
132 };
133 
134 enum icp_qat_css_fwtype {
135 	CSS_AE_FIRMWARE = 0,
136 	CSS_MMP_FIRMWARE = 1
137 };
138 
139 struct icp_qat_uclo_page {
140 	struct icp_qat_uclo_encap_page *encap_page;
141 	struct icp_qat_uclo_region *region;
142 	unsigned int flags;
143 };
144 
145 struct icp_qat_uclo_region {
146 	struct icp_qat_uclo_page *loaded;
147 	struct icp_qat_uclo_page *page;
148 };
149 
150 struct icp_qat_uclo_aeslice {
151 	struct icp_qat_uclo_region *region;
152 	struct icp_qat_uclo_page *page;
153 	struct icp_qat_uclo_page *cur_page[ICP_QAT_UCLO_MAX_CTX];
154 	struct icp_qat_uclo_encapme *encap_image;
155 	unsigned int ctx_mask_assigned;
156 	unsigned int new_uaddr[ICP_QAT_UCLO_MAX_CTX];
157 };
158 
159 struct icp_qat_uclo_aedata {
160 	unsigned int slice_num;
161 	unsigned int eff_ustore_size;
162 	struct icp_qat_uclo_aeslice ae_slices[ICP_QAT_UCLO_MAX_CTX];
163 };
164 
165 struct icp_qat_uof_encap_obj {
166 	char *beg_uof;
167 	struct icp_qat_uof_objhdr *obj_hdr;
168 	struct icp_qat_uof_chunkhdr *chunk_hdr;
169 	struct icp_qat_uof_varmem_seg *var_mem_seg;
170 };
171 
172 struct icp_qat_uclo_encap_uwblock {
173 	unsigned int start_addr;
174 	unsigned int words_num;
175 	u64 micro_words;
176 };
177 
178 struct icp_qat_uclo_encap_page {
179 	unsigned int def_page;
180 	unsigned int page_region;
181 	unsigned int beg_addr_v;
182 	unsigned int beg_addr_p;
183 	unsigned int micro_words_num;
184 	unsigned int uwblock_num;
185 	struct icp_qat_uclo_encap_uwblock *uwblock;
186 };
187 
188 struct icp_qat_uclo_encapme {
189 	struct icp_qat_uof_image *img_ptr;
190 	struct icp_qat_uclo_encap_page *page;
191 	unsigned int ae_reg_num;
192 	struct icp_qat_uof_ae_reg *ae_reg;
193 	unsigned int init_regsym_num;
194 	struct icp_qat_uof_init_regsym *init_regsym;
195 	unsigned int sbreak_num;
196 	struct icp_qat_uof_sbreak *sbreak;
197 	unsigned int uwords_num;
198 };
199 
200 struct icp_qat_uclo_init_mem_table {
201 	unsigned int entry_num;
202 	struct icp_qat_uof_initmem *init_mem;
203 };
204 
205 struct icp_qat_uclo_objhdr {
206 	char *file_buff;
207 	unsigned int checksum;
208 	unsigned int size;
209 };
210 
211 struct icp_qat_uof_strtable {
212 	unsigned int table_len;
213 	unsigned int reserved;
214 	u64 strings;
215 };
216 
217 struct icp_qat_uclo_objhandle {
218 	unsigned int prod_type;
219 	unsigned int prod_rev;
220 	struct icp_qat_uclo_objhdr *obj_hdr;
221 	struct icp_qat_uof_encap_obj encap_uof_obj;
222 	struct icp_qat_uof_strtable str_table;
223 	struct icp_qat_uclo_encapme ae_uimage[ICP_QAT_UCLO_MAX_UIMAGE];
224 	struct icp_qat_uclo_aedata ae_data[ICP_QAT_UCLO_MAX_AE];
225 	struct icp_qat_uclo_init_mem_table init_mem_tab;
226 	struct icp_qat_uof_batch_init *lm_init_tab[ICP_QAT_UCLO_MAX_AE];
227 	struct icp_qat_uof_batch_init *umem_init_tab[ICP_QAT_UCLO_MAX_AE];
228 	int uimage_num;
229 	int uword_in_bytes;
230 	int global_inited;
231 	unsigned int ae_num;
232 	unsigned int ustore_phy_size;
233 	void *obj_buf;
234 	u64 *uword_buf;
235 };
236 
237 struct icp_qat_uof_uword_block {
238 	unsigned int start_addr;
239 	unsigned int words_num;
240 	unsigned int uword_offset;
241 	unsigned int reserved;
242 };
243 
244 struct icp_qat_uof_filehdr {
245 	unsigned short file_id;
246 	unsigned short reserved1;
247 	char min_ver;
248 	char maj_ver;
249 	unsigned short reserved2;
250 	unsigned short max_chunks;
251 	unsigned short num_chunks;
252 };
253 
254 struct icp_qat_uof_filechunkhdr {
255 	char chunk_id[ICP_QAT_UOF_OBJID_LEN];
256 	unsigned int checksum;
257 	unsigned int offset;
258 	unsigned int size;
259 };
260 
261 struct icp_qat_uof_objhdr {
262 	unsigned int ac_dev_type;
263 	unsigned short min_cpu_ver;
264 	unsigned short max_cpu_ver;
265 	short max_chunks;
266 	short num_chunks;
267 	unsigned int reserved1;
268 	unsigned int reserved2;
269 };
270 
271 struct icp_qat_uof_chunkhdr {
272 	char chunk_id[ICP_QAT_UOF_OBJID_LEN];
273 	unsigned int offset;
274 	unsigned int size;
275 };
276 
277 struct icp_qat_uof_memvar_attr {
278 	unsigned int offset_in_byte;
279 	unsigned int value;
280 };
281 
282 struct icp_qat_uof_initmem {
283 	unsigned int sym_name;
284 	char region;
285 	char scope;
286 	unsigned short reserved1;
287 	unsigned int addr;
288 	unsigned int num_in_bytes;
289 	unsigned int val_attr_num;
290 };
291 
292 struct icp_qat_uof_init_regsym {
293 	unsigned int sym_name;
294 	char init_type;
295 	char value_type;
296 	char reg_type;
297 	unsigned char ctx;
298 	unsigned int reg_addr;
299 	unsigned int value;
300 };
301 
302 struct icp_qat_uof_varmem_seg {
303 	unsigned int sram_base;
304 	unsigned int sram_size;
305 	unsigned int sram_alignment;
306 	unsigned int sdram_base;
307 	unsigned int sdram_size;
308 	unsigned int sdram_alignment;
309 	unsigned int sdram1_base;
310 	unsigned int sdram1_size;
311 	unsigned int sdram1_alignment;
312 	unsigned int scratch_base;
313 	unsigned int scratch_size;
314 	unsigned int scratch_alignment;
315 };
316 
317 struct icp_qat_uof_gtid {
318 	char tool_id[ICP_QAT_UOF_OBJID_LEN];
319 	int tool_ver;
320 	unsigned int reserved1;
321 	unsigned int reserved2;
322 };
323 
324 struct icp_qat_uof_sbreak {
325 	unsigned int page_num;
326 	unsigned int virt_uaddr;
327 	unsigned char sbreak_type;
328 	unsigned char reg_type;
329 	unsigned short reserved1;
330 	unsigned int addr_offset;
331 	unsigned int reg_addr;
332 };
333 
334 struct icp_qat_uof_code_page {
335 	unsigned int page_region;
336 	unsigned int page_num;
337 	unsigned char def_page;
338 	unsigned char reserved2;
339 	unsigned short reserved1;
340 	unsigned int beg_addr_v;
341 	unsigned int beg_addr_p;
342 	unsigned int neigh_reg_tab_offset;
343 	unsigned int uc_var_tab_offset;
344 	unsigned int imp_var_tab_offset;
345 	unsigned int imp_expr_tab_offset;
346 	unsigned int code_area_offset;
347 };
348 
349 struct icp_qat_uof_image {
350 	unsigned int img_name;
351 	unsigned int ae_assigned;
352 	unsigned int ctx_assigned;
353 	unsigned int ac_dev_type;
354 	unsigned int entry_address;
355 	unsigned int fill_pattern[2];
356 	unsigned int reloadable_size;
357 	unsigned char sensitivity;
358 	unsigned char reserved;
359 	unsigned short ae_mode;
360 	unsigned short max_ver;
361 	unsigned short min_ver;
362 	unsigned short image_attrib;
363 	unsigned short reserved2;
364 	unsigned short page_region_num;
365 	unsigned short numpages;
366 	unsigned int reg_tab_offset;
367 	unsigned int init_reg_sym_tab;
368 	unsigned int sbreak_tab;
369 	unsigned int app_metadata;
370 };
371 
372 struct icp_qat_uof_objtable {
373 	unsigned int entry_num;
374 };
375 
376 struct icp_qat_uof_ae_reg {
377 	unsigned int name;
378 	unsigned int vis_name;
379 	unsigned short type;
380 	unsigned short addr;
381 	unsigned short access_mode;
382 	unsigned char visible;
383 	unsigned char reserved1;
384 	unsigned short ref_count;
385 	unsigned short reserved2;
386 	unsigned int xo_id;
387 };
388 
389 struct icp_qat_uof_code_area {
390 	unsigned int micro_words_num;
391 	unsigned int uword_block_tab;
392 };
393 
394 struct icp_qat_uof_batch_init {
395 	unsigned int ae;
396 	unsigned int addr;
397 	unsigned int *value;
398 	unsigned int size;
399 	struct icp_qat_uof_batch_init *next;
400 };
401 
402 struct icp_qat_suof_img_hdr {
403 	char          *simg_buf;
404 	unsigned long simg_len;
405 	char          *css_header;
406 	char          *css_key;
407 	char          *css_signature;
408 	char          *css_simg;
409 	unsigned long simg_size;
410 	unsigned int  ae_num;
411 	unsigned int  ae_mask;
412 	unsigned int  fw_type;
413 	unsigned long simg_name;
414 	unsigned long appmeta_data;
415 };
416 
417 struct icp_qat_suof_img_tbl {
418 	unsigned int num_simgs;
419 	struct icp_qat_suof_img_hdr *simg_hdr;
420 };
421 
422 struct icp_qat_suof_handle {
423 	unsigned int  file_id;
424 	unsigned int  check_sum;
425 	char          min_ver;
426 	char          maj_ver;
427 	char          fw_type;
428 	char          *suof_buf;
429 	unsigned int  suof_size;
430 	char          *sym_str;
431 	unsigned int  sym_size;
432 	struct icp_qat_suof_img_tbl img_table;
433 };
434 
435 struct icp_qat_fw_auth_desc {
436 	unsigned int   img_len;
437 	unsigned int   ae_mask;
438 	unsigned int   css_hdr_high;
439 	unsigned int   css_hdr_low;
440 	unsigned int   img_high;
441 	unsigned int   img_low;
442 	unsigned int   signature_high;
443 	unsigned int   signature_low;
444 	unsigned int   fwsk_pub_high;
445 	unsigned int   fwsk_pub_low;
446 	unsigned int   img_ae_mode_data_high;
447 	unsigned int   img_ae_mode_data_low;
448 	unsigned int   img_ae_init_data_high;
449 	unsigned int   img_ae_init_data_low;
450 	unsigned int   img_ae_insts_high;
451 	unsigned int   img_ae_insts_low;
452 };
453 
454 struct icp_qat_auth_chunk {
455 	struct icp_qat_fw_auth_desc fw_auth_desc;
456 	u64 chunk_size;
457 	u64 chunk_bus_addr;
458 };
459 
460 struct icp_qat_css_hdr {
461 	unsigned int module_type;
462 	unsigned int header_len;
463 	unsigned int header_ver;
464 	unsigned int module_id;
465 	unsigned int module_vendor;
466 	unsigned int date;
467 	unsigned int size;
468 	unsigned int key_size;
469 	unsigned int module_size;
470 	unsigned int exponent_size;
471 	unsigned int fw_type;
472 	unsigned int reserved[21];
473 };
474 
475 struct icp_qat_simg_ae_mode {
476 	unsigned int     file_id;
477 	unsigned short   maj_ver;
478 	unsigned short   min_ver;
479 	unsigned int     dev_type;
480 	unsigned short   devmax_ver;
481 	unsigned short   devmin_ver;
482 	unsigned int     ae_mask;
483 	unsigned int     ctx_enables;
484 	char             fw_type;
485 	char             ctx_mode;
486 	char             nn_mode;
487 	char             lm0_mode;
488 	char             lm1_mode;
489 	char             scs_mode;
490 	char             lm2_mode;
491 	char             lm3_mode;
492 	char             tindex_mode;
493 	unsigned char    reserved[7];
494 	char             simg_name[256];
495 	char             appmeta_data[256];
496 };
497 
498 struct icp_qat_suof_filehdr {
499 	unsigned int     file_id;
500 	unsigned int     check_sum;
501 	char             min_ver;
502 	char             maj_ver;
503 	char             fw_type;
504 	char             reserved;
505 	unsigned short   max_chunks;
506 	unsigned short   num_chunks;
507 };
508 
509 struct icp_qat_suof_chunk_hdr {
510 	char chunk_id[ICP_QAT_SUOF_OBJ_ID_LEN];
511 	u64 offset;
512 	u64 size;
513 };
514 
515 struct icp_qat_suof_strtable {
516 	unsigned int tab_length;
517 	unsigned int strings;
518 };
519 
520 struct icp_qat_suof_objhdr {
521 	unsigned int img_length;
522 	unsigned int reserved;
523 };
524 
525 struct icp_qat_mof_file_hdr {
526 	unsigned int file_id;
527 	unsigned int checksum;
528 	char min_ver;
529 	char maj_ver;
530 	unsigned short reserved;
531 	unsigned short max_chunks;
532 	unsigned short num_chunks;
533 };
534 
535 struct icp_qat_mof_chunkhdr {
536 	char chunk_id[ICP_QAT_MOF_OBJ_ID_LEN];
537 	u64 offset;
538 	u64 size;
539 };
540 
541 struct icp_qat_mof_str_table {
542 	unsigned int tab_len;
543 	unsigned int strings;
544 };
545 
546 struct icp_qat_mof_obj_hdr {
547 	unsigned short max_chunks;
548 	unsigned short num_chunks;
549 	unsigned int reserved;
550 };
551 
552 struct icp_qat_mof_obj_chunkhdr {
553 	char chunk_id[ICP_QAT_MOF_OBJ_CHUNKID_LEN];
554 	u64 offset;
555 	u64 size;
556 	unsigned int name;
557 	unsigned int reserved;
558 };
559 
560 struct icp_qat_mof_objhdr {
561 	char *obj_name;
562 	char *obj_buf;
563 	unsigned int obj_size;
564 };
565 
566 struct icp_qat_mof_table {
567 	unsigned int num_objs;
568 	struct icp_qat_mof_objhdr *obj_hdr;
569 };
570 
571 struct icp_qat_mof_handle {
572 	unsigned int file_id;
573 	unsigned int checksum;
574 	char min_ver;
575 	char maj_ver;
576 	char *mof_buf;
577 	u32 mof_size;
578 	char *sym_str;
579 	unsigned int sym_size;
580 	char *uobjs_hdr;
581 	char *sobjs_hdr;
582 	struct icp_qat_mof_table obj_table;
583 };
584 #endif
585