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