1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 #include "adf_cfg.h" 5 #include "cpa.h" 6 #include "icp_accel_devices.h" 7 #include "adf_common_drv.h" 8 #include "icp_adf_debug.h" 9 #include "icp_adf_init.h" 10 #include "lac_sal_ctrl.h" 11 12 extern struct mtx *adfDevicesLock; 13 14 static int 15 adf_module_load(void) 16 { 17 CpaStatus ret = CPA_STATUS_SUCCESS; 18 19 qatUtilsMutexInit(&adfDevicesLock); 20 ret = SalCtrl_AdfServicesRegister(); 21 if (ret != CPA_STATUS_SUCCESS) { 22 qatUtilsMutexDestroy(&adfDevicesLock); 23 return EFAULT; 24 } 25 26 return 0; 27 } 28 29 static int 30 adf_module_unload(void) 31 { 32 CpaStatus ret = CPA_STATUS_SUCCESS; 33 34 ret = SalCtrl_AdfServicesUnregister(); 35 if (ret != CPA_STATUS_SUCCESS) { 36 return EBUSY; 37 } 38 qatUtilsMutexDestroy(&adfDevicesLock); 39 40 return 0; 41 } 42 43 static int 44 adf_modevent(module_t mod, int type, void *arg) 45 { 46 int error; 47 48 switch (type) { 49 case MOD_LOAD: 50 error = adf_module_load(); 51 break; 52 case MOD_UNLOAD: 53 error = adf_module_unload(); 54 break; 55 default: 56 error = EOPNOTSUPP; 57 break; 58 } 59 60 return (error); 61 } 62 63 static moduledata_t adf_mod = { "qat_api", adf_modevent, 0 }; 64 65 DECLARE_MODULE(qat_api, adf_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND); 66 MODULE_VERSION(qat_api, 1); 67 MODULE_DEPEND(qat_api, qat_common, 1, 1, 1); 68 MODULE_DEPEND(qat_api, linuxkpi, 1, 1, 1); 69