xref: /freebsd/sys/dev/qat/qat_api/common/crypto/sym/lac_sym_stats.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 
4 /**
5  ***************************************************************************
6  * @file lac_sym_stats.c   Implementation of symmetric stats
7  *
8  * @ingroup LacSym
9  *
10  ***************************************************************************/
11 
12 /*
13 *******************************************************************************
14 * Include public/global header files
15 *******************************************************************************
16 */
17 #include "cpa.h"
18 #include "cpa_cy_sym.h"
19 
20 /*
21 *******************************************************************************
22 * Include private header files
23 *******************************************************************************
24 */
25 #include "lac_mem_pools.h"
26 #include "icp_adf_transport.h"
27 #include "icp_accel_devices.h"
28 #include "icp_adf_debug.h"
29 #include "icp_qat_fw_la.h"
30 #include "lac_sym_qat.h"
31 #include "lac_sym_stats.h"
32 #include "lac_sal_types_crypto.h"
33 #include "sal_statistics.h"
34 
35 /* Number of Symmetric Crypto statistics */
36 #define LAC_SYM_NUM_STATS (sizeof(CpaCySymStats64) / sizeof(Cpa64U))
37 
38 CpaStatus
LacSym_StatsInit(CpaInstanceHandle instanceHandle)39 LacSym_StatsInit(CpaInstanceHandle instanceHandle)
40 {
41 	CpaStatus status = CPA_STATUS_SUCCESS;
42 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
43 
44 	pService->pLacSymStatsArr =
45 	    LAC_OS_MALLOC(LAC_SYM_NUM_STATS * sizeof(QatUtilsAtomic));
46 
47 	if (NULL != pService->pLacSymStatsArr) {
48 		LAC_OS_BZERO((void *)LAC_CONST_VOLATILE_PTR_CAST(
49 				 pService->pLacSymStatsArr),
50 			     LAC_SYM_NUM_STATS * sizeof(QatUtilsAtomic));
51 	} else {
52 		status = CPA_STATUS_RESOURCE;
53 	}
54 	return status;
55 }
56 
57 void
LacSym_StatsFree(CpaInstanceHandle instanceHandle)58 LacSym_StatsFree(CpaInstanceHandle instanceHandle)
59 {
60 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
61 	if (NULL != pService->pLacSymStatsArr) {
62 		LAC_OS_FREE(pService->pLacSymStatsArr);
63 	}
64 }
65 
66 void
LacSym_StatsInc(Cpa32U offset,CpaInstanceHandle instanceHandle)67 LacSym_StatsInc(Cpa32U offset, CpaInstanceHandle instanceHandle)
68 {
69 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
70 	if (CPA_TRUE ==
71 	    pService->generic_service_info.stats->bSymStatsEnabled) {
72 		qatUtilsAtomicInc(
73 		    &pService->pLacSymStatsArr[offset / sizeof(Cpa64U)]);
74 	}
75 }
76 
77 void
LacSym_Stats32CopyGet(CpaInstanceHandle instanceHandle,struct _CpaCySymStats * const pSymStats)78 LacSym_Stats32CopyGet(CpaInstanceHandle instanceHandle,
79 		      struct _CpaCySymStats *const pSymStats)
80 {
81 	int i = 0;
82 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
83 
84 	for (i = 0; i < LAC_SYM_NUM_STATS; i++) {
85 		((Cpa32U *)pSymStats)[i] =
86 		    (Cpa32U)qatUtilsAtomicGet(&pService->pLacSymStatsArr[i]);
87 	}
88 }
89 
90 void
LacSym_Stats64CopyGet(CpaInstanceHandle instanceHandle,CpaCySymStats64 * const pSymStats)91 LacSym_Stats64CopyGet(CpaInstanceHandle instanceHandle,
92 		      CpaCySymStats64 *const pSymStats)
93 {
94 	int i = 0;
95 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
96 
97 	for (i = 0; i < LAC_SYM_NUM_STATS; i++) {
98 		((Cpa64U *)pSymStats)[i] =
99 		    qatUtilsAtomicGet(&pService->pLacSymStatsArr[i]);
100 	}
101 }
102 
103 void
LacSym_StatsShow(CpaInstanceHandle instanceHandle)104 LacSym_StatsShow(CpaInstanceHandle instanceHandle)
105 {
106 	CpaCySymStats64 symStats = { 0 };
107 
108 	LacSym_Stats64CopyGet(instanceHandle, &symStats);
109 
110 	QAT_UTILS_LOG(SEPARATOR BORDER
111 		      "              Symmetric Stats               " BORDER
112 		      "\n" SEPARATOR);
113 
114 	/* Session Info */
115 	QAT_UTILS_LOG(BORDER " Sessions Initialized:           %16llu " BORDER
116 			     "\n" BORDER
117 			     " Sessions Removed:               %16llu " BORDER
118 			     "\n" BORDER
119 			     " Session Errors:                 %16llu " BORDER
120 			     "\n" SEPARATOR,
121 		      (unsigned long long)symStats.numSessionsInitialized,
122 		      (unsigned long long)symStats.numSessionsRemoved,
123 		      (unsigned long long)symStats.numSessionErrors);
124 
125 	/* Session info */
126 	QAT_UTILS_LOG(
127 	    BORDER " Symmetric Requests:             %16llu " BORDER "\n" BORDER
128 		   " Symmetric Request Errors:       %16llu " BORDER "\n" BORDER
129 		   " Symmetric Completed:            %16llu " BORDER "\n" BORDER
130 		   " Symmetric Completed Errors:     %16llu " BORDER "\n" BORDER
131 		   " Symmetric Verify Failures:      %16llu " BORDER
132 		   "\n" SEPARATOR,
133 	    (unsigned long long)symStats.numSymOpRequests,
134 	    (unsigned long long)symStats.numSymOpRequestErrors,
135 	    (unsigned long long)symStats.numSymOpCompleted,
136 	    (unsigned long long)symStats.numSymOpCompletedErrors,
137 	    (unsigned long long)symStats.numSymOpVerifyFailures);
138 }
139