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