1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) */
2 /* Copyright(c) 2014 - 2021 Intel Corporation */
3 #ifndef ADF_DRV_H
4 #define ADF_DRV_H
5
6 #include <linux/list.h>
7 #include <linux/pci.h>
8 #include "adf_accel_devices.h"
9 #include "icp_qat_fw_loader_handle.h"
10 #include "icp_qat_hal.h"
11
12 #define ADF_MAJOR_VERSION 0
13 #define ADF_MINOR_VERSION 6
14 #define ADF_BUILD_VERSION 0
15 #define ADF_DRV_VERSION __stringify(ADF_MAJOR_VERSION) "." \
16 __stringify(ADF_MINOR_VERSION) "." \
17 __stringify(ADF_BUILD_VERSION)
18
19 #define ADF_STATUS_RESTARTING 0
20 #define ADF_STATUS_STARTING 1
21 #define ADF_STATUS_CONFIGURED 2
22 #define ADF_STATUS_STARTED 3
23 #define ADF_STATUS_AE_INITIALISED 4
24 #define ADF_STATUS_AE_UCODE_LOADED 5
25 #define ADF_STATUS_AE_STARTED 6
26 #define ADF_STATUS_PF_RUNNING 7
27 #define ADF_STATUS_IRQ_ALLOCATED 8
28 #define ADF_STATUS_CRYPTO_ALGS_REGISTERED 9
29
30 enum adf_dev_reset_mode {
31 ADF_DEV_RESET_ASYNC = 0,
32 ADF_DEV_RESET_SYNC
33 };
34
35 enum adf_event {
36 ADF_EVENT_INIT = 0,
37 ADF_EVENT_START,
38 ADF_EVENT_STOP,
39 ADF_EVENT_SHUTDOWN,
40 ADF_EVENT_RESTARTING,
41 ADF_EVENT_RESTARTED,
42 };
43
44 struct service_hndl {
45 int (*event_hld)(struct adf_accel_dev *accel_dev,
46 enum adf_event event);
47 unsigned long init_status[ADF_DEVS_ARRAY_SIZE];
48 unsigned long start_status[ADF_DEVS_ARRAY_SIZE];
49 char *name;
50 struct list_head list;
51 };
52
53 int adf_service_register(struct service_hndl *service);
54 int adf_service_unregister(struct service_hndl *service);
55
56 int adf_dev_init(struct adf_accel_dev *accel_dev);
57 int adf_dev_start(struct adf_accel_dev *accel_dev);
58 void adf_dev_stop(struct adf_accel_dev *accel_dev);
59 void adf_dev_shutdown(struct adf_accel_dev *accel_dev);
60 int adf_dev_shutdown_cache_cfg(struct adf_accel_dev *accel_dev);
61
62 int adf_dev_up(struct adf_accel_dev *accel_dev, bool init_config);
63 int adf_dev_down(struct adf_accel_dev *accel_dev, bool cache_config);
64
65 void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data);
66 void adf_clean_vf_map(bool);
67
68 int adf_ctl_dev_register(void);
69 void adf_ctl_dev_unregister(void);
70 int adf_processes_dev_register(void);
71 void adf_processes_dev_unregister(void);
72
73 int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev,
74 struct adf_accel_dev *pf);
75 void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev,
76 struct adf_accel_dev *pf);
77 struct list_head *adf_devmgr_get_head(void);
78 struct adf_accel_dev *adf_devmgr_get_dev_by_id(u32 id);
79 struct adf_accel_dev *adf_devmgr_get_first(void);
80 struct adf_accel_dev *adf_devmgr_pci_to_accel_dev(struct pci_dev *pci_dev);
81 int adf_devmgr_verify_id(u32 id);
82 void adf_devmgr_get_num_dev(u32 *num);
83 int adf_devmgr_in_reset(struct adf_accel_dev *accel_dev);
84 int adf_dev_started(struct adf_accel_dev *accel_dev);
85 int adf_dev_restarting_notify(struct adf_accel_dev *accel_dev);
86 int adf_dev_restarted_notify(struct adf_accel_dev *accel_dev);
87 int adf_ae_init(struct adf_accel_dev *accel_dev);
88 int adf_ae_shutdown(struct adf_accel_dev *accel_dev);
89 int adf_ae_fw_load(struct adf_accel_dev *accel_dev);
90 void adf_ae_fw_release(struct adf_accel_dev *accel_dev);
91 int adf_ae_start(struct adf_accel_dev *accel_dev);
92 int adf_ae_stop(struct adf_accel_dev *accel_dev);
93
94 extern const struct pci_error_handlers adf_err_handler;
95 void adf_enable_aer(struct adf_accel_dev *accel_dev);
96 void adf_disable_aer(struct adf_accel_dev *accel_dev);
97 void adf_reset_sbr(struct adf_accel_dev *accel_dev);
98 void adf_reset_flr(struct adf_accel_dev *accel_dev);
99 void adf_dev_restore(struct adf_accel_dev *accel_dev);
100 int adf_init_aer(void);
101 void adf_exit_aer(void);
102 int adf_init_admin_comms(struct adf_accel_dev *accel_dev);
103 void adf_exit_admin_comms(struct adf_accel_dev *accel_dev);
104 int adf_send_admin_init(struct adf_accel_dev *accel_dev);
105 int adf_init_admin_pm(struct adf_accel_dev *accel_dev, u32 idle_delay);
106 int adf_init_arb(struct adf_accel_dev *accel_dev);
107 void adf_exit_arb(struct adf_accel_dev *accel_dev);
108 void adf_update_ring_arb(struct adf_etr_ring_data *ring);
109
110 int adf_dev_get(struct adf_accel_dev *accel_dev);
111 void adf_dev_put(struct adf_accel_dev *accel_dev);
112 int adf_dev_in_use(struct adf_accel_dev *accel_dev);
113 int adf_init_etr_data(struct adf_accel_dev *accel_dev);
114 void adf_cleanup_etr_data(struct adf_accel_dev *accel_dev);
115 int qat_crypto_register(void);
116 int qat_crypto_unregister(void);
117 int qat_crypto_dev_config(struct adf_accel_dev *accel_dev);
118 int qat_crypto_vf_dev_config(struct adf_accel_dev *accel_dev);
119 struct qat_crypto_instance *qat_crypto_get_instance_node(int node);
120 void qat_crypto_put_instance(struct qat_crypto_instance *inst);
121 void qat_alg_callback(void *resp);
122 void qat_alg_asym_callback(void *resp);
123 int qat_algs_register(void);
124 void qat_algs_unregister(void);
125 int qat_asym_algs_register(void);
126 void qat_asym_algs_unregister(void);
127
128 int adf_isr_resource_alloc(struct adf_accel_dev *accel_dev);
129 void adf_isr_resource_free(struct adf_accel_dev *accel_dev);
130 int adf_vf_isr_resource_alloc(struct adf_accel_dev *accel_dev);
131 void adf_vf_isr_resource_free(struct adf_accel_dev *accel_dev);
132
133 int adf_pfvf_comms_disabled(struct adf_accel_dev *accel_dev);
134
135 int adf_sysfs_init(struct adf_accel_dev *accel_dev);
136
137 int qat_hal_init(struct adf_accel_dev *accel_dev);
138 void qat_hal_deinit(struct icp_qat_fw_loader_handle *handle);
139 int qat_hal_start(struct icp_qat_fw_loader_handle *handle);
140 void qat_hal_stop(struct icp_qat_fw_loader_handle *handle, unsigned char ae,
141 unsigned int ctx_mask);
142 void qat_hal_reset(struct icp_qat_fw_loader_handle *handle);
143 int qat_hal_clr_reset(struct icp_qat_fw_loader_handle *handle);
144 void qat_hal_set_live_ctx(struct icp_qat_fw_loader_handle *handle,
145 unsigned char ae, unsigned int ctx_mask);
146 int qat_hal_check_ae_active(struct icp_qat_fw_loader_handle *handle,
147 unsigned int ae);
148 int qat_hal_set_ae_lm_mode(struct icp_qat_fw_loader_handle *handle,
149 unsigned char ae, enum icp_qat_uof_regtype lm_type,
150 unsigned char mode);
151 int qat_hal_set_ae_ctx_mode(struct icp_qat_fw_loader_handle *handle,
152 unsigned char ae, unsigned char mode);
153 int qat_hal_set_ae_nn_mode(struct icp_qat_fw_loader_handle *handle,
154 unsigned char ae, unsigned char mode);
155 void qat_hal_set_pc(struct icp_qat_fw_loader_handle *handle,
156 unsigned char ae, unsigned int ctx_mask, unsigned int upc);
157 void qat_hal_wr_uwords(struct icp_qat_fw_loader_handle *handle,
158 unsigned char ae, unsigned int uaddr,
159 unsigned int words_num, u64 *uword);
160 void qat_hal_wr_umem(struct icp_qat_fw_loader_handle *handle, unsigned char ae,
161 unsigned int uword_addr, unsigned int words_num,
162 unsigned int *data);
163 int qat_hal_get_ins_num(void);
164 int qat_hal_batch_wr_lm(struct icp_qat_fw_loader_handle *handle,
165 unsigned char ae,
166 struct icp_qat_uof_batch_init *lm_init_header);
167 int qat_hal_init_gpr(struct icp_qat_fw_loader_handle *handle,
168 unsigned char ae, unsigned long ctx_mask,
169 enum icp_qat_uof_regtype reg_type,
170 unsigned short reg_num, unsigned int regdata);
171 int qat_hal_init_wr_xfer(struct icp_qat_fw_loader_handle *handle,
172 unsigned char ae, unsigned long ctx_mask,
173 enum icp_qat_uof_regtype reg_type,
174 unsigned short reg_num, unsigned int regdata);
175 int qat_hal_init_rd_xfer(struct icp_qat_fw_loader_handle *handle,
176 unsigned char ae, unsigned long ctx_mask,
177 enum icp_qat_uof_regtype reg_type,
178 unsigned short reg_num, unsigned int regdata);
179 int qat_hal_init_nn(struct icp_qat_fw_loader_handle *handle,
180 unsigned char ae, unsigned long ctx_mask,
181 unsigned short reg_num, unsigned int regdata);
182 int qat_hal_wr_lm(struct icp_qat_fw_loader_handle *handle,
183 unsigned char ae, unsigned short lm_addr, unsigned int value);
184 void qat_hal_set_ae_tindex_mode(struct icp_qat_fw_loader_handle *handle,
185 unsigned char ae, unsigned char mode);
186 int qat_uclo_wr_all_uimage(struct icp_qat_fw_loader_handle *handle);
187 void qat_uclo_del_obj(struct icp_qat_fw_loader_handle *handle);
188 int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle, void *addr_ptr,
189 int mem_size);
190 int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle,
191 void *addr_ptr, u32 mem_size, char *obj_name);
192 int qat_uclo_set_cfg_ae_mask(struct icp_qat_fw_loader_handle *handle,
193 unsigned int cfg_ae_mask);
194 int adf_init_misc_wq(void);
195 void adf_exit_misc_wq(void);
196 bool adf_misc_wq_queue_work(struct work_struct *work);
197 #if defined(CONFIG_PCI_IOV)
198 int adf_sriov_configure(struct pci_dev *pdev, int numvfs);
199 void adf_disable_sriov(struct adf_accel_dev *accel_dev);
200 void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, u32 vf_mask);
201 void adf_disable_all_vf2pf_interrupts(struct adf_accel_dev *accel_dev);
202 bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev);
203 bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr);
204 int adf_pf2vf_handle_pf_restarting(struct adf_accel_dev *accel_dev);
205 void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
206 void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev);
207 void adf_schedule_vf2pf_handler(struct adf_accel_vf_info *vf_info);
208 int adf_init_pf_wq(void);
209 void adf_exit_pf_wq(void);
210 int adf_init_vf_wq(void);
211 void adf_exit_vf_wq(void);
212 void adf_flush_vf_wq(struct adf_accel_dev *accel_dev);
213 #else
214 #define adf_sriov_configure NULL
215
adf_disable_sriov(struct adf_accel_dev * accel_dev)216 static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev)
217 {
218 }
219
adf_init_pf_wq(void)220 static inline int adf_init_pf_wq(void)
221 {
222 return 0;
223 }
224
adf_exit_pf_wq(void)225 static inline void adf_exit_pf_wq(void)
226 {
227 }
228
adf_init_vf_wq(void)229 static inline int adf_init_vf_wq(void)
230 {
231 return 0;
232 }
233
adf_exit_vf_wq(void)234 static inline void adf_exit_vf_wq(void)
235 {
236 }
237
238 #endif
239
adf_get_pmisc_base(struct adf_accel_dev * accel_dev)240 static inline void __iomem *adf_get_pmisc_base(struct adf_accel_dev *accel_dev)
241 {
242 struct adf_hw_device_data *hw_data = accel_dev->hw_device;
243 struct adf_bar *pmisc;
244
245 pmisc = &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)];
246
247 return pmisc->virt_addr;
248 }
249
250 #endif
251