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 29 enum adf_dev_reset_mode { 30 ADF_DEV_RESET_ASYNC = 0, 31 ADF_DEV_RESET_SYNC 32 }; 33 34 enum adf_event { 35 ADF_EVENT_INIT = 0, 36 ADF_EVENT_START, 37 ADF_EVENT_STOP, 38 ADF_EVENT_SHUTDOWN, 39 ADF_EVENT_RESTARTING, 40 ADF_EVENT_RESTARTED, 41 }; 42 43 struct service_hndl { 44 int (*event_hld)(struct adf_accel_dev *accel_dev, 45 enum adf_event event); 46 unsigned long init_status[ADF_DEVS_ARRAY_SIZE]; 47 unsigned long start_status[ADF_DEVS_ARRAY_SIZE]; 48 char *name; 49 struct list_head list; 50 }; 51 52 int adf_service_register(struct service_hndl *service); 53 int adf_service_unregister(struct service_hndl *service); 54 55 int adf_dev_up(struct adf_accel_dev *accel_dev, bool init_config); 56 int adf_dev_down(struct adf_accel_dev *accel_dev, bool cache_config); 57 int adf_dev_restart(struct adf_accel_dev *accel_dev); 58 59 void adf_devmgr_update_class_index(struct adf_hw_device_data *hw_data); 60 void adf_clean_vf_map(bool); 61 int adf_devmgr_add_dev(struct adf_accel_dev *accel_dev, 62 struct adf_accel_dev *pf); 63 void adf_devmgr_rm_dev(struct adf_accel_dev *accel_dev, 64 struct adf_accel_dev *pf); 65 struct list_head *adf_devmgr_get_head(void); 66 struct adf_accel_dev *adf_devmgr_get_dev_by_id(u32 id); 67 struct adf_accel_dev *adf_devmgr_get_first(void); 68 struct adf_accel_dev *adf_devmgr_pci_to_accel_dev(struct pci_dev *pci_dev); 69 int adf_devmgr_verify_id(u32 id); 70 void adf_devmgr_get_num_dev(u32 *num); 71 int adf_devmgr_in_reset(struct adf_accel_dev *accel_dev); 72 int adf_dev_started(struct adf_accel_dev *accel_dev); 73 int adf_dev_restarting_notify(struct adf_accel_dev *accel_dev); 74 int adf_dev_restarted_notify(struct adf_accel_dev *accel_dev); 75 int adf_ae_init(struct adf_accel_dev *accel_dev); 76 int adf_ae_shutdown(struct adf_accel_dev *accel_dev); 77 int adf_ae_fw_load(struct adf_accel_dev *accel_dev); 78 void adf_ae_fw_release(struct adf_accel_dev *accel_dev); 79 int adf_ae_start(struct adf_accel_dev *accel_dev); 80 int adf_ae_stop(struct adf_accel_dev *accel_dev); 81 82 extern const struct pci_error_handlers adf_err_handler; 83 void adf_reset_sbr(struct adf_accel_dev *accel_dev); 84 void adf_reset_flr(struct adf_accel_dev *accel_dev); 85 void adf_dev_restore(struct adf_accel_dev *accel_dev); 86 int adf_init_aer(void); 87 void adf_exit_aer(void); 88 int adf_init_admin_comms(struct adf_accel_dev *accel_dev); 89 void adf_exit_admin_comms(struct adf_accel_dev *accel_dev); 90 int adf_send_admin_init(struct adf_accel_dev *accel_dev); 91 int adf_get_ae_fw_counters(struct adf_accel_dev *accel_dev, u16 ae, u64 *reqs, u64 *resps); 92 int adf_init_admin_pm(struct adf_accel_dev *accel_dev, u32 idle_delay); 93 int adf_send_admin_tim_sync(struct adf_accel_dev *accel_dev, u32 cnt); 94 int adf_send_admin_hb_timer(struct adf_accel_dev *accel_dev, uint32_t ticks); 95 int adf_get_fw_timestamp(struct adf_accel_dev *accel_dev, u64 *timestamp); 96 int adf_init_arb(struct adf_accel_dev *accel_dev); 97 void adf_exit_arb(struct adf_accel_dev *accel_dev); 98 void adf_update_ring_arb(struct adf_etr_ring_data *ring); 99 100 int adf_dev_get(struct adf_accel_dev *accel_dev); 101 void adf_dev_put(struct adf_accel_dev *accel_dev); 102 int adf_dev_in_use(struct adf_accel_dev *accel_dev); 103 int adf_init_etr_data(struct adf_accel_dev *accel_dev); 104 void adf_cleanup_etr_data(struct adf_accel_dev *accel_dev); 105 int qat_crypto_register(void); 106 int qat_crypto_unregister(void); 107 int qat_crypto_vf_dev_config(struct adf_accel_dev *accel_dev); 108 struct qat_crypto_instance *qat_crypto_get_instance_node(int node); 109 void qat_crypto_put_instance(struct qat_crypto_instance *inst); 110 void qat_alg_callback(void *resp); 111 void qat_alg_asym_callback(void *resp); 112 int qat_algs_register(void); 113 void qat_algs_unregister(void); 114 int qat_asym_algs_register(void); 115 void qat_asym_algs_unregister(void); 116 117 struct qat_compression_instance *qat_compression_get_instance_node(int node); 118 void qat_compression_put_instance(struct qat_compression_instance *inst); 119 int qat_compression_register(void); 120 int qat_compression_unregister(void); 121 int qat_comp_algs_register(void); 122 void qat_comp_algs_unregister(void); 123 void qat_comp_alg_callback(void *resp); 124 125 int adf_isr_resource_alloc(struct adf_accel_dev *accel_dev); 126 void adf_isr_resource_free(struct adf_accel_dev *accel_dev); 127 int adf_vf_isr_resource_alloc(struct adf_accel_dev *accel_dev); 128 void adf_vf_isr_resource_free(struct adf_accel_dev *accel_dev); 129 130 int adf_pfvf_comms_disabled(struct adf_accel_dev *accel_dev); 131 132 int adf_sysfs_init(struct adf_accel_dev *accel_dev); 133 134 int qat_hal_init(struct adf_accel_dev *accel_dev); 135 void qat_hal_deinit(struct icp_qat_fw_loader_handle *handle); 136 int qat_hal_start(struct icp_qat_fw_loader_handle *handle); 137 void qat_hal_stop(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 138 unsigned int ctx_mask); 139 void qat_hal_reset(struct icp_qat_fw_loader_handle *handle); 140 int qat_hal_clr_reset(struct icp_qat_fw_loader_handle *handle); 141 void qat_hal_set_live_ctx(struct icp_qat_fw_loader_handle *handle, 142 unsigned char ae, unsigned int ctx_mask); 143 int qat_hal_check_ae_active(struct icp_qat_fw_loader_handle *handle, 144 unsigned int ae); 145 int qat_hal_set_ae_lm_mode(struct icp_qat_fw_loader_handle *handle, 146 unsigned char ae, enum icp_qat_uof_regtype lm_type, 147 unsigned char mode); 148 int qat_hal_set_ae_ctx_mode(struct icp_qat_fw_loader_handle *handle, 149 unsigned char ae, unsigned char mode); 150 int qat_hal_set_ae_nn_mode(struct icp_qat_fw_loader_handle *handle, 151 unsigned char ae, unsigned char mode); 152 void qat_hal_set_pc(struct icp_qat_fw_loader_handle *handle, 153 unsigned char ae, unsigned int ctx_mask, unsigned int upc); 154 void qat_hal_wr_uwords(struct icp_qat_fw_loader_handle *handle, 155 unsigned char ae, unsigned int uaddr, 156 unsigned int words_num, u64 *uword); 157 void qat_hal_wr_umem(struct icp_qat_fw_loader_handle *handle, unsigned char ae, 158 unsigned int uword_addr, unsigned int words_num, 159 unsigned int *data); 160 int qat_hal_get_ins_num(void); 161 int qat_hal_batch_wr_lm(struct icp_qat_fw_loader_handle *handle, 162 unsigned char ae, 163 struct icp_qat_uof_batch_init *lm_init_header); 164 int qat_hal_init_gpr(struct icp_qat_fw_loader_handle *handle, 165 unsigned char ae, unsigned long ctx_mask, 166 enum icp_qat_uof_regtype reg_type, 167 unsigned short reg_num, unsigned int regdata); 168 int qat_hal_init_wr_xfer(struct icp_qat_fw_loader_handle *handle, 169 unsigned char ae, unsigned long ctx_mask, 170 enum icp_qat_uof_regtype reg_type, 171 unsigned short reg_num, unsigned int regdata); 172 int qat_hal_init_rd_xfer(struct icp_qat_fw_loader_handle *handle, 173 unsigned char ae, unsigned long ctx_mask, 174 enum icp_qat_uof_regtype reg_type, 175 unsigned short reg_num, unsigned int regdata); 176 int qat_hal_init_nn(struct icp_qat_fw_loader_handle *handle, 177 unsigned char ae, unsigned long ctx_mask, 178 unsigned short reg_num, unsigned int regdata); 179 void qat_hal_set_ae_tindex_mode(struct icp_qat_fw_loader_handle *handle, 180 unsigned char ae, unsigned char mode); 181 int qat_uclo_wr_all_uimage(struct icp_qat_fw_loader_handle *handle); 182 void qat_uclo_del_obj(struct icp_qat_fw_loader_handle *handle); 183 int qat_uclo_wr_mimage(struct icp_qat_fw_loader_handle *handle, void *addr_ptr, 184 int mem_size); 185 int qat_uclo_map_obj(struct icp_qat_fw_loader_handle *handle, 186 void *addr_ptr, u32 mem_size, const char *obj_name); 187 int qat_uclo_set_cfg_ae_mask(struct icp_qat_fw_loader_handle *handle, 188 unsigned int cfg_ae_mask); 189 int adf_init_misc_wq(void); 190 void adf_exit_misc_wq(void); 191 bool adf_misc_wq_queue_work(struct work_struct *work); 192 bool adf_misc_wq_queue_delayed_work(struct delayed_work *work, 193 unsigned long delay); 194 #if defined(CONFIG_PCI_IOV) 195 int adf_sriov_configure(struct pci_dev *pdev, int numvfs); 196 void adf_disable_sriov(struct adf_accel_dev *accel_dev); 197 void adf_enable_vf2pf_interrupts(struct adf_accel_dev *accel_dev, u32 vf_mask); 198 void adf_disable_all_vf2pf_interrupts(struct adf_accel_dev *accel_dev); 199 bool adf_recv_and_handle_pf2vf_msg(struct adf_accel_dev *accel_dev); 200 bool adf_recv_and_handle_vf2pf_msg(struct adf_accel_dev *accel_dev, u32 vf_nr); 201 int adf_pf2vf_handle_pf_restarting(struct adf_accel_dev *accel_dev); 202 void adf_enable_pf2vf_interrupts(struct adf_accel_dev *accel_dev); 203 void adf_disable_pf2vf_interrupts(struct adf_accel_dev *accel_dev); 204 void adf_schedule_vf2pf_handler(struct adf_accel_vf_info *vf_info); 205 int adf_init_pf_wq(void); 206 void adf_exit_pf_wq(void); 207 int adf_init_vf_wq(void); 208 void adf_exit_vf_wq(void); 209 void adf_flush_vf_wq(struct adf_accel_dev *accel_dev); 210 #else 211 #define adf_sriov_configure NULL 212 213 static inline void adf_disable_sriov(struct adf_accel_dev *accel_dev) 214 { 215 } 216 217 static inline int adf_init_pf_wq(void) 218 { 219 return 0; 220 } 221 222 static inline void adf_exit_pf_wq(void) 223 { 224 } 225 226 static inline int adf_init_vf_wq(void) 227 { 228 return 0; 229 } 230 231 static inline void adf_exit_vf_wq(void) 232 { 233 } 234 235 #endif 236 237 static inline void __iomem *adf_get_pmisc_base(struct adf_accel_dev *accel_dev) 238 { 239 struct adf_hw_device_data *hw_data = accel_dev->hw_device; 240 struct adf_bar *pmisc; 241 242 pmisc = &GET_BARS(accel_dev)[hw_data->get_misc_bar_id(hw_data)]; 243 244 return pmisc->virt_addr; 245 } 246 247 #endif 248