1*78ee8d1cSJulian Grajkowski /* SPDX-License-Identifier: BSD-3-Clause */ 2*78ee8d1cSJulian Grajkowski /* Copyright(c) 2007-2022 Intel Corporation */ 3*78ee8d1cSJulian Grajkowski /** 4*78ee8d1cSJulian Grajkowski ***************************************************************************** 5*78ee8d1cSJulian Grajkowski * @file dev_info.c 6*78ee8d1cSJulian Grajkowski * 7*78ee8d1cSJulian Grajkowski * @defgroup Device 8*78ee8d1cSJulian Grajkowski * 9*78ee8d1cSJulian Grajkowski * @description 10*78ee8d1cSJulian Grajkowski * This file contains implementation of functions for device level APIs 11*78ee8d1cSJulian Grajkowski * 12*78ee8d1cSJulian Grajkowski *****************************************************************************/ 13*78ee8d1cSJulian Grajkowski 14*78ee8d1cSJulian Grajkowski /* QAT-API includes */ 15*78ee8d1cSJulian Grajkowski #include "cpa_dev.h" 16*78ee8d1cSJulian Grajkowski #include "icp_accel_devices.h" 17*78ee8d1cSJulian Grajkowski #include "lac_common.h" 18*78ee8d1cSJulian Grajkowski #include "icp_adf_cfg.h" 19*78ee8d1cSJulian Grajkowski #include "lac_sal_types.h" 20*78ee8d1cSJulian Grajkowski #include "icp_adf_accel_mgr.h" 21*78ee8d1cSJulian Grajkowski #include "sal_string_parse.h" 22*78ee8d1cSJulian Grajkowski #include "lac_sal.h" 23*78ee8d1cSJulian Grajkowski 24*78ee8d1cSJulian Grajkowski CpaStatus cpaGetNumDevices(Cpa16U * numDevices)25*78ee8d1cSJulian GrajkowskicpaGetNumDevices(Cpa16U *numDevices) 26*78ee8d1cSJulian Grajkowski { 27*78ee8d1cSJulian Grajkowski LAC_CHECK_NULL_PARAM(numDevices); 28*78ee8d1cSJulian Grajkowski 29*78ee8d1cSJulian Grajkowski return icp_amgr_getNumInstances(numDevices); 30*78ee8d1cSJulian Grajkowski } 31*78ee8d1cSJulian Grajkowski 32*78ee8d1cSJulian Grajkowski CpaStatus cpaGetDeviceInfo(Cpa16U device,CpaDeviceInfo * deviceInfo)33*78ee8d1cSJulian GrajkowskicpaGetDeviceInfo(Cpa16U device, CpaDeviceInfo *deviceInfo) 34*78ee8d1cSJulian Grajkowski { 35*78ee8d1cSJulian Grajkowski CpaStatus status = CPA_STATUS_SUCCESS; 36*78ee8d1cSJulian Grajkowski icp_accel_dev_t *pDevice = NULL; 37*78ee8d1cSJulian Grajkowski Cpa16U numDevicesAvail = 0; 38*78ee8d1cSJulian Grajkowski Cpa32U capabilitiesMask = 0; 39*78ee8d1cSJulian Grajkowski Cpa32U enabledServices = 0; 40*78ee8d1cSJulian Grajkowski 41*78ee8d1cSJulian Grajkowski LAC_CHECK_NULL_PARAM(deviceInfo); 42*78ee8d1cSJulian Grajkowski status = icp_amgr_getNumInstances(&numDevicesAvail); 43*78ee8d1cSJulian Grajkowski /* Check if the application is not attempting to access a 44*78ee8d1cSJulian Grajkowski * device that does not exist. 45*78ee8d1cSJulian Grajkowski */ 46*78ee8d1cSJulian Grajkowski if (0 == numDevicesAvail) { 47*78ee8d1cSJulian Grajkowski QAT_UTILS_LOG("Failed to retrieve number of devices!\n"); 48*78ee8d1cSJulian Grajkowski return CPA_STATUS_FAIL; 49*78ee8d1cSJulian Grajkowski } 50*78ee8d1cSJulian Grajkowski if (device >= numDevicesAvail) { 51*78ee8d1cSJulian Grajkowski QAT_UTILS_LOG( 52*78ee8d1cSJulian Grajkowski "Invalid device access! Number of devices available: %d.\n", 53*78ee8d1cSJulian Grajkowski numDevicesAvail); 54*78ee8d1cSJulian Grajkowski return CPA_STATUS_FAIL; 55*78ee8d1cSJulian Grajkowski } 56*78ee8d1cSJulian Grajkowski 57*78ee8d1cSJulian Grajkowski /* Clear the entire capability structure before initialising it */ 58*78ee8d1cSJulian Grajkowski memset(deviceInfo, 0x00, sizeof(CpaDeviceInfo)); 59*78ee8d1cSJulian Grajkowski /* Bus/Device/Function should be 0xFF until initialised */ 60*78ee8d1cSJulian Grajkowski deviceInfo->bdf = 0xffff; 61*78ee8d1cSJulian Grajkowski 62*78ee8d1cSJulian Grajkowski pDevice = icp_adf_getAccelDevByAccelId(device); 63*78ee8d1cSJulian Grajkowski if (NULL == pDevice) { 64*78ee8d1cSJulian Grajkowski QAT_UTILS_LOG("Failed to retrieve device.\n"); 65*78ee8d1cSJulian Grajkowski return status; 66*78ee8d1cSJulian Grajkowski } 67*78ee8d1cSJulian Grajkowski 68*78ee8d1cSJulian Grajkowski /* Device of interest is found, retrieve the information for it */ 69*78ee8d1cSJulian Grajkowski deviceInfo->sku = pDevice->sku; 70*78ee8d1cSJulian Grajkowski deviceInfo->deviceId = pDevice->pciDevId; 71*78ee8d1cSJulian Grajkowski deviceInfo->bdf = icp_adf_get_busAddress(pDevice->accelId); 72*78ee8d1cSJulian Grajkowski deviceInfo->numaNode = pDevice->pkg_id; 73*78ee8d1cSJulian Grajkowski 74*78ee8d1cSJulian Grajkowski if (DEVICE_DH895XCCVF == pDevice->deviceType || 75*78ee8d1cSJulian Grajkowski DEVICE_C62XVF == pDevice->deviceType || 76*78ee8d1cSJulian Grajkowski DEVICE_C3XXXVF == pDevice->deviceType || 77*78ee8d1cSJulian Grajkowski DEVICE_C4XXXVF == pDevice->deviceType) { 78*78ee8d1cSJulian Grajkowski deviceInfo->isVf = CPA_TRUE; 79*78ee8d1cSJulian Grajkowski } 80*78ee8d1cSJulian Grajkowski 81*78ee8d1cSJulian Grajkowski status = SalCtrl_GetEnabledServices(pDevice, &enabledServices); 82*78ee8d1cSJulian Grajkowski if (CPA_STATUS_SUCCESS != status) { 83*78ee8d1cSJulian Grajkowski QAT_UTILS_LOG("Failed to retrieve enabled services!\n"); 84*78ee8d1cSJulian Grajkowski return status; 85*78ee8d1cSJulian Grajkowski } 86*78ee8d1cSJulian Grajkowski 87*78ee8d1cSJulian Grajkowski status = icp_amgr_getAccelDevCapabilities(pDevice, &capabilitiesMask); 88*78ee8d1cSJulian Grajkowski if (CPA_STATUS_SUCCESS != status) { 89*78ee8d1cSJulian Grajkowski QAT_UTILS_LOG("Failed to retrieve accel capabilities mask!\n"); 90*78ee8d1cSJulian Grajkowski return status; 91*78ee8d1cSJulian Grajkowski } 92*78ee8d1cSJulian Grajkowski 93*78ee8d1cSJulian Grajkowski /* Determine if Compression service is enabled */ 94*78ee8d1cSJulian Grajkowski if (enabledServices & SAL_SERVICE_TYPE_COMPRESSION) { 95*78ee8d1cSJulian Grajkowski deviceInfo->dcEnabled = 96*78ee8d1cSJulian Grajkowski (((capabilitiesMask & ICP_ACCEL_CAPABILITIES_COMPRESSION) != 97*78ee8d1cSJulian Grajkowski 0) ? 98*78ee8d1cSJulian Grajkowski CPA_TRUE : 99*78ee8d1cSJulian Grajkowski CPA_FALSE); 100*78ee8d1cSJulian Grajkowski } 101*78ee8d1cSJulian Grajkowski 102*78ee8d1cSJulian Grajkowski /* Determine if Crypto service is enabled */ 103*78ee8d1cSJulian Grajkowski if (enabledServices & SAL_SERVICE_TYPE_CRYPTO) { 104*78ee8d1cSJulian Grajkowski deviceInfo->cySymEnabled = 105*78ee8d1cSJulian Grajkowski (((capabilitiesMask & 106*78ee8d1cSJulian Grajkowski ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC)) ? 107*78ee8d1cSJulian Grajkowski CPA_TRUE : 108*78ee8d1cSJulian Grajkowski CPA_FALSE); 109*78ee8d1cSJulian Grajkowski deviceInfo->cyAsymEnabled = 110*78ee8d1cSJulian Grajkowski (((capabilitiesMask & 111*78ee8d1cSJulian Grajkowski ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) != 0) ? 112*78ee8d1cSJulian Grajkowski CPA_TRUE : 113*78ee8d1cSJulian Grajkowski CPA_FALSE); 114*78ee8d1cSJulian Grajkowski } 115*78ee8d1cSJulian Grajkowski /* Determine if Crypto Sym service is enabled */ 116*78ee8d1cSJulian Grajkowski if (enabledServices & SAL_SERVICE_TYPE_CRYPTO_SYM) { 117*78ee8d1cSJulian Grajkowski deviceInfo->cySymEnabled = 118*78ee8d1cSJulian Grajkowski (((capabilitiesMask & 119*78ee8d1cSJulian Grajkowski ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC)) ? 120*78ee8d1cSJulian Grajkowski CPA_TRUE : 121*78ee8d1cSJulian Grajkowski CPA_FALSE); 122*78ee8d1cSJulian Grajkowski } 123*78ee8d1cSJulian Grajkowski /* Determine if Crypto Asym service is enabled */ 124*78ee8d1cSJulian Grajkowski if (enabledServices & SAL_SERVICE_TYPE_CRYPTO_ASYM) { 125*78ee8d1cSJulian Grajkowski deviceInfo->cyAsymEnabled = 126*78ee8d1cSJulian Grajkowski (((capabilitiesMask & 127*78ee8d1cSJulian Grajkowski ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) != 0) ? 128*78ee8d1cSJulian Grajkowski CPA_TRUE : 129*78ee8d1cSJulian Grajkowski CPA_FALSE); 130*78ee8d1cSJulian Grajkowski } 131*78ee8d1cSJulian Grajkowski deviceInfo->deviceMemorySizeAvailable = pDevice->deviceMemAvail; 132*78ee8d1cSJulian Grajkowski 133*78ee8d1cSJulian Grajkowski return status; 134*78ee8d1cSJulian Grajkowski } 135