xref: /linux/drivers/crypto/intel/qat/qat_common/adf_mstate_mgr.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright(c) 2024 Intel Corporation */
3 
4 #ifndef ADF_MSTATE_MGR_H
5 #define ADF_MSTATE_MGR_H
6 
7 #define ADF_MSTATE_ID_LEN		8
8 
9 #define ADF_MSTATE_ETRB_IDS		"ETRBAR"
10 #define ADF_MSTATE_MISCB_IDS		"MISCBAR"
11 #define ADF_MSTATE_EXTB_IDS		"EXTBAR"
12 #define ADF_MSTATE_GEN_IDS		"GENER"
13 #define ADF_MSTATE_CONFIG_IDS		"CONFIG"
14 #define ADF_MSTATE_SECTION_NUM		5
15 
16 #define ADF_MSTATE_BANK_IDX_IDS		"bnk"
17 
18 #define ADF_MSTATE_ETR_REGS_IDS		"mregs"
19 #define ADF_MSTATE_VINTSRC_IDS		"visrc"
20 #define ADF_MSTATE_VINTMSK_IDS		"vimsk"
21 #define ADF_MSTATE_SLA_IDS		"sla"
22 #define ADF_MSTATE_IOV_INIT_IDS		"iovinit"
23 #define ADF_MSTATE_COMPAT_VER_IDS	"compver"
24 #define ADF_MSTATE_GEN_CAP_IDS		"gencap"
25 #define ADF_MSTATE_GEN_SVCMAP_IDS	"svcmap"
26 #define ADF_MSTATE_GEN_EXTDC_IDS	"extdc"
27 #define ADF_MSTATE_VINTSRC_PF2VM_IDS	"vispv"
28 #define ADF_MSTATE_VINTMSK_PF2VM_IDS	"vimpv"
29 #define ADF_MSTATE_VM2PF_IDS		"vm2pf"
30 #define ADF_MSTATE_PF2VM_IDS		"pf2vm"
31 
32 struct adf_mstate_mgr {
33 	u8 *buf;
34 	u8 *state;
35 	u32 size;
36 	u32 n_sects;
37 };
38 
39 struct adf_mstate_preh {
40 	u32 magic;
41 	u32 version;
42 	u16 preh_len;
43 	u16 n_sects;
44 	u32 size;
45 };
46 
47 struct adf_mstate_vreginfo {
48 	void *addr;
49 	u32 size;
50 };
51 
52 struct adf_mstate_sect_h;
53 
54 typedef int (*adf_mstate_preamble_checker)(struct adf_mstate_preh *preamble, void *opa);
55 typedef int (*adf_mstate_populate)(struct adf_mstate_mgr *sub_mgr, u8 *buf,
56 				   u32 size, void *opa);
57 typedef int (*adf_mstate_action)(struct adf_mstate_mgr *sub_mgr, u8 *buf, u32 size,
58 				 void *opa);
59 
60 struct adf_mstate_mgr *adf_mstate_mgr_new(u8 *buf, u32 size);
61 void adf_mstate_mgr_destroy(struct adf_mstate_mgr *mgr);
62 void adf_mstate_mgr_init(struct adf_mstate_mgr *mgr, u8 *buf, u32 size);
63 void adf_mstate_mgr_init_from_parent(struct adf_mstate_mgr *mgr,
64 				     struct adf_mstate_mgr *p_mgr);
65 void adf_mstate_mgr_init_from_psect(struct adf_mstate_mgr *mgr,
66 				    struct adf_mstate_sect_h *p_sect);
67 int adf_mstate_mgr_init_from_remote(struct adf_mstate_mgr *mgr,
68 				    u8 *buf, u32 size,
69 				    adf_mstate_preamble_checker checker,
70 				    void *opaque);
71 struct adf_mstate_preh *adf_mstate_preamble_add(struct adf_mstate_mgr *mgr);
72 int adf_mstate_preamble_update(struct adf_mstate_mgr *mgr);
73 u32 adf_mstate_state_size(struct adf_mstate_mgr *mgr);
74 u32 adf_mstate_state_size_from_remote(struct adf_mstate_mgr *mgr);
75 void adf_mstate_sect_update(struct adf_mstate_mgr *p_mgr,
76 			    struct adf_mstate_mgr *curr_mgr,
77 			    struct adf_mstate_sect_h *sect);
78 struct adf_mstate_sect_h *adf_mstate_sect_add_vreg(struct adf_mstate_mgr *mgr,
79 						   const char *id,
80 						   struct adf_mstate_vreginfo *info);
81 struct adf_mstate_sect_h *adf_mstate_sect_add(struct adf_mstate_mgr *mgr,
82 					      const char *id,
83 					      adf_mstate_populate populate,
84 					      void *opaque);
85 struct adf_mstate_sect_h *adf_mstate_sect_lookup(struct adf_mstate_mgr *mgr,
86 						 const char *id,
87 						 adf_mstate_action action,
88 						 void *opaque);
89 #endif
90