1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 /** 5 ***************************************************************************** 6 * @file sal_versions.c 7 * 8 * @ingroup SalVersions 9 * 10 * @description 11 * This file contains implementation of functions used to obtain version 12 * information 13 * 14 *****************************************************************************/ 15 16 #include "cpa.h" 17 #include "qat_utils.h" 18 19 #include "icp_accel_devices.h" 20 #include "icp_adf_accel_mgr.h" 21 #include "icp_adf_cfg.h" 22 23 #include "lac_common.h" 24 25 #include "icp_sal_versions.h" 26 27 #define ICP_SAL_VERSIONS_ALL_CAP_MASK 0xFFFFFFFF 28 /**< Mask used to get all devices from ADF */ 29 30 /** 31 ******************************************************************************* 32 * @ingroup SalVersions 33 * Fills in the version info structure 34 * @description 35 * This function obtains hardware and software information associated with 36 * a given device and fills in the version info structure 37 * 38 * @param[in] device Pointer to the device for which version information 39 * is to be obtained. 40 * @param[out] pVerInfo Pointer to a structure that will hold version 41 * information 42 * 43 * @context 44 * This function might sleep. It cannot be executed in a context that 45 * does not permit sleeping. 46 * @assumptions 47 * The system has been started 48 * @sideEffects 49 * None 50 * @blocking 51 * No 52 * @reentrant 53 * No 54 * @threadSafe 55 * Yes 56 * 57 * @return CPA_STATUS_SUCCESS Operation finished successfully 58 * @return CPA_STATUS_FAIL Operation failed 59 * 60 *****************************************************************************/ 61 static CpaStatus 62 SalVersions_FillVersionInfo(icp_accel_dev_t *device, 63 icp_sal_dev_version_info_t *pVerInfo) 64 { 65 CpaStatus status = CPA_STATUS_SUCCESS; 66 char param_value[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = { 0 }; 67 Cpa32S strSize = 0; 68 69 memset(pVerInfo, 0, sizeof(icp_sal_dev_version_info_t)); 70 pVerInfo->devId = device->accelId; 71 72 status = icp_adf_cfgGetParamValue(device, 73 LAC_CFG_SECTION_GENERAL, 74 ICP_CFG_HW_REV_ID_KEY, 75 param_value); 76 LAC_CHECK_STATUS(status); 77 78 strSize = snprintf((char *)pVerInfo->hardwareVersion, 79 ICP_SAL_VERSIONS_HW_VERSION_SIZE, 80 "%s", 81 param_value); 82 LAC_CHECK_PARAM_RANGE(strSize, 1, ICP_SAL_VERSIONS_HW_VERSION_SIZE); 83 84 memset(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); 85 status = icp_adf_cfgGetParamValue(device, 86 LAC_CFG_SECTION_GENERAL, 87 ICP_CFG_UOF_VER_KEY, 88 param_value); 89 LAC_CHECK_STATUS(status); 90 91 strSize = snprintf((char *)pVerInfo->firmwareVersion, 92 ICP_SAL_VERSIONS_FW_VERSION_SIZE, 93 "%s", 94 param_value); 95 LAC_CHECK_PARAM_RANGE(strSize, 1, ICP_SAL_VERSIONS_FW_VERSION_SIZE); 96 97 memset(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); 98 status = icp_adf_cfgGetParamValue(device, 99 LAC_CFG_SECTION_GENERAL, 100 ICP_CFG_MMP_VER_KEY, 101 param_value); 102 LAC_CHECK_STATUS(status); 103 104 strSize = snprintf((char *)pVerInfo->mmpVersion, 105 ICP_SAL_VERSIONS_MMP_VERSION_SIZE, 106 "%s", 107 param_value); 108 LAC_CHECK_PARAM_RANGE(strSize, 1, ICP_SAL_VERSIONS_MMP_VERSION_SIZE); 109 110 snprintf((char *)pVerInfo->softwareVersion, 111 ICP_SAL_VERSIONS_SW_VERSION_SIZE, 112 "%d.%d.%d", 113 SAL_INFO2_DRIVER_SW_VERSION_MAJ_NUMBER, 114 SAL_INFO2_DRIVER_SW_VERSION_MIN_NUMBER, 115 SAL_INFO2_DRIVER_SW_VERSION_PATCH_NUMBER); 116 117 return status; 118 } 119 120 CpaStatus 121 icp_sal_getDevVersionInfo(Cpa32U devId, icp_sal_dev_version_info_t *pVerInfo) 122 { 123 CpaStatus status = CPA_STATUS_SUCCESS; 124 Cpa16U numInstances = 0; 125 icp_accel_dev_t **pAccel_dev = NULL; 126 Cpa16U num_accel_dev = 0, index = 0; 127 icp_accel_dev_t *pDevice = NULL; 128 129 LAC_CHECK_NULL_PARAM(pVerInfo); 130 131 status = icp_amgr_getNumInstances(&numInstances); 132 if (CPA_STATUS_SUCCESS != status) { 133 QAT_UTILS_LOG("Error while getting number of devices.\n"); 134 return CPA_STATUS_FAIL; 135 } 136 137 if (devId >= ADF_MAX_DEVICES) { 138 QAT_UTILS_LOG("Invalid devId\n"); 139 return CPA_STATUS_INVALID_PARAM; 140 } 141 142 pAccel_dev = 143 malloc(numInstances * sizeof(icp_accel_dev_t *), M_QAT, M_WAITOK); 144 145 /* Get ADF to return all accel_devs */ 146 status = 147 icp_amgr_getAllAccelDevByCapabilities(ICP_SAL_VERSIONS_ALL_CAP_MASK, 148 pAccel_dev, 149 &num_accel_dev); 150 151 if (CPA_STATUS_SUCCESS == status) { 152 for (index = 0; index < num_accel_dev; index++) { 153 pDevice = (icp_accel_dev_t *)pAccel_dev[index]; 154 155 if (pDevice->accelId == devId) { 156 status = SalVersions_FillVersionInfo(pDevice, 157 pVerInfo); 158 if (CPA_STATUS_SUCCESS != status) { 159 QAT_UTILS_LOG( 160 "Error while filling in version info.\n"); 161 } 162 break; 163 } 164 } 165 166 if (index == num_accel_dev) { 167 QAT_UTILS_LOG("Device %d not found or not started.\n", 168 devId); 169 status = CPA_STATUS_FAIL; 170 } 171 } else { 172 QAT_UTILS_LOG("Error while getting devices.\n"); 173 } 174 175 free(pAccel_dev, M_QAT); 176 return status; 177 } 178