aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/qat/qat_api/common/compression/include
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/qat/qat_api/common/compression/include')
-rw-r--r--sys/dev/qat/qat_api/common/compression/include/dc_datapath.h186
-rw-r--r--sys/dev/qat/qat_api/common/compression/include/dc_error_counter.h25
-rw-r--r--sys/dev/qat/qat_api/common/compression/include/dc_header_footer.h44
-rw-r--r--sys/dev/qat/qat_api/common/compression/include/dc_session.h278
-rw-r--r--sys/dev/qat/qat_api/common/compression/include/dc_stats.h81
5 files changed, 614 insertions, 0 deletions
diff --git a/sys/dev/qat/qat_api/common/compression/include/dc_datapath.h b/sys/dev/qat/qat_api/common/compression/include/dc_datapath.h
new file mode 100644
index 000000000000..0a6ef7191704
--- /dev/null
+++ b/sys/dev/qat/qat_api/common/compression/include/dc_datapath.h
@@ -0,0 +1,186 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright(c) 2007-2022 Intel Corporation */
+/* $FreeBSD$ */
+/**
+ *****************************************************************************
+ * @file dc_datapath.h
+ *
+ * @ingroup Dc_DataCompression
+ *
+ * @description
+ * Definition of the Data Compression datapath parameters.
+ *
+ *******************
+ * **********************************************************/
+#ifndef DC_DATAPATH_H_
+#define DC_DATAPATH_H_
+
+#define LAC_QAT_DC_REQ_SZ_LW 32
+#define LAC_QAT_DC_RESP_SZ_LW 8
+
+/* Restriction on the source buffer size for compression due to the firmware
+ * processing */
+#define DC_SRC_BUFFER_MIN_SIZE (15)
+
+/* Restriction on the destination buffer size for compression due to
+ * the management of skid buffers in the firmware */
+#define DC_DEST_BUFFER_DYN_MIN_SIZE (128)
+#define DC_DEST_BUFFER_STA_MIN_SIZE (64)
+/* C62x and C3xxx pcie rev0 devices require an additional 32bytes */
+#define DC_DEST_BUFFER_STA_ADDITIONAL_SIZE (32)
+
+/* C4xxx device only requires 47 bytes */
+#define DC_DEST_BUFFER_MIN_SIZE (47)
+
+/* Minimum destination buffer size for decompression */
+#define DC_DEST_BUFFER_DEC_MIN_SIZE (1)
+
+/* Restriction on the source and destination buffer sizes for compression due
+ * to the firmware taking 32 bits parameters. The max size is 2^32-1 */
+#define DC_BUFFER_MAX_SIZE (0xFFFFFFFF)
+
+/* DC Source & Destination buffer type (FLAT/SGL) */
+#define DC_DEFAULT_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_SGL
+#define DC_DP_QAT_PTR_TYPE QAT_COMN_PTR_TYPE_FLAT
+
+/* Offset to first byte of Input Byte Counter (IBC) in state register */
+#define DC_STATE_IBC_OFFSET (8)
+/* Size in bytes of input byte counter (IBC) in state register */
+#define DC_IBC_SIZE_IN_BYTES (4)
+
+/* Offset to first byte to CRC32 in state register */
+#define DC_STATE_CRC32_OFFSET (40)
+/* Offset to first byte to output CRC32 in state register */
+#define DC_STATE_OUTPUT_CRC32_OFFSET (48)
+/* Offset to first byte to input CRC32 in state register */
+#define DC_STATE_INPUT_CRC32_OFFSET (52)
+
+/* Offset to first byte of ADLER32 in state register */
+#define DC_STATE_ADLER32_OFFSET (48)
+
+/* 8 bit mask value */
+#define DC_8_BIT_MASK (0xff)
+
+/* 8 bit shift position */
+#define DC_8_BIT_SHIFT_POS (8)
+
+/* Size in bytes of checksum */
+#define DC_CHECKSUM_SIZE_IN_BYTES (4)
+
+/* Mask used to set the most significant bit to zero */
+#define DC_STATE_REGISTER_ZERO_MSB_MASK (0x7F)
+
+/* Mask used to keep only the most significant bit and set the others to zero */
+#define DC_STATE_REGISTER_KEEP_MSB_MASK (0x80)
+
+/* Compression state register word containing the parity bit */
+#define DC_STATE_REGISTER_PARITY_BIT_WORD (5)
+
+/* Location of the parity bit within the compression state register word */
+#define DC_STATE_REGISTER_PARITY_BIT (7)
+
+/* size which needs to be reserved before the results field to
+ * align the results field with the API struct */
+#define DC_API_ALIGNMENT_OFFSET (offsetof(CpaDcDpOpData, results))
+
+/* Mask used to check the CompressAndVerify capability bit */
+#define DC_CNV_EXTENDED_CAPABILITY (0x01)
+
+/* Mask used to check the CompressAndVerifyAndRecover capability bit */
+#define DC_CNVNR_EXTENDED_CAPABILITY (0x100)
+
+/* Default values for CNV integrity checks,
+ * those are used to inform hardware of specifying CRC parameters to be used
+ * when calculating CRCs */
+#define DC_CRC_POLY_DEFAULT 0x04c11db7
+#define DC_XOR_FLAGS_DEFAULT 0xe0000
+#define DC_XOR_OUT_DEFAULT 0xffffffff
+#define DC_INVALID_CRC 0x0
+
+/**
+*******************************************************************************
+* @ingroup cpaDc Data Compression
+* Compression cookie
+* @description
+* This cookie stores information for a particular compression perform op.
+* This includes various user-supplied parameters for the operation which
+* will be needed in our callback function.
+* A pointer to this cookie is stored in the opaque data field of the QAT
+* message so that it can be accessed in the asynchronous callback.
+* @note
+* The order of the parameters within this structure is important. It needs
+* to match the order of the parameters in CpaDcDpOpData up to the
+* pSessionHandle. This allows the correct processing of the callback.
+*****************************************************************************/
+typedef struct dc_compression_cookie_s {
+ Cpa8U dcReqParamsBuffer[DC_API_ALIGNMENT_OFFSET];
+ /**< Memory block - was previously reserved for request parameters.
+ * Now size maintained so following members align with API struct,
+ * but no longer used for request parameters */
+ CpaDcRqResults reserved;
+ /**< This is reserved for results to correctly align the structure
+ * to match the one from the data plane API */
+ CpaInstanceHandle dcInstance;
+ /**< Compression instance handle */
+ CpaDcSessionHandle pSessionHandle;
+ /**< Pointer to the session handle */
+ icp_qat_fw_comp_req_t request;
+ /**< Compression request */
+ void *callbackTag;
+ /**< Opaque data supplied by the client */
+ dc_session_desc_t *pSessionDesc;
+ /**< Pointer to the session descriptor */
+ CpaDcFlush flushFlag;
+ /**< Flush flag */
+ CpaDcOpData *pDcOpData;
+ /**< struct containing flags and CRC related data for this session */
+ CpaDcRqResults *pResults;
+ /**< Pointer to result buffer holding consumed and produced data */
+ Cpa32U srcTotalDataLenInBytes;
+ /**< Total length of the source data */
+ Cpa32U dstTotalDataLenInBytes;
+ /**< Total length of the destination data */
+ dc_request_dir_t compDecomp;
+ /**< Used to know whether the request is compression or decompression.
+ * Useful when defining the session as combined */
+ CpaBufferList *pUserSrcBuff;
+ /**< virtual userspace ptr to source SGL */
+ CpaBufferList *pUserDestBuff;
+ /**< virtual userspace ptr to destination SGL */
+} dc_compression_cookie_t;
+
+/**
+ *****************************************************************************
+ * @ingroup Dc_DataCompression
+ * Callback function called for compression and decompression requests in
+ * asynchronous mode
+ *
+ * @description
+ * Called to process compression and decompression response messages. This
+ * callback will check for errors, update the statistics and will call the
+ * user callback
+ *
+ * @param[in] pRespMsg Response message
+ *
+ *****************************************************************************/
+void dcCompression_ProcessCallback(void *pRespMsg);
+
+/**
+*****************************************************************************
+* @ingroup Dc_DataCompression
+* Describes CNV and CNVNR modes
+*
+* @description
+* This enum is used to indicate the CNV modes.
+*
+*****************************************************************************/
+typedef enum dc_cnv_mode_s {
+ DC_NO_CNV = 0,
+ /* CNV = FALSE, CNVNR = FALSE */
+ DC_CNV,
+ /* CNV = TRUE, CNVNR = FALSE */
+ DC_CNVNR,
+ /* CNV = TRUE, CNVNR = TRUE */
+} dc_cnv_mode_t;
+
+#endif /* DC_DATAPATH_H_ */
diff --git a/sys/dev/qat/qat_api/common/compression/include/dc_error_counter.h b/sys/dev/qat/qat_api/common/compression/include/dc_error_counter.h
new file mode 100644
index 000000000000..dd1189fd970a
--- /dev/null
+++ b/sys/dev/qat/qat_api/common/compression/include/dc_error_counter.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright(c) 2007-2022 Intel Corporation */
+/* $FreeBSD$ */
+/**
+ *****************************************************************************
+ * @file dc_error_counter.h
+ *
+ * @ingroup Dc_DataCompression
+ *
+ * @description
+ * Definition of the Data Compression Error Counter parameters.
+ *
+ *****************************************************************************/
+#ifndef DC_ERROR_COUNTER_H
+#define DC_ERROR_COUNTER_H
+
+#include "cpa_types.h"
+#include "cpa_dc.h"
+
+#define MAX_DC_ERROR_TYPE 20
+
+void dcErrorLog(CpaDcReqStatus dcError);
+Cpa64U getDcErrorCounter(CpaDcReqStatus dcError);
+
+#endif /* DC_ERROR_COUNTER_H */
diff --git a/sys/dev/qat/qat_api/common/compression/include/dc_header_footer.h b/sys/dev/qat/qat_api/common/compression/include/dc_header_footer.h
new file mode 100644
index 000000000000..0ec2cc6f3f16
--- /dev/null
+++ b/sys/dev/qat/qat_api/common/compression/include/dc_header_footer.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright(c) 2007-2022 Intel Corporation */
+/* $FreeBSD$ */
+/**
+ *****************************************************************************
+ * @file dc_header_footer.h
+ *
+ * @ingroup Dc_DataCompression
+ *
+ * @description
+ * Definition of the Data Compression header and footer parameters.
+ *
+ *****************************************************************************/
+#ifndef DC_HEADER_FOOTER_H_
+#define DC_HEADER_FOOTER_H_
+
+/* Header and footer sizes for Zlib and Gzip */
+#define DC_ZLIB_HEADER_SIZE (2)
+#define DC_GZIP_HEADER_SIZE (10)
+#define DC_ZLIB_FOOTER_SIZE (4)
+#define DC_GZIP_FOOTER_SIZE (8)
+
+/* Values used to build the headers for Zlib and Gzip */
+#define DC_GZIP_ID1 (0x1f)
+#define DC_GZIP_ID2 (0x8b)
+#define DC_GZIP_FILESYSTYPE (0x03)
+#define DC_ZLIB_WINDOWSIZE_OFFSET (4)
+#define DC_ZLIB_FLEVEL_OFFSET (6)
+#define DC_ZLIB_HEADER_OFFSET (31)
+
+/* Compression level for Zlib */
+#define DC_ZLIB_LEVEL_0 (0)
+#define DC_ZLIB_LEVEL_1 (1)
+#define DC_ZLIB_LEVEL_2 (2)
+#define DC_ZLIB_LEVEL_3 (3)
+
+/* CM parameter for Zlib */
+#define DC_ZLIB_CM_DEFLATE (8)
+
+/* Type of Gzip compression */
+#define DC_GZIP_FAST_COMP (4)
+#define DC_GZIP_MAX_COMP (2)
+
+#endif /* DC_HEADER_FOOTER_H_ */
diff --git a/sys/dev/qat/qat_api/common/compression/include/dc_session.h b/sys/dev/qat/qat_api/common/compression/include/dc_session.h
new file mode 100644
index 000000000000..5a4961fadd60
--- /dev/null
+++ b/sys/dev/qat/qat_api/common/compression/include/dc_session.h
@@ -0,0 +1,278 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright(c) 2007-2022 Intel Corporation */
+/* $FreeBSD$ */
+/**
+ *****************************************************************************
+ * @file dc_session.h
+ *
+ * @ingroup Dc_DataCompression
+ *
+ * @description
+ * Definition of the Data Compression session parameters.
+ *
+ *****************************************************************************/
+#ifndef DC_SESSION_H
+#define DC_SESSION_H
+
+#include "cpa_dc_dp.h"
+#include "icp_qat_fw_comp.h"
+#include "sal_qat_cmn_msg.h"
+
+/* Maximum number of intermediate buffers SGLs for devices
+ * with a maximum of 6 compression slices */
+#define DC_QAT_MAX_NUM_INTER_BUFFERS_6COMP_SLICES (12)
+
+/* Maximum number of intermediate buffers SGLs for devices
+ * with a maximum of 10 max compression slices */
+#define DC_QAT_MAX_NUM_INTER_BUFFERS_10COMP_SLICES (20)
+
+/* Maximum number of intermediate buffers SGLs for devices
+ * with a maximum of 24 max compression slices and 32 MEs */
+#define DC_QAT_MAX_NUM_INTER_BUFFERS_24COMP_SLICES (64)
+
+/* Maximum size of the state registers 64 bytes */
+#define DC_QAT_STATE_REGISTERS_MAX_SIZE (64)
+
+/* Size of the history window.
+ * Base 2 logarithm of maximum window size minus 8 */
+#define DC_8K_WINDOW_SIZE (5)
+#define DC_16K_WINDOW_SIZE (6)
+#define DC_32K_WINDOW_SIZE (7)
+
+/* Context size */
+#define DC_DEFLATE_MAX_CONTEXT_SIZE (49152)
+#define DC_INFLATE_CONTEXT_SIZE (36864)
+
+#define DC_DEFLATE_EH_MAX_CONTEXT_SIZE (65536)
+#define DC_DEFLATE_EH_MIN_CONTEXT_SIZE (49152)
+#define DC_INFLATE_EH_CONTEXT_SIZE (34032)
+
+/* Retrieve the session descriptor pointer from the session context structure
+ * that the user allocates. The pointer to the internally realigned address
+ * is stored at the start of the session context that the user allocates */
+#define DC_SESSION_DESC_FROM_CTX_GET(pSession) \
+ (dc_session_desc_t *)(*(LAC_ARCH_UINT *)pSession)
+
+/* Maximum size for the compression part of the content descriptor */
+#define DC_QAT_COMP_CONTENT_DESC_SIZE sizeof(icp_qat_fw_comp_cd_hdr_t)
+
+/* Maximum size for the translator part of the content descriptor */
+#define DC_QAT_TRANS_CONTENT_DESC_SIZE \
+ (sizeof(icp_qat_fw_xlt_cd_hdr_t) + DC_QAT_MAX_TRANS_SETUP_BLK_SZ)
+
+/* Maximum size of the decompression content descriptor */
+#define DC_QAT_CONTENT_DESC_DECOMP_MAX_SIZE \
+ LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE, \
+ (1 << LAC_64BYTE_ALIGNMENT_SHIFT))
+
+/* Maximum size of the compression content descriptor */
+#define DC_QAT_CONTENT_DESC_COMP_MAX_SIZE \
+ LAC_ALIGN_POW2_ROUNDUP(DC_QAT_COMP_CONTENT_DESC_SIZE + \
+ DC_QAT_TRANS_CONTENT_DESC_SIZE, \
+ (1 << LAC_64BYTE_ALIGNMENT_SHIFT))
+
+/* Direction of the request */
+typedef enum dc_request_dir_e {
+ DC_COMPRESSION_REQUEST = 1,
+ DC_DECOMPRESSION_REQUEST
+} dc_request_dir_t;
+
+/* Type of the compression request */
+typedef enum dc_request_type_e {
+ DC_REQUEST_FIRST = 1,
+ DC_REQUEST_SUBSEQUENT
+} dc_request_type_t;
+
+typedef enum dc_block_type_e {
+ DC_CLEARTEXT_TYPE = 0,
+ DC_STATIC_TYPE,
+ DC_DYNAMIC_TYPE
+} dc_block_type_t;
+
+/* Internal data structure supporting end to end data integrity checks. */
+typedef struct dc_integrity_crc_fw_s {
+ Cpa32U crc32;
+ /* CRC32 checksum returned for compressed data */
+ Cpa32U adler32;
+ /* ADLER32 checksum returned for compressed data */
+ Cpa32U oCrc32Cpr;
+ /* CRC32 checksum returned for data output by compression accelerator */
+ Cpa32U iCrc32Cpr;
+ /* CRC32 checksum returned for input data to compression accelerator */
+ Cpa32U oCrc32Xlt;
+ /* CRC32 checksum returned for data output by translator accelerator */
+ Cpa32U iCrc32Xlt;
+ /* CRC32 checksum returned for input data to translator accelerator */
+ Cpa32U xorFlags;
+ /* Initialise transactor pCRC controls in state register */
+ Cpa32U crcPoly;
+ /* CRC32 polynomial used by hardware */
+ Cpa32U xorOut;
+ /* CRC32 from XOR stage (Input CRC is xor'ed with value in the state) */
+ Cpa32U deflateBlockType;
+ /* Bit 1 - Bit 0
+ * 0 0 -> RAW DATA + Deflate header.
+ * This will not produced any CRC check because
+ * the output will not come from the slices.
+ * It will be a simple copy from input to output
+ * buffers list.
+ * 0 1 -> Static deflate block type
+ * 1 0 -> Dynamic deflate block type
+ * 1 1 -> Invalid type */
+} dc_integrity_crc_fw_t;
+
+typedef struct dc_sw_checksums_s {
+ Cpa32U swCrcI;
+ Cpa32U swCrcO;
+} dc_sw_checksums_t;
+
+/* Session descriptor structure for compression */
+typedef struct dc_session_desc_s {
+ Cpa8U stateRegistersComp[DC_QAT_STATE_REGISTERS_MAX_SIZE];
+ /**< State registers for compression */
+ Cpa8U stateRegistersDecomp[DC_QAT_STATE_REGISTERS_MAX_SIZE];
+ /**< State registers for decompression */
+ icp_qat_fw_comp_req_t reqCacheComp;
+ /**< Cache as much as possible of the compression request in a pre-built
+ * request */
+ icp_qat_fw_comp_req_t reqCacheDecomp;
+ /**< Cache as much as possible of the decompression request in a
+ * pre-built
+ * request */
+ dc_request_type_t requestType;
+ /**< Type of the compression request. As stateful mode do not support
+ * more
+ * than one in-flight request there is no need to use spinlocks */
+ dc_request_type_t previousRequestType;
+ /**< Type of the previous compression request. Used in cases where there
+ * the
+ * stateful operation needs to be resubmitted */
+ CpaDcHuffType huffType;
+ /**< Huffman tree type */
+ CpaDcCompType compType;
+ /**< Compression type */
+ CpaDcChecksum checksumType;
+ /**< Type of checksum */
+ CpaDcAutoSelectBest autoSelectBestHuffmanTree;
+ /**< Indicates if the implementation selects the best Huffman encoding
+ */
+ CpaDcSessionDir sessDirection;
+ /**< Session direction */
+ CpaDcSessionState sessState;
+ /**< Session state */
+ Cpa32U deflateWindowSize;
+ /**< Window size */
+ CpaDcCompLvl compLevel;
+ /**< Compression level */
+ CpaDcCallbackFn pCompressionCb;
+ /**< Callback function defined for the traditional compression session
+ */
+ QatUtilsAtomic pendingStatelessCbCount;
+ /**< Keeps track of number of pending requests on stateless session */
+ QatUtilsAtomic pendingStatefulCbCount;
+ /**< Keeps track of number of pending requests on stateful session */
+ Cpa64U pendingDpStatelessCbCount;
+ /**< Keeps track of number of data plane pending requests on stateless
+ * session */
+ struct mtx sessionLock;
+ /**< Lock used to provide exclusive access for number of stateful
+ * in-flight
+ * requests update */
+ CpaBoolean isDcDp;
+ /**< Indicates if the data plane API is used */
+ Cpa32U minContextSize;
+ /**< Indicates the minimum size required to allocate the context buffer
+ */
+ CpaBufferList *pContextBuffer;
+ /**< Context buffer */
+ Cpa32U historyBuffSize;
+ /**< Size of the history buffer */
+ Cpa64U cumulativeConsumedBytes;
+ /**< Cumulative amount of consumed bytes. Used to build the footer in
+ * the
+ * stateful case */
+ Cpa32U previousChecksum;
+ /**< Save the previous value of the checksum. Used to process zero byte
+ * stateful compression or decompression requests */
+ CpaBoolean isSopForCompressionProcessed;
+ /**< Indicates whether a Compression Request is received in this session
+ */
+ CpaBoolean isSopForDecompressionProcessed;
+ /**< Indicates whether a Decompression Request is received in this
+ * session
+ */
+ /**< Data integrity table */
+ dc_integrity_crc_fw_t dataIntegrityCrcs;
+ /**< Physical address of Data integrity buffer */
+ CpaPhysicalAddr physDataIntegrityCrcs;
+ /* Seed checksums structure used to calculate software calculated
+ * checksums.
+ */
+ dc_sw_checksums_t seedSwCrc;
+ /* Driver calculated integrity software CRC */
+ dc_sw_checksums_t integritySwCrc;
+} dc_session_desc_t;
+
+/**
+ *****************************************************************************
+ * @ingroup Dc_DataCompression
+ * Initialise a compression session
+ *
+ * @description
+ * This function will initialise a compression session
+ *
+ * @param[in] dcInstance Instance handle derived from discovery
+ * functions
+ * @param[in,out] pSessionHandle Pointer to a session handle
+ * @param[in,out] pSessionData Pointer to a user instantiated structure
+ * containing session data
+ * @param[in] pContextBuffer Pointer to context buffer
+ *
+ * @param[in] callbackFn For synchronous operation this callback
+ * shall be a null pointer
+ *
+ * @retval CPA_STATUS_SUCCESS Function executed successfully
+ * @retval CPA_STATUS_FAIL Function failed
+ * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in
+ * @retval CPA_STATUS_RESOURCE Error related to system resources
+ *****************************************************************************/
+CpaStatus dcInitSession(CpaInstanceHandle dcInstance,
+ CpaDcSessionHandle pSessionHandle,
+ CpaDcSessionSetupData *pSessionData,
+ CpaBufferList *pContextBuffer,
+ CpaDcCallbackFn callbackFn);
+
+/**
+ *****************************************************************************
+ * @ingroup Dc_DataCompression
+ * Get the size of the memory required to hold the session information
+ *
+ * @description
+ * This function will get the size of the memory required to hold the
+ * session information
+ *
+ * @param[in] dcInstance Instance handle derived from discovery
+ * functions
+ * @param[in] pSessionData Pointer to a user instantiated structure
+ * containing session data
+ * @param[out] pSessionSize On return, this parameter will be the size
+ * of the memory that will be
+ * required by cpaDcInitSession() for session
+ * data.
+ * @param[out] pContextSize On return, this parameter will be the size
+ * of the memory that will be required
+ * for context data. Context data is
+ * save/restore data including history and
+ * any implementation specific data that is
+ * required for a save/restore operation.
+ *
+ * @retval CPA_STATUS_SUCCESS Function executed successfully
+ * @retval CPA_STATUS_FAIL Function failed
+ * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in
+ *****************************************************************************/
+CpaStatus dcGetSessionSize(CpaInstanceHandle dcInstance,
+ CpaDcSessionSetupData *pSessionData,
+ Cpa32U *pSessionSize,
+ Cpa32U *pContextSize);
+
+#endif /* DC_SESSION_H */
diff --git a/sys/dev/qat/qat_api/common/compression/include/dc_stats.h b/sys/dev/qat/qat_api/common/compression/include/dc_stats.h
new file mode 100644
index 000000000000..357be30107b1
--- /dev/null
+++ b/sys/dev/qat/qat_api/common/compression/include/dc_stats.h
@@ -0,0 +1,81 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright(c) 2007-2022 Intel Corporation */
+/* $FreeBSD$ */
+/**
+ *****************************************************************************
+ * @file dc_stats.h
+ *
+ * @ingroup Dc_DataCompression
+ *
+ * @description
+ * Definition of the Data Compression stats parameters.
+ *
+ *****************************************************************************/
+#ifndef DC_STATS_H_
+#define DC_STATS_H_
+
+/* Number of Compression statistics */
+#define COMPRESSION_NUM_STATS (sizeof(CpaDcStats) / sizeof(Cpa64U))
+
+#define COMPRESSION_STAT_INC(statistic, pService) \
+ do { \
+ if (CPA_TRUE == \
+ pService->generic_service_info.stats->bDcStatsEnabled) { \
+ qatUtilsAtomicInc( \
+ &pService->pCompStatsArr[offsetof(CpaDcStats, \
+ statistic) / \
+ sizeof(Cpa64U)]); \
+ } \
+ } while (0)
+
+/* Macro to get all Compression stats (from internal array of atomics) */
+#define COMPRESSION_STATS_GET(compStats, pService) \
+ do { \
+ int i; \
+ for (i = 0; i < COMPRESSION_NUM_STATS; i++) { \
+ ((Cpa64U *)compStats)[i] = \
+ qatUtilsAtomicGet(&pService->pCompStatsArr[i]); \
+ } \
+ } while (0)
+
+/* Macro to reset all Compression stats */
+#define COMPRESSION_STATS_RESET(pService) \
+ do { \
+ int i; \
+ for (i = 0; i < COMPRESSION_NUM_STATS; i++) { \
+ qatUtilsAtomicSet(0, &pService->pCompStatsArr[i]); \
+ } \
+ } while (0)
+
+/**
+*******************************************************************************
+* @ingroup Dc_DataCompression
+* Initialises the compression stats
+*
+* @description
+* This function allocates and initialises the stats array to 0
+*
+* @param[in] pService Pointer to a compression service structure
+*
+* @retval CPA_STATUS_SUCCESS initialisation successful
+* @retval CPA_STATUS_RESOURCE array allocation failed
+*
+*****************************************************************************/
+CpaStatus dcStatsInit(sal_compression_service_t *pService);
+
+/**
+*******************************************************************************
+* @ingroup Dc_DataCompression
+* Frees the compression stats
+*
+* @description
+* This function frees the stats array
+*
+* @param[in] pService Pointer to a compression service structure
+*
+* @retval None
+*
+*****************************************************************************/
+void dcStatsFree(sal_compression_service_t *pService);
+
+#endif /* DC_STATS_H_ */