xref: /freebsd/sys/dev/qat/qat_api/device/dev_info.c (revision 06c3fb27)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 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 	Cpa16U numDevicesAvail = 0;
38 	Cpa32U capabilitiesMask = 0;
39 	Cpa32U enabledServices = 0;
40 
41 	LAC_CHECK_NULL_PARAM(deviceInfo);
42 	status = icp_amgr_getNumInstances(&numDevicesAvail);
43 	/* Check if the application is not attempting to access a
44 	 * device that does not exist.
45 	 */
46 	if (0 == numDevicesAvail) {
47 		QAT_UTILS_LOG("Failed to retrieve number of devices!\n");
48 		return CPA_STATUS_FAIL;
49 	}
50 	if (device >= numDevicesAvail) {
51 		QAT_UTILS_LOG(
52 		    "Invalid device access! Number of devices available: %d.\n",
53 		    numDevicesAvail);
54 		return CPA_STATUS_FAIL;
55 	}
56 
57 	/* Clear the entire capability structure before initialising it */
58 	memset(deviceInfo, 0x00, sizeof(CpaDeviceInfo));
59 	/* Bus/Device/Function should be 0xFF until initialised */
60 	deviceInfo->bdf = 0xffff;
61 
62 	pDevice = icp_adf_getAccelDevByAccelId(device);
63 	if (NULL == pDevice) {
64 		QAT_UTILS_LOG("Failed to retrieve device.\n");
65 		return status;
66 	}
67 
68 	/* Device of interest is found, retrieve the information for it */
69 	deviceInfo->sku = pDevice->sku;
70 	deviceInfo->deviceId = pDevice->pciDevId;
71 	deviceInfo->bdf = icp_adf_get_busAddress(pDevice->accelId);
72 	deviceInfo->numaNode = pDevice->pkg_id;
73 
74 	if (DEVICE_DH895XCCVF == pDevice->deviceType ||
75 	    DEVICE_C62XVF == pDevice->deviceType ||
76 	    DEVICE_C3XXXVF == pDevice->deviceType ||
77 	    DEVICE_C4XXXVF == pDevice->deviceType) {
78 		deviceInfo->isVf = CPA_TRUE;
79 	}
80 
81 	status = SalCtrl_GetEnabledServices(pDevice, &enabledServices);
82 	if (CPA_STATUS_SUCCESS != status) {
83 		QAT_UTILS_LOG("Failed to retrieve enabled services!\n");
84 		return status;
85 	}
86 
87 	status = icp_amgr_getAccelDevCapabilities(pDevice, &capabilitiesMask);
88 	if (CPA_STATUS_SUCCESS != status) {
89 		QAT_UTILS_LOG("Failed to retrieve accel capabilities mask!\n");
90 		return status;
91 	}
92 
93 	/* Determine if Compression service is enabled */
94 	if (enabledServices & SAL_SERVICE_TYPE_COMPRESSION) {
95 		deviceInfo->dcEnabled =
96 		    (((capabilitiesMask & ICP_ACCEL_CAPABILITIES_COMPRESSION) !=
97 		      0) ?
98 			 CPA_TRUE :
99 			 CPA_FALSE);
100 	}
101 
102 	/* Determine if Crypto service is enabled */
103 	if (enabledServices & SAL_SERVICE_TYPE_CRYPTO) {
104 		deviceInfo->cySymEnabled =
105 		    (((capabilitiesMask &
106 		       ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC)) ?
107 			 CPA_TRUE :
108 			 CPA_FALSE);
109 		deviceInfo->cyAsymEnabled =
110 		    (((capabilitiesMask &
111 		       ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) != 0) ?
112 			 CPA_TRUE :
113 			 CPA_FALSE);
114 	}
115 	/* Determine if Crypto Sym service is enabled */
116 	if (enabledServices & SAL_SERVICE_TYPE_CRYPTO_SYM) {
117 		deviceInfo->cySymEnabled =
118 		    (((capabilitiesMask &
119 		       ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC)) ?
120 			 CPA_TRUE :
121 			 CPA_FALSE);
122 	}
123 	/* Determine if Crypto Asym service is enabled */
124 	if (enabledServices & SAL_SERVICE_TYPE_CRYPTO_ASYM) {
125 		deviceInfo->cyAsymEnabled =
126 		    (((capabilitiesMask &
127 		       ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) != 0) ?
128 			 CPA_TRUE :
129 			 CPA_FALSE);
130 	}
131 	deviceInfo->deviceMemorySizeAvailable = pDevice->deviceMemAvail;
132 
133 	return status;
134 }
135