1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 /**
5  ***************************************************************************
6  * @file lac_sal_types.h
7  *
8  * @ingroup SalCtrl
9  *
10  * Generic instance type definitions of SAL controller
11  *
12  ***************************************************************************/
13 
14 #ifndef LAC_SAL_TYPES_H
15 #define LAC_SAL_TYPES_H
16 
17 #include "lac_sync.h"
18 #include "lac_list.h"
19 #include "icp_accel_devices.h"
20 #include "sal_statistics.h"
21 #include "icp_adf_debug.h"
22 
23 #define SAL_CFG_BASE_DEC 10
24 #define SAL_CFG_BASE_HEX 16
25 
26 /**
27  *****************************************************************************
28  * @ingroup SalCtrl
29  *      Instance States
30  *
31  * @description
32  *    An enumeration containing the possible states for an instance.
33  *
34  *****************************************************************************/
35 typedef enum sal_service_state_s {
36 	SAL_SERVICE_STATE_UNINITIALIZED = 0,
37 	SAL_SERVICE_STATE_INITIALIZING,
38 	SAL_SERVICE_STATE_INITIALIZED,
39 	SAL_SERVICE_STATE_RUNNING,
40 	SAL_SERVICE_STATE_SHUTTING_DOWN,
41 	SAL_SERVICE_STATE_SHUTDOWN,
42 	SAL_SERVICE_STATE_RESTARTING,
43 	SAL_SERVICE_STATE_END
44 } sal_service_state_t;
45 
46 /**
47  *****************************************************************************
48  * @ingroup SalCtrl
49  *      Service Instance Types
50  *
51  * @description
52  *      An enumeration containing the possible types for a service.
53  *
54  *****************************************************************************/
55 typedef enum {
56 	SAL_SERVICE_TYPE_UNKNOWN = 0,
57 	/* symmetric and asymmetric crypto service */
58 	SAL_SERVICE_TYPE_CRYPTO = 1,
59 	/* compression service */
60 	SAL_SERVICE_TYPE_COMPRESSION = 2,
61 	/* inline service */
62 	SAL_SERVICE_TYPE_INLINE = 4,
63 	/* asymmetric crypto only service*/
64 	SAL_SERVICE_TYPE_CRYPTO_ASYM = 8,
65 	/* symmetric crypto only service*/
66 	SAL_SERVICE_TYPE_CRYPTO_SYM = 16,
67 	SAL_SERVICE_TYPE_QAT = 32
68 } sal_service_type_t;
69 
70 /**
71  *****************************************************************************
72  * @ingroup SalCtrl
73  *      Device generations
74  *
75  * @description
76  *      List in an enum all the QAT device generations.
77  *
78  *****************************************************************************/
79 typedef enum { GEN2, GEN3, GEN4 } sal_generation_t;
80 
81 /**
82  *****************************************************************************
83  * @ingroup SalCtrl
84  *      Generic Instance Container
85  *
86  * @description
87  *      Contains all the common information across the different instances.
88  *
89  *****************************************************************************/
90 typedef struct sal_service_s {
91 	sal_service_type_t type;
92 	/**< Service type (e.g. SAL_SERVICE_TYPE_CRYPTO)*/
93 
94 	Cpa8U state;
95 	/**< Status of the service instance
96 	   (e.g. SAL_SERVICE_STATE_INITIALIZED) */
97 
98 	Cpa32U instance;
99 	/**< Instance number */
100 
101 	CpaVirtualToPhysical virt2PhysClient;
102 	/**< Function pointer to client supplied virt_to_phys */
103 
104 	CpaStatus (*init)(icp_accel_dev_t *device,
105 			  struct sal_service_s *service);
106 	/**< Function pointer for instance INIT function */
107 	CpaStatus (*start)(icp_accel_dev_t *device,
108 			   struct sal_service_s *service);
109 	/**< Function pointer for instance START function */
110 	CpaStatus (*stop)(icp_accel_dev_t *device,
111 			  struct sal_service_s *service);
112 	/**< Function pointer for instance STOP function */
113 	CpaStatus (*shutdown)(icp_accel_dev_t *device,
114 			      struct sal_service_s *service);
115 	/**< Function pointer for instance SHUTDOWN function */
116 
117 	CpaCyInstanceNotificationCbFunc notification_cb;
118 	/**< Function pointer for instance restarting handler */
119 
120 	void *cb_tag;
121 	/**< Restarting handler priv data */
122 
123 	sal_statistics_collection_t *stats;
124 	/**< Pointer to device statistics configuration */
125 
126 	void *debug_parent_dir;
127 	/**< Pointer to parent proc dir entry */
128 
129 	CpaBoolean is_dyn;
130 
131 	Cpa32U capabilitiesMask;
132 	/**< Capabilities mask of the device */
133 
134 	Cpa32U dcExtendedFeatures;
135 	/**< Bit field of features. I.e. Compress And Verify */
136 
137 	CpaBoolean isInstanceStarted;
138 	/**< True if user called StartInstance on this instance */
139 
140 	CpaBoolean integrityCrcCheck;
141 	/** < True if the device supports end to end data integrity checks */
142 
143 	sal_generation_t gen;
144 	/** Generation of devices */
145 } sal_service_t;
146 
147 /**
148  *****************************************************************************
149  * @ingroup SalCtrl
150  *      SAL structure
151  *
152  * @description
153  *      Contains lists to crypto and compression instances.
154  *
155  *****************************************************************************/
156 typedef struct sal_s {
157 	sal_list_t *crypto_services;
158 	/**< Container of sal_crypto_service_t */
159 	sal_list_t *asym_services;
160 	/**< Container of sal_asym_service_t */
161 	sal_list_t *sym_services;
162 	/**< Container of sal_sym_service_t */
163 	sal_list_t *compression_services;
164 	/**< Container of sal_compression_service_t */
165 	debug_dir_info_t *cy_dir;
166 	/**< Container for crypto proc debug */
167 	debug_dir_info_t *asym_dir;
168 	/**< Container for asym proc debug */
169 	debug_dir_info_t *sym_dir;
170 	/**< Container for sym proc debug */
171 	debug_dir_info_t *dc_dir;
172 	/**< Container for compression proc debug */
173 	debug_file_info_t *ver_file;
174 	/**< Container for version debug file */
175 } sal_t;
176 
177 /**
178  *****************************************************************************
179  * @ingroup SalCtrl
180  *      SAL debug structure
181  *
182  * @description
183  *      Service debug handler
184  *
185  *****************************************************************************/
186 typedef struct sal_service_debug_s {
187 	icp_accel_dev_t *accel_dev;
188 	debug_file_info_t debug_file;
189 } sal_service_debug_t;
190 
191 /**
192  *******************************************************************************
193  * @ingroup SalCtrl
194  *      This macro verifies that the right service type has been passed in.
195  *
196  * @param[in] pService         pointer to service instance
197  * @param[in] service_type     service type to check againstx.
198  *
199  * @return CPA_STATUS_FAIL      Parameter is incorrect type
200   *
201  ******************************************************************************/
202 #define SAL_CHECK_INSTANCE_TYPE(pService, service_type)                        \
203 	do {                                                                   \
204 		sal_service_t *pGenericService = NULL;                         \
205 		pGenericService = (sal_service_t *)pService;                   \
206 		if (!(service_type & pGenericService->type)) {                 \
207 			QAT_UTILS_LOG("Instance handle type is incorrect.\n"); \
208 			return CPA_STATUS_FAIL;                                \
209 		}                                                              \
210 	} while (0)
211 
212 #endif
213