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