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