Date: Fri, 20 Jun 2025 13:52:36 GMT From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 9c5211114872 - stable/14 - qat: reimplement cpaCyGetXXXInstances as a wrapper Message-ID: <202506201352.55KDqacS058479@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9c521111487295819f34a44f3d6b27c90d9dbb73 commit 9c521111487295819f34a44f3d6b27c90d9dbb73 Author: Hareshx Sankar Raj <hareshx.sankar.raj@intel.com> AuthorDate: 2025-05-01 05:53:54 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-06-20 12:47:27 +0000 qat: reimplement cpaCyGetXXXInstances as a wrapper Currently code from sal_instances.c and sal_crypto.c for getting cy instances or number of instances is duplicated. This commit replaces cpaCyGetXXXInstances implementation with Lac_GetCyXXXInstancesByType invocation. Reviewed by: markj, ziaee MFC after: 2 weeks Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D50379 (cherry picked from commit e745eee59c821c1d8ae7f5b25dfbdf0049b4787c) --- sys/dev/qat/qat_api/common/ctrl/sal_crypto.c | 205 ++------------------- .../qat/qat_api/common/ctrl/sal_get_instances.c | 177 ++++++++++++++---- .../qat_api/common/include/lac_sal_types_crypto.h | 23 ++- 3 files changed, 182 insertions(+), 223 deletions(-) diff --git a/sys/dev/qat/qat_api/common/ctrl/sal_crypto.c b/sys/dev/qat/qat_api/common/ctrl/sal_crypto.c index e8a5ab1361e7..7bfc5ec3ba10 100644 --- a/sys/dev/qat/qat_api/common/ctrl/sal_crypto.c +++ b/sys/dev/qat/qat_api/common/ctrl/sal_crypto.c @@ -73,6 +73,15 @@ #define NUM_CRYPTO_ASYM_RX_RINGS 1 #define NUM_CRYPTO_NRBG_RX_RINGS 1 +CpaStatus Lac_GetCyInstancesByType( + const CpaAccelerationServiceType accelerationServiceType, + Cpa16U numInstances, + CpaInstanceHandle *pInstances); + +CpaStatus Lac_GetCyNumInstancesByType( + const CpaAccelerationServiceType accelerationServiceType, + Cpa16U *pNumInstances); + static CpaInstanceHandle Lac_CryptoGetFirstHandle(void) { @@ -1068,84 +1077,8 @@ cpaCyInstanceSetNotificationCb( CpaStatus cpaCyGetNumInstances(Cpa16U *pNumInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; - CpaInstanceHandle cyInstanceHandle; - CpaInstanceInfo2 info; - icp_accel_dev_t **pAdfInsts = NULL; - icp_accel_dev_t *dev_addr = NULL; - sal_t *base_addr = NULL; - sal_list_t *list_temp = NULL; - Cpa16U num_accel_dev = 0; - Cpa16U num_inst = 0; - Cpa16U i = 0; - - LAC_CHECK_NULL_PARAM(pNumInstances); - - /* Get the number of accel_dev in the system */ - status = icp_amgr_getNumInstances(&num_accel_dev); - LAC_CHECK_STATUS(status); - - /* Allocate memory to store addr of accel_devs */ - pAdfInsts = - malloc(num_accel_dev * sizeof(icp_accel_dev_t *), M_QAT, M_WAITOK); - num_accel_dev = 0; - /* Get ADF to return all accel_devs that support either - * symmetric or asymmetric crypto */ - status = icp_amgr_getAllAccelDevByCapabilities( - (ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | - ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC), - pAdfInsts, - &num_accel_dev); - if (CPA_STATUS_SUCCESS != status) { - LAC_LOG_ERROR("No support for crypto\n"); - *pNumInstances = 0; - free(pAdfInsts, M_QAT); - return status; - } - - for (i = 0; i < num_accel_dev; i++) { - dev_addr = (icp_accel_dev_t *)pAdfInsts[i]; - if (NULL == dev_addr || NULL == dev_addr->pSalHandle) { - continue; - } - - base_addr = dev_addr->pSalHandle; - list_temp = base_addr->crypto_services; - while (NULL != list_temp) { - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - if (CPA_STATUS_SUCCESS == status && - CPA_TRUE == info.isPolled) { - num_inst++; - } - list_temp = SalList_next(list_temp); - } - list_temp = base_addr->asym_services; - while (NULL != list_temp) { - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - if (CPA_STATUS_SUCCESS == status && - CPA_TRUE == info.isPolled) { - num_inst++; - } - list_temp = SalList_next(list_temp); - } - list_temp = base_addr->sym_services; - while (NULL != list_temp) { - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - if (CPA_STATUS_SUCCESS == status && - CPA_TRUE == info.isPolled) { - num_inst++; - } - list_temp = SalList_next(list_temp); - } - } - *pNumInstances = num_inst; - free(pAdfInsts, M_QAT); - - - return status; + return Lac_GetCyNumInstancesByType(CPA_ACC_SVC_TYPE_CRYPTO, + pNumInstances); } /** @@ -1155,119 +1088,9 @@ cpaCyGetNumInstances(Cpa16U *pNumInstances) CpaStatus cpaCyGetInstances(Cpa16U numInstances, CpaInstanceHandle *pCyInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; - CpaInstanceHandle cyInstanceHandle; - CpaInstanceInfo2 info; - icp_accel_dev_t **pAdfInsts = NULL; - icp_accel_dev_t *dev_addr = NULL; - sal_t *base_addr = NULL; - sal_list_t *list_temp = NULL; - Cpa16U num_accel_dev = 0; - Cpa16U num_allocated_instances = 0; - Cpa16U index = 0; - Cpa16U i = 0; - - - LAC_CHECK_NULL_PARAM(pCyInstances); - if (0 == numInstances) { - LAC_INVALID_PARAM_LOG("NumInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - - /* Get the number of crypto instances */ - status = cpaCyGetNumInstances(&num_allocated_instances); - if (CPA_STATUS_SUCCESS != status) { - return status; - } - - if (numInstances > num_allocated_instances) { - QAT_UTILS_LOG("Only %d crypto instances available\n", - num_allocated_instances); - return CPA_STATUS_RESOURCE; - } - - /* Get the number of accel devices in the system */ - status = icp_amgr_getNumInstances(&num_accel_dev); - LAC_CHECK_STATUS(status); - - /* Allocate memory to store addr of accel_devs */ - pAdfInsts = - malloc(num_accel_dev * sizeof(icp_accel_dev_t *), M_QAT, M_WAITOK); - - num_accel_dev = 0; - /* Get ADF to return all accel_devs that support either - * symmetric or asymmetric crypto */ - status = icp_amgr_getAllAccelDevByCapabilities( - (ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | - ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC), - pAdfInsts, - &num_accel_dev); - if (CPA_STATUS_SUCCESS != status) { - LAC_LOG_ERROR("No support for crypto\n"); - free(pAdfInsts, M_QAT); - return status; - } - - for (i = 0; i < num_accel_dev; i++) { - dev_addr = (icp_accel_dev_t *)pAdfInsts[i]; - /* Note dev_addr cannot be NULL here as numInstances = 0 - * is not valid and if dev_addr = NULL then index = 0 (which - * is less than numInstances and status is set to _RESOURCE - * above - */ - base_addr = dev_addr->pSalHandle; - if (NULL == base_addr) { - continue; - } - list_temp = base_addr->crypto_services; - while (NULL != list_temp) { - if (index > (numInstances - 1)) { - break; - } - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - list_temp = SalList_next(list_temp); - if (CPA_STATUS_SUCCESS != status || - CPA_TRUE != info.isPolled) { - continue; - } - pCyInstances[index] = cyInstanceHandle; - index++; - } - list_temp = base_addr->asym_services; - while (NULL != list_temp) { - if (index > (numInstances - 1)) { - break; - } - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - list_temp = SalList_next(list_temp); - if (CPA_STATUS_SUCCESS != status || - CPA_TRUE != info.isPolled) { - continue; - } - pCyInstances[index] = cyInstanceHandle; - index++; - } - list_temp = base_addr->sym_services; - while (NULL != list_temp) { - if (index > (numInstances - 1)) { - break; - } - cyInstanceHandle = SalList_getObject(list_temp); - status = cpaCyInstanceGetInfo2(cyInstanceHandle, &info); - list_temp = SalList_next(list_temp); - if (CPA_STATUS_SUCCESS != status || - CPA_TRUE != info.isPolled) { - continue; - } - pCyInstances[index] = cyInstanceHandle; - index++; - } - } - free(pAdfInsts, M_QAT); - - return status; + return Lac_GetCyInstancesByType(CPA_ACC_SVC_TYPE_CRYPTO, + numInstances, + pCyInstances); } /** diff --git a/sys/dev/qat/qat_api/common/ctrl/sal_get_instances.c b/sys/dev/qat/qat_api/common/ctrl/sal_get_instances.c index 27037e99d1ac..f68853dc43a8 100644 --- a/sys/dev/qat/qat_api/common/ctrl/sal_get_instances.c +++ b/sys/dev/qat/qat_api/common/ctrl/sal_get_instances.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright(c) 2007-2022 Intel Corporation */ +/* Copyright(c) 2007-2025 Intel Corporation */ /** ***************************************************************************** @@ -10,7 +10,9 @@ * @ingroup SalCtrl * * @description - * This file contains the main function to get SAL instances. + * This file contains generic functions to get instances of a specified + * service type. Note these are complementary to the already existing + * service-specific functions. * *****************************************************************************/ @@ -34,19 +36,22 @@ #include "lac_mem.h" #include "lac_list.h" #include "lac_sal_types.h" +#include "lac_sal_types_crypto.h" /** ****************************************************************************** * @ingroup SalCtrl * @description - * Get either sym or asym instance number + * Get the total number of either sym, asym or cy instances *****************************************************************************/ -static CpaStatus -Lac_GetSingleCyNumInstances( +CpaStatus +Lac_GetCyNumInstancesByType( const CpaAccelerationServiceType accelerationServiceType, Cpa16U *pNumInstances) { CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceHandle instanceHandle; + CpaInstanceInfo2 info; icp_accel_dev_t **pAdfInsts = NULL; icp_accel_dev_t *dev_addr = NULL; sal_t *base_addr = NULL; @@ -71,6 +76,12 @@ Lac_GetSingleCyNumInstances( service = "sym"; break; + case CPA_ACC_SVC_TYPE_CRYPTO: + accel_capability = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; + service = "cy"; + break; + default: QAT_UTILS_LOG("Invalid service type\n"); return CPA_STATUS_INVALID_PARAM; @@ -106,14 +117,48 @@ Lac_GetSingleCyNumInstances( } base_addr = dev_addr->pSalHandle; - if (CPA_ACC_SVC_TYPE_CRYPTO_ASYM == accelerationServiceType) { + if (CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { + list_temp = base_addr->crypto_services; + while (NULL != list_temp) { + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + if (CPA_STATUS_SUCCESS == status && + CPA_TRUE == info.isPolled) { + num_inst++; + } + list_temp = SalList_next(list_temp); + } + } + + if (CPA_ACC_SVC_TYPE_CRYPTO_ASYM == accelerationServiceType || + CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->asym_services; - } else { - list_temp = base_addr->sym_services; + while (NULL != list_temp) { + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + if (CPA_STATUS_SUCCESS == status && + CPA_TRUE == info.isPolled) { + num_inst++; + } + list_temp = SalList_next(list_temp); + } } - while (NULL != list_temp) { - num_inst++; - list_temp = SalList_next(list_temp); + + if (CPA_ACC_SVC_TYPE_CRYPTO_SYM == accelerationServiceType || + CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { + list_temp = base_addr->sym_services; + while (NULL != list_temp) { + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + if (CPA_STATUS_SUCCESS == status && + CPA_TRUE == info.isPolled) { + num_inst++; + } + list_temp = SalList_next(list_temp); + } } } @@ -127,15 +172,17 @@ Lac_GetSingleCyNumInstances( ****************************************************************************** * @ingroup SalCtrl * @description - * Get either sym or asym instance + * Get either sym, asym or cy instance *****************************************************************************/ -static CpaStatus -Lac_GetSingleCyInstances( +CpaStatus +Lac_GetCyInstancesByType( const CpaAccelerationServiceType accelerationServiceType, Cpa16U numInstances, CpaInstanceHandle *pInstances) { CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceHandle instanceHandle = NULL; + CpaInstanceInfo2 info; icp_accel_dev_t **pAdfInsts = NULL; icp_accel_dev_t *dev_addr = NULL; sal_t *base_addr = NULL; @@ -163,14 +210,21 @@ Lac_GetSingleCyInstances( accel_capability = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; service = "sym"; break; + + case CPA_ACC_SVC_TYPE_CRYPTO: + accel_capability = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC; + service = "cy"; + break; + default: QAT_UTILS_LOG("Invalid service type\n"); return CPA_STATUS_INVALID_PARAM; } /* Get the number of instances */ - status = cpaGetNumInstances(accelerationServiceType, - &num_allocated_instances); + status = Lac_GetCyNumInstancesByType(accelerationServiceType, + &num_allocated_instances); if (CPA_STATUS_SUCCESS != status) { return status; } @@ -216,17 +270,63 @@ Lac_GetSingleCyInstances( continue; } - if (CPA_ACC_SVC_TYPE_CRYPTO_ASYM == accelerationServiceType) + if (CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { + list_temp = base_addr->crypto_services; + while (NULL != list_temp) { + if (index > (numInstances - 1)) + break; + + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + list_temp = SalList_next(list_temp); + if (CPA_STATUS_SUCCESS != status || + CPA_TRUE != info.isPolled) { + continue; + } + pInstances[index] = instanceHandle; + index++; + } + } + + if (CPA_ACC_SVC_TYPE_CRYPTO_ASYM == accelerationServiceType || + CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->asym_services; - else - list_temp = base_addr->sym_services; - while (NULL != list_temp) { - if (index > (numInstances - 1)) - break; + while (NULL != list_temp) { + if (index > (numInstances - 1)) + break; + + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + list_temp = SalList_next(list_temp); + if (CPA_STATUS_SUCCESS != status || + CPA_TRUE != info.isPolled) { + continue; + } + pInstances[index] = instanceHandle; + index++; + } + } - pInstances[index] = SalList_getObject(list_temp); - list_temp = SalList_next(list_temp); - index++; + if (CPA_ACC_SVC_TYPE_CRYPTO_SYM == accelerationServiceType || + CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { + list_temp = base_addr->sym_services; + while (NULL != list_temp) { + if (index > (numInstances - 1)) + break; + + instanceHandle = SalList_getObject(list_temp); + status = cpaCyInstanceGetInfo2(instanceHandle, + &info); + list_temp = SalList_next(list_temp); + if (CPA_STATUS_SUCCESS != status || + CPA_TRUE != info.isPolled) { + continue; + } + pInstances[index] = instanceHandle; + index++; + } } } free(pAdfInsts, M_QAT); @@ -242,16 +342,24 @@ CpaStatus cpaGetNumInstances(const CpaAccelerationServiceType accelerationServiceType, Cpa16U *pNumInstances) { + LAC_CHECK_NULL_PARAM(pNumInstances); + switch (accelerationServiceType) { case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: case CPA_ACC_SVC_TYPE_CRYPTO_SYM: - return Lac_GetSingleCyNumInstances(accelerationServiceType, - pNumInstances); case CPA_ACC_SVC_TYPE_CRYPTO: - return cpaCyGetNumInstances(pNumInstances); + return Lac_GetCyNumInstancesByType(accelerationServiceType, + pNumInstances); + case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: return cpaDcGetNumInstances(pNumInstances); + case CPA_ACC_SVC_TYPE_PATTERN_MATCH: + case CPA_ACC_SVC_TYPE_RAID: + case CPA_ACC_SVC_TYPE_XML: + QAT_UTILS_LOG("Unsupported service type\n"); + return CPA_STATUS_UNSUPPORTED; + default: QAT_UTILS_LOG("Invalid service type\n"); *pNumInstances = 0; @@ -268,18 +376,25 @@ cpaGetInstances(const CpaAccelerationServiceType accelerationServiceType, Cpa16U numInstances, CpaInstanceHandle *pInstances) { + LAC_CHECK_NULL_PARAM(pInstances); + switch (accelerationServiceType) { case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: case CPA_ACC_SVC_TYPE_CRYPTO_SYM: - return Lac_GetSingleCyInstances(accelerationServiceType, + case CPA_ACC_SVC_TYPE_CRYPTO: + return Lac_GetCyInstancesByType(accelerationServiceType, numInstances, pInstances); - case CPA_ACC_SVC_TYPE_CRYPTO: - return cpaCyGetInstances(numInstances, pInstances); case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: return cpaDcGetInstances(numInstances, pInstances); + case CPA_ACC_SVC_TYPE_PATTERN_MATCH: + case CPA_ACC_SVC_TYPE_RAID: + case CPA_ACC_SVC_TYPE_XML: + QAT_UTILS_LOG("Unsupported service type\n"); + return CPA_STATUS_UNSUPPORTED; + default: QAT_UTILS_LOG("Invalid service type\n"); return CPA_STATUS_INVALID_PARAM; diff --git a/sys/dev/qat/qat_api/common/include/lac_sal_types_crypto.h b/sys/dev/qat/qat_api/common/include/lac_sal_types_crypto.h index c26603e4b582..952c174adfec 100644 --- a/sys/dev/qat/qat_api/common/include/lac_sal_types_crypto.h +++ b/sys/dev/qat/qat_api/common/include/lac_sal_types_crypto.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright(c) 2007-2022 Intel Corporation */ +/* Copyright(c) 2007-2025 Intel Corporation */ /** *************************************************************************** @@ -187,4 +187,25 @@ typedef struct sal_crypto_service_s { CpaInstanceHandle Lac_GetFirstHandle(sal_service_type_t svc_type); +/** + ****************************************************************************** + * @ingroup SalCtrl + * @description + * Get the total number of either sym, asym or cy instances + *****************************************************************************/ +CpaStatus Lac_GetCyNumInstancesByType( + const CpaAccelerationServiceType accelerationServiceType, + Cpa16U *pNumInstances); + +/** + ****************************************************************************** + * @ingroup SalCtrl + * @description + * Get either sym, asym or cy instance + *****************************************************************************/ +CpaStatus Lac_GetCyInstancesByType( + const CpaAccelerationServiceType accelerationServiceType, + Cpa16U numInstances, + CpaInstanceHandle *pInstances); + #endif /*LAC_SAL_TYPES_CRYPTO_H_*/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506201352.55KDqacS058479>