xref: /freebsd/sys/dev/qat/include/common/adf_common_drv.h (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 #ifndef ADF_DRV_H
5 #define ADF_DRV_H
6 
7 #include <dev/pci/pcivar.h>
8 #include "adf_accel_devices.h"
9 #include "icp_qat_fw_loader_handle.h"
10 #include "icp_qat_hal.h"
11 #include "adf_cfg_user.h"
12 
13 #define ADF_MAJOR_VERSION 0
14 #define ADF_MINOR_VERSION 6
15 #define ADF_BUILD_VERSION 0
16 #define ADF_DRV_VERSION                                                        \
17 	__stringify(ADF_MAJOR_VERSION) "." __stringify(                        \
18 	    ADF_MINOR_VERSION) "." __stringify(ADF_BUILD_VERSION)
19 
20 #define ADF_STATUS_RESTARTING 0
21 #define ADF_STATUS_STARTING 1
22 #define ADF_STATUS_CONFIGURED 2
23 #define ADF_STATUS_STARTED 3
24 #define ADF_STATUS_AE_INITIALISED 4
25 #define ADF_STATUS_AE_UCODE_LOADED 5
26 #define ADF_STATUS_AE_STARTED 6
27 #define ADF_STATUS_PF_RUNNING 7
28 #define ADF_STATUS_IRQ_ALLOCATED 8
29 #define ADF_PCIE_FLR_ATTEMPT 10
30 #define ADF_STATUS_SYSCTL_CTX_INITIALISED 9
31 
32 #define PCI_EXP_AERUCS 0x104
33 
34 /* PMISC BAR upper and lower offsets in PCIe config space */
35 #define ADF_PMISC_L_OFFSET 0x18
36 #define ADF_PMISC_U_OFFSET 0x1c
37 
38 enum adf_dev_reset_mode { ADF_DEV_RESET_ASYNC = 0, ADF_DEV_RESET_SYNC };
39 
40 enum adf_event {
41 	ADF_EVENT_INIT = 0,
42 	ADF_EVENT_START,
43 	ADF_EVENT_STOP,
44 	ADF_EVENT_SHUTDOWN,
45 	ADF_EVENT_RESTARTING,
46 	ADF_EVENT_RESTARTED,
47 	ADF_EVENT_ERROR,
48 };
49 
50 struct adf_state {
51 	enum adf_event dev_state;
52 	int dev_id;
53 };
54 
55 struct service_hndl {
56 	int (*event_hld)(struct adf_accel_dev *accel_dev, enum adf_event event);
57 	unsigned long init_status[ADF_DEVS_ARRAY_SIZE];
58 	unsigned long start_status[ADF_DEVS_ARRAY_SIZE];
59 	char *name;
60 	struct list_head list;
61 };
62 
63 static inline int
64 get_current_node(void)
65 {
66 	return PCPU_GET(domain);
67 }
68 
69 int adf_service_register(struct service_hndl *service);
70 int adf_service_unregister(struct service_hndl *service);
71 
72 int adf_dev_init(struct adf_accel_dev *accel_dev);
73 int adf_dev_start(struct adf_accel_dev *accel_dev);
74 int adf_dev_stop(struct adf_accel_dev *accel_dev);
75 void adf_dev_shutdown(struct adf_accel_dev *accel_dev);
76 int adf_dev_autoreset(struct adf_accel_dev *accel_dev);
77 int adf_dev_reset(struct adf_accel_dev *accel_dev,
78 		  enum adf_dev_reset_mode mode);
79 int adf_dev_aer_schedule_reset(struct adf_accel_dev *accel_dev,
80 			       enum adf_dev_reset_mode mode);
81 void adf_error_notifier(uintptr_t arg);
82 int adf_init_fatal_error_wq(void);
83 void adf_exit_fatal_error_wq(void);
84 int adf_iov_putmsg(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr);
85 int adf_iov_notify(struct adf_accel_dev *accel_dev, u32 msg, u8 vf_nr);
86 void adf_pf2vf_notify_restarting(struct adf_accel_dev *accel_dev);
87 int adf_notify_fatal_error(struct adf_accel_dev *accel_dev);
88 void adf_pf2vf_notify_fatal_error(struct adf_accel_dev *accel_dev);
89 void adf_pf2vf_notify_uncorrectable_error(struct adf_accel_dev *accel_dev);
90 void adf_pf2vf_notify_heartbeat_error(struct adf_accel_dev *accel_dev);
91 typedef int (*adf_iov_block_provider)(struct adf_accel_dev *accel_dev,
92 				      u8 **buffer,
93 				      u8 *length,
94 				      u8 *block_version,
95 				      u8 compatibility,
96 				      u8 byte_num);
97 int adf_iov_block_provider_register(u8 block_type,
98 				    const adf_iov_block_provider provider);
99 u8 adf_iov_is_block_provider_registered(u8 block_type);
100 int adf_iov_block_provider_unregister(u8 block_type,
101 				      const adf_iov_block_provider provider);
102 int adf_iov_block_get(struct adf_accel_dev *accel_dev,
103 		      u8 block_type,
104 		      u8 *block_version,
105 		      u8 *buffer,
106 		      u8 *length);
107 u8 adf_pfvf_crc(u8 start_crc, u8 *buf, u8 len);
108 int adf_iov_init_compat_manager(struct adf_accel_dev *accel_dev,
109 				struct adf_accel_compat_manager **cm);
110 int adf_iov_shutdown_compat_manager(struct adf_accel_dev *accel_dev,
111 				    struct adf_accel_compat_manager **cm);
112 int adf_iov_register_compat_checker(struct adf_accel_dev *accel_dev,
113 				    const adf_iov_compat_checker_t cc);
114 int adf_iov_unregister_compat_checker(struct adf_accel_dev *accel_dev,
115 				      const adf_iov_compat_checker_t cc);
116 int adf_pf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev);
117 int adf_pf_disable_vf2pf_comms(struct adf_accel_dev *accel_dev);
118 int adf_enable_vf2pf_comms(struct adf_accel_dev *accel_dev);
119 int adf_disable_vf2pf_comms(struct adf_accel_dev *accel_dev);
120 void adf_vf2pf_req_hndl(struct adf_accel_vf_info *vf_info);
121 void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
122 void adf_clean_vf_map(bool);
123 int adf_sysctl_add_fw_versions(struct adf_accel_dev *accel_dev);
124 int adf_sysctl_remove_fw_versions(struct adf_accel_dev *accel_dev);
125 
126 int adf_ctl_dev_register(void);
127 void adf_ctl_dev_unregister(void);
128 int adf_pf_vf_capabilities_init(struct adf_accel_dev *accel_dev);
129 int adf_pf_ext_dc_cap_msg_provider(struct adf_accel_dev *accel_dev,
130 				   u8 **buffer,
131 				   u8 *length,
132 				   u8 *block_version,
133 				   u8 compatibility);
134 int adf_pf_vf_ring_to_svc_init(struct adf_accel_dev *accel_dev);
135 int adf_pf_ring_to_svc_msg_provider(struct adf_accel_dev *accel_dev,
136 				    u8 **buffer,
137 				    u8 *length,
138 				    u8 *block_version,
139 				    u8 compatibility,
140 				    u8 byte_num);
141 int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,
142 		       struct adf_accel_dev *pf);
143 void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev,
144 		       struct adf_accel_dev *pf);
145 struct list_head *adf_devmgr_get_head(void);
146 struct adf_accel_dev *adf_devmgr_get_dev_by_id(uint32_t id);
147 struct adf_accel_dev *adf_devmgr_get_first(void);
148 struct adf_accel_dev *adf_devmgr_pci_to_accel_dev(device_t pci_dev);
149 int adf_devmgr_verify_id(uint32_t *id);
150 void adf_devmgr_get_num_dev(uint32_t *num);
151 int adf_devmgr_in_reset(struct adf_accel_dev *accel_dev);
152 int adf_dev_started(struct adf_accel_dev *accel_dev);
153 int adf_dev_restarting_notify(struct adf_accel_dev *accel_dev);
154 int adf_dev_restarting_notify_sync(struct adf_accel_dev *accel_dev);
155 int adf_dev_restarted_notify(struct adf_accel_dev *accel_dev);
156 int adf_dev_stop_notify_sync(struct adf_accel_dev *accel_dev);
157 int adf_ae_init(struct adf_accel_dev *accel_dev);
158 int adf_ae_shutdown(struct adf_accel_dev *accel_dev);
159 int adf_ae_fw_load(struct adf_accel_dev *accel_dev);
160 void adf_ae_fw_release(struct adf_accel_dev *accel_dev);
161 int adf_ae_start(struct adf_accel_dev *accel_dev);
162 int adf_ae_stop(struct adf_accel_dev *accel_dev);
163 
164 int adf_aer_store_ppaerucm_reg(device_t pdev,
165 			       struct adf_hw_device_data *hw_data);
166 
167 int adf_enable_aer(struct adf_accel_dev *accel_dev, device_t *adf);
168 void adf_disable_aer(struct adf_accel_dev *accel_dev);
169 void adf_reset_sbr(struct adf_accel_dev *accel_dev);
170 void adf_reset_flr(struct adf_accel_dev *accel_dev);
171 void adf_dev_pre_reset(struct adf_accel_dev *accel_dev);
172 void adf_dev_post_reset(struct adf_accel_dev *accel_dev);
173 void adf_dev_restore(struct adf_accel_dev *accel_dev);
174 int adf_init_aer(void);
175 void adf_exit_aer(void);
176 int adf_put_admin_msg_sync(struct adf_accel_dev *accel_dev,
177 			   u32 ae,
178 			   void *in,
179 			   void *out);
180 struct icp_qat_fw_init_admin_req;
181 struct icp_qat_fw_init_admin_resp;
182 int adf_send_admin(struct adf_accel_dev *accel_dev,
183 		   struct icp_qat_fw_init_admin_req *req,
184 		   struct icp_qat_fw_init_admin_resp *resp,
185 		   u32 ae_mask);
186 int adf_config_device(struct adf_accel_dev *accel_dev);
187 
188 int adf_init_admin_comms(struct adf_accel_dev *accel_dev);
189 void adf_exit_admin_comms(struct adf_accel_dev *accel_dev);
190 int adf_send_admin_init(struct adf_accel_dev *accel_dev);
191 int adf_get_fw_timestamp(struct adf_accel_dev *accel_dev, u64 *timestamp);
192 int adf_get_fw_pke_stats(struct adf_accel_dev *accel_dev,
193 			 u64 *suc_count,
194 			 u64 *unsuc_count);
195 int adf_dev_measure_clock(struct adf_accel_dev *accel_dev,
196 			  u32 *frequency,
197 			  u32 min,
198 			  u32 max);
199 int adf_clock_debugfs_add(struct adf_accel_dev *accel_dev);
200 u64 adf_clock_get_current_time(void);
201 int adf_init_arb(struct adf_accel_dev *accel_dev);
202 int adf_init_gen2_arb(struct adf_accel_dev *accel_dev);
203 void adf_exit_arb(struct adf_accel_dev *accel_dev);
204 void adf_disable_arb(struct adf_accel_dev *accel_dev);
205 void adf_update_ring_arb(struct adf_etr_ring_data *ring);
206 void
207 adf_enable_ring_arb(void *csr_addr, unsigned int bank_nr, unsigned int mask);
208 void
209 adf_disable_ring_arb(void *csr_addr, unsigned int bank_nr, unsigned int mask);
210 int adf_set_ssm_wdtimer(struct adf_accel_dev *accel_dev);
211 struct adf_accel_dev *adf_devmgr_get_dev_by_bdf(struct adf_pci_address *addr);
212 struct adf_accel_dev *adf_devmgr_get_dev_by_pci_bus(u8 bus);
213 int adf_get_vf_nr(struct adf_pci_address *vf_pci_addr, int *vf_nr);
214 u32 adf_get_slices_for_svc(struct adf_accel_dev *accel_dev,
215 			   enum adf_svc_type svc);
216 bool adf_is_bdf_equal(struct adf_pci_address *bdf1,
217 		      struct adf_pci_address *bdf2);
218 int adf_is_vf_nr_valid(struct adf_accel_dev *accel_dev, int vf_nr);
219 void adf_dev_get(struct adf_accel_dev *accel_dev);
220 void adf_dev_put(struct adf_accel_dev *accel_dev);
221 int adf_dev_in_use(struct adf_accel_dev *accel_dev);
222 int adf_init_etr_data(struct adf_accel_dev *accel_dev);
223 void adf_cleanup_etr_data(struct adf_accel_dev *accel_dev);
224 
225 struct qat_crypto_instance *qat_crypto_get_instance_node(int node);
226 void qat_crypto_put_instance(struct qat_crypto_instance *inst);
227 void qat_alg_callback(void *resp);
228 void qat_alg_asym_callback(void *resp);
229 int qat_algs_register(void);
230 void qat_algs_unregister(void);
231 int qat_asym_algs_register(void);
232 void qat_asym_algs_unregister(void);
233 
234 int adf_isr_resource_alloc(struct adf_accel_dev *accel_dev);
235 void adf_isr_resource_free(struct adf_accel_dev *accel_dev);
236 int adf_vf_isr_resource_alloc(struct adf_accel_dev *accel_dev);
237 void adf_vf_isr_resource_free(struct adf_accel_dev *accel_dev);
238 
239 int qat_hal_init(struct adf_accel_dev *accel_dev);
240 void qat_hal_deinit(struct icp_qat_fw_loader_handle *handle);
241 void qat_hal_start(struct icp_qat_fw_loader_handle *handle,
242 		   unsigned char ae,
243 		   unsigned int ctx_mask);
244 void qat_hal_stop(struct icp_qat_fw_loader_handle *handle,
245 		  unsigned char ae,
246 		  unsigned int ctx_mask);
247 void qat_hal_reset(struct icp_qat_fw_loader_handle *handle);
248 int qat_hal_clr_reset(struct icp_qat_fw_loader_handle *handle);
249 void qat_hal_set_live_ctx(struct icp_qat_fw_loader_handle *handle,
250 			  unsigned char ae,
251 			  unsigned int ctx_mask);
252 int qat_hal_check_ae_active(struct icp_qat_fw_loader_handle *handle,
253 			    unsigned int ae);
254 int qat_hal_set_ae_lm_mode(struct icp_qat_fw_loader_handle *handle,
255 			   unsigned char ae,
256 			   enum icp_qat_uof_regtype lm_type,
257 			   unsigned char mode);
258 void qat_hal_set_ae_tindex_mode(struct icp_qat_fw_loader_handle *handle,
259 				unsigned char ae,
260 				unsigned char mode);
261 void qat_hal_set_ae_scs_mode(struct icp_qat_fw_loader_handle *handle,
262 			     unsigned char ae,
263 			     unsigned char mode);
264 int qat_hal_set_ae_ctx_mode(struct icp_qat_fw_loader_handle *handle,
265 			    unsigned char ae,
266 			    unsigned char mode);
267 int qat_hal_set_ae_nn_mode(struct icp_qat_fw_loader_handle *handle,
268 			   unsigned char ae,
269 			   unsigned char mode);
270 void qat_hal_set_pc(struct icp_qat_fw_loader_handle *handle,
271 		    unsigned char ae,
272 		    unsigned int ctx_mask,
273 		    unsigned int upc);
274 void qat_hal_wr_uwords(struct icp_qat_fw_loader_handle *handle,
275 		       unsigned char ae,
276 		       unsigned int uaddr,
277 		       unsigned int words_num,
278 		       const uint64_t *uword);
279 void qat_hal_wr_coalesce_uwords(struct icp_qat_fw_loader_handle *handle,
280 				unsigned char ae,
281 				unsigned int uaddr,
282 				unsigned int words_num,
283 				uint64_t *uword);
284 
285 void qat_hal_wr_umem(struct icp_qat_fw_loader_handle *handle,
286 		     unsigned char ae,
287 		     unsigned int uword_addr,
288 		     unsigned int words_num,
289 		     unsigned int *data);
290 int qat_hal_get_ins_num(void);
291 int qat_hal_batch_wr_lm(struct icp_qat_fw_loader_handle *handle,
292 			unsigned char ae,
293 			struct icp_qat_uof_batch_init *lm_init_header);
294 int qat_hal_init_gpr(struct icp_qat_fw_loader_handle *handle,
295 		     unsigned char ae,
296 		     unsigned long ctx_mask,
297 		     enum icp_qat_uof_regtype reg_type,
298 		     unsigned short reg_num,
299 		     unsigned int regdata);
300 int qat_hal_init_wr_xfer(struct icp_qat_fw_loader_handle *handle,
301 			 unsigned char ae,
302 			 unsigned long ctx_mask,
303 			 enum icp_qat_uof_regtype reg_type,
304 			 unsigned short reg_num,
305 			 unsigned int regdata);
306 int qat_hal_init_rd_xfer(struct icp_qat_fw_loader_handle *handle,
307 			 unsigned char ae,
308 			 unsigned long ctx_mask,
309 			 enum icp_qat_uof_regtype reg_type,
310 			 unsigned short reg_num,
311 			 unsigned int regdata);
312 int qat_hal_init_nn(struct icp_qat_fw_loader_handle *handle,
313 		    unsigned char ae,
314 		    unsigned long ctx_mask,
315 		    unsigned short reg_num,
316 		    unsigned int regdata);
317 int qat_hal_wr_lm(struct icp_qat_fw_loader_handle *handle,
318 		  unsigned char ae,
319 		  unsigned short lm_addr,
320 		  unsigned int value);
321 int qat_uclo_wr_all_uimage(struct icp_qat_fw_loader_handle *handle);
322 void qat_uclo_del_obj(struct icp_qat_fw_loader_handle *handle);
323 void qat_uclo_del_mof(struct icp_qat_fw_loader_handle *handle);
324 int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle,
325 		       const void *addr_ptr,
326 		       int mem_size);
327 int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle,
328 		     const void *addr_ptr,
329 		     u32 mem_size,
330 		     const char *obj_name);
331 
332 void qat_hal_get_scs_neigh_ae(unsigned char ae, unsigned char *ae_neigh);
333 int qat_uclo_set_cfg_ae_mask(struct icp_qat_fw_loader_handle *handle,
334 			     unsigned int cfg_ae_mask);
335 void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
336 void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
337 int adf_init_vf_wq(void);
338 void adf_exit_vf_wq(void);
339 void adf_flush_vf_wq(void);
340 int adf_vf2pf_init(struct adf_accel_dev *accel_dev);
341 void adf_vf2pf_shutdown(struct adf_accel_dev *accel_dev);
342 static inline int
343 adf_sriov_configure(device_t *pdev, int numvfs)
344 {
345 	return 0;
346 }
347 
348 static inline void
349 adf_disable_sriov(struct adf_accel_dev *accel_dev)
350 {
351 }
352 
353 static inline void
354 adf_vf2pf_handler(struct adf_accel_vf_info *vf_info)
355 {
356 }
357 
358 static inline int
359 adf_init_pf_wq(void)
360 {
361 	return 0;
362 }
363 
364 static inline void
365 adf_exit_pf_wq(void)
366 {
367 }
368 #endif
369