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