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