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