From 60a474f65b292e4f3522158a70b97b5bf9be0dbf Mon Sep 17 00:00:00 2001 From: Srikanth Thokala Date: Thu, 6 Aug 2026 18:48:40 +0530 Subject: [PATCH] QATlib: 26.08.0 release Changes from 26.02.0 to 26.08.0: * Added support for QAT Gen6 6xxx device, including Dictionary, Z-Standard, and KPT features, along with related sample codes. * Introduced the environment variable QAT_MAX_2M_HPG_PER_PROCESS to enable 2MB hugepages. * Introduced EPOLL coalesce timer support across all QATlib-supported devices. * Added sla_mgr script for device management related to rate-limiting feature. * Aligned with CPA API v5.09. * Bug Fixes. (See Resolved section in README.md) Signed-off-by: Srikanth Thokala --- INSTALL | 1 + Makefile.am | 15 +- README.md | 130 +- Samples.am | 87 +- configure.ac | 6 +- filelist | 36 +- m4/.gitkeep | 0 qat_sla_mgr.8 | 202 + qatlib.spec.in | 26 +- quickassist/include/cpa.h | 163 +- quickassist/include/dc/cpa_dc_chain.h | 5 +- quickassist/include/dc/cpa_dc_dp.h | 51 +- quickassist/include/lac/cpa_cy_key.h | 7 + quickassist/include/lac/cpa_cy_kpt.h | 3 +- quickassist/include/lac/cpa_cy_sym_dp.h | 17 +- .../access_layer/include/icp_accel_devices.h | 35 +- .../access_layer/include/icp_adf_debug.h | 97 - .../access_layer/include/icp_adf_init.h | 6 +- .../access_layer/include/icp_adf_transport.h | 37 + .../include/qat_library_version.h | 2 +- .../src/common/compression/dc_buffers.c | 231 +- .../src/common/compression/dc_capabilities.c | 158 +- .../src/common/compression/dc_chain.c | 405 +- .../src/common/compression/dc_crc64.c | 20 +- .../src/common/compression/dc_datapath.c | 155 +- .../src/common/compression/dc_dictionary.c | 67 +- .../src/common/compression/dc_ns_datapath.c | 26 +- .../src/common/compression/dc_session.c | 332 +- .../src/common/compression/dc_stats.c | 1 - .../compression/include/dc_capabilities.h | 110 +- .../src/common/compression/include/dc_chain.h | 4 + .../src/common/compression/include/dc_crc64.h | 2 +- .../common/compression/include/dc_datapath.h | 9 +- .../common/compression/include/dc_session.h | 43 +- .../asym/diffie_hellman/lac_dh_control_path.c | 1 - .../asym/diffie_hellman/lac_dh_data_path.c | 1 - .../crypto/asym/diffie_hellman/lac_dh_stats.c | 1 - .../src/common/crypto/asym/dsa/lac_dsa.c | 1 - .../src/common/crypto/asym/ecc/lac_ec.c | 119 +- .../common/crypto/asym/ecc/lac_ec_common.c | 16 +- .../src/common/crypto/asym/ecc/lac_ecdh.c | 1 - .../src/common/crypto/asym/ecc/lac_ecdsa.c | 91 +- .../src/common/crypto/asym/ecc/lac_ecsm2.c | 1 - .../common/crypto/asym/ecc/lac_kpt_ecdsa.c | 477 +- .../src/common/crypto/asym/include/lac_ec.h | 16 +- .../crypto/asym/include/lac_pke_qat_comms.h | 79 + .../crypto/asym/include/lac_pke_utils.h | 2 + .../common/crypto/asym/large_number/lac_ln.c | 1 - .../asym/pke_common/lac_pke_qat_comms.c | 159 +- .../crypto/asym/pke_common/lac_pke_utils.c | 1 - .../src/common/crypto/asym/prime/lac_prime.c | 1 - .../crypto/asym/rsa/lac_kpt_rsa_decrypt.c | 565 ++- .../src/common/crypto/asym/rsa/lac_rsa.c | 43 +- .../crypto/asym/rsa/lac_rsa_control_path.c | 1 - .../common/crypto/asym/rsa/lac_rsa_decrypt.c | 484 +- .../common/crypto/asym/rsa/lac_rsa_encrypt.c | 1 - .../common/crypto/asym/rsa/lac_rsa_keygen.c | 1 - .../src/common/crypto/asym/rsa/lac_rsa_p.h | 22 +- .../common/crypto/asym/rsa/lac_rsa_stats.c | 14 +- .../kpt/crypto/lac_kpt_crypto_qat_comms.c | 128 + .../kpt/include/lac_kpt_crypto_qat_comms.h | 116 + .../kpt/include/lac_kpt_pro_qat_comms.h | 199 + .../kpt/provision/lac_kpt_pro_qat_comms.c | 391 ++ .../crypto/kpt/provision/lac_kpt_provision.c | 350 +- .../src/common/crypto/sym/include/lac_sym.h | 3 + .../crypto/sym/include/lac_sym_cipher_defs.h | 10 - .../common/crypto/sym/include/lac_sym_hash.h | 27 + .../src/common/crypto/sym/key/lac_sym_key.c | 21 +- .../src/common/crypto/sym/lac_sym_alg_chain.c | 38 +- .../src/common/crypto/sym/lac_sym_api.c | 236 +- .../src/common/crypto/sym/lac_sym_auth_enc.c | 1 - .../src/common/crypto/sym/lac_sym_cb.c | 1 - .../src/common/crypto/sym/lac_sym_cipher.c | 38 +- .../common/crypto/sym/lac_sym_compile_check.c | 1 - .../src/common/crypto/sym/lac_sym_dp.c | 52 +- .../src/common/crypto/sym/lac_sym_hash.c | 76 +- .../crypto/sym/lac_sym_hash_hw_precomputes.c | 1 - .../crypto/sym/lac_sym_hash_sw_precomputes.c | 1 - .../src/common/crypto/sym/lac_sym_partial.c | 1 - .../src/common/crypto/sym/lac_sym_queue.c | 1 - .../src/common/crypto/sym/lac_sym_stats.c | 3 +- .../crypto/sym/qat/lac_sym_qat_cipher.c | 105 +- .../common/crypto/sym/qat/lac_sym_qat_hash.c | 91 +- .../sym/qat/lac_sym_qat_hash_defs_lookup.c | 89 +- .../common/crypto/sym/qat/lac_sym_qat_key.c | 1 - .../src/common/ctrl/sal_compression.c | 194 +- .../ctrl/sal_compression_capabilities.c | 220 +- .../src/common/ctrl/sal_create_services.c | 1 - .../access_layer/src/common/ctrl/sal_crypto.c | 859 +--- .../src/common/ctrl/sal_ctrl_services.c | 309 +- .../src/common/ctrl/sal_resp_type.c | 182 - .../src/common/ctrl/sal_transport_cfg.c | 364 ++ .../src/common/include/lac_common.h | 55 + .../access_layer/src/common/include/lac_log.h | 57 + .../src/common/include/lac_sal_types.h | 40 +- .../src/common/include/lac_sal_types_crypto.h | 6 +- .../src/common/include/sal_qat_cmn_msg.h | 18 + .../common/include/sal_types_compression.h | 3 - .../src/common/qat_comms/sal_qat_cmn_msg.c | 21 + .../src/common/utils/lac_buffer_desc.c | 1 - .../src/common/utils/lac_log_message.c | 1 - .../access_layer/src/common/utils/lac_mem.c | 31 +- .../src/common/utils/lac_mem_pools.c | 1 - .../src/common/utils/lac_sw_responses.c | 55 +- .../src/common/utils/sal_misc_error_stats.c | 1 - .../src/common/utils/sal_service_state.c | 1 - .../src/common/utils/sal_statistics.c | 1 - .../qat_direct/adf_io/vfio/adf_common_cfg.c | 14 +- .../adf_io/vfio/adf_common_user_bundles.c | 6 +- .../adf_io/vfio/adf_common_user_proxy.c | 11 +- .../src/qat_direct/adf_io/vfio/adf_pfvf_msg.h | 2 +- .../qat_direct/adf_io/vfio/adf_pfvf_proto.c | 36 +- .../qat_direct/adf_io/vfio/adf_pfvf_proto.h | 1 + .../qat_direct/adf_io/vfio/adf_pfvf_vf_msg.c | 11 +- .../src/qat_direct/adf_io/vfio/adf_vfio_pf.c | 36 +- .../src/qat_direct/adf_io/vfio/qat_mgr.h | 19 +- .../qat_direct/adf_io/vfio/qat_mgr_client.c | 90 +- .../src/qat_direct/adf_io/vfio/qat_mgr_lib.c | 88 +- .../src/qat_direct/adf_io/vfio/vfio_lib.c | 64 +- .../src/qat_direct/adf_io/vfio/vfio_mgr_lib.c | 235 +- .../src/qat_direct/include/adf_dev_ring_ctl.h | 2 + .../include/adf_platform_acceldev_common.h | 47 +- .../qat_direct/include/adf_platform_common.h | 44 +- .../src/qat_direct/include/adf_user_ring.h | 1 + .../src/qat_direct/include/icp_platform.h | 6 +- .../src/qat_direct/io/adf_user_device.c | 11 + .../src/qat_direct/io/adf_user_init.c | 16 +- .../src/qat_direct/io/adf_user_ring.c | 48 +- .../qat_direct/io/adf_user_transport_ctrl.c | 196 +- .../access_layer/src/sample_code/README.txt | 1 + .../kpt_ecdsa_sample/kpt_ecdsa_sample_main.c | 57 + .../kpt_ecdsa_sample/kpt_ecdsa_sample_op.c | 866 ++++ .../kpt/kpt_rsa_sample/kpt_rsa_sample_main.c | 57 + .../kpt/kpt_rsa_sample/kpt_rsa_sample_op.c | 884 ++++ .../functional/asym/kpt/kpt_sample_common.c | 570 +++ .../functional/asym/kpt/kpt_sample_common.h | 70 + .../functional/common/cpa_sample_utils.c | 215 +- .../cpa_chaining_sample_user.c | 26 + .../cpa_chaining_xstor_sample.c | 1305 +++++ .../cpa_dc_sample_user_dict.c | 80 + .../cpa_dc_stateless_sample_dict.c | 654 +++ .../dc/stateless_sample_dict/paper4 | 294 ++ .../dc/stateless_sample_dict/paper4.dict | 31 + .../cpa_decomp_sample_user.c | 77 + .../cpa_decomp_stateless_sample.c | 472 ++ .../decomp/decomp_stateless_sample/paper4.gz | Bin 0 -> 5603 bytes .../functional/include/cpa_sample_utils.h | 26 + .../hash_file_sample/cpa_hash_file_sample.c | 106 +- .../cpa_zuc128_sample.c} | 871 ++-- .../cpa_zuc128_sample_user.c} | 118 +- .../common/qat_perf_buffer_utils.c | 9 +- .../compression/cpa_sample_code_dc_dp.c | 594 ++- .../compression/cpa_sample_code_dc_perf.h | 33 +- .../compression/cpa_sample_code_dc_utils.c | 1874 +++++++- .../compression/cpa_sample_code_dc_utils.h | 553 ++- .../compression/cpa_sample_code_zlib.c | 3 + .../compression/qat_chaining_main.c | 193 +- .../compression/qat_compression_cnv_utils.h | 5 +- .../compression/qat_compression_main.c | 585 ++- .../compression/qat_compression_main.h | 142 +- .../compression/qat_compression_utils.c | 185 +- .../performance/cpa_sample_code_main.c | 4248 +++++++++++------ .../crypto/cpa_sample_code_crypto_utils.c | 1002 +++- .../crypto/cpa_sample_code_crypto_utils.h | 536 ++- .../crypto/cpa_sample_code_dh_perf.c | 10 +- .../crypto/cpa_sample_code_dsa_perf.c | 10 +- .../crypto/cpa_sample_code_ecdsa_perf.c | 254 +- .../crypto/cpa_sample_code_ike_dsa_perf.c | 2 +- .../crypto/cpa_sample_code_rsa_perf.c | 258 +- .../crypto/cpa_sample_code_sm2_perf.c | 63 + .../crypto/cpa_sample_code_sym_perf.c | 285 +- .../crypto/cpa_sample_code_sym_perf_dp.c | 89 +- .../performance/crypto/qat_sym_main.c | 325 +- .../performance/crypto/qat_sym_utils.c | 22 +- .../framework/cpa_sample_code_framework.c | 169 +- .../framework/cpa_sample_code_framework.h | 8 + .../linux/user_space/cpa_sample_code_utils.c | 449 +- .../linux/user_space/cpa_sample_code_utils.h | 76 +- .../qae/linux/kernel_space/qae_mem_utils.c | 171 - .../access_layer/src/user/sal_user.c | 1 - .../lookaside/firmware/include/icp_qat_fw.h | 32 + .../firmware/include/icp_qat_fw_comp.h | 31 +- .../firmware/include/icp_qat_fw_kpt_pro.h | 109 + .../firmware/include/icp_qat_fw_la.h | 55 + .../firmware/include/icp_qat_fw_mmp.h | 731 ++- .../firmware/include/icp_qat_fw_mmp_ids.h | 245 + .../lookaside/firmware/include/icp_qat_hw.h | 27 +- .../include/icp_qat_hw_20_comp_defs.h | 4 + .../firmware/include/icp_qat_hw_51_comp.h | 207 + .../include/icp_qat_hw_51_comp_defs.h | 753 +++ quickassist/utilities/apps/sla_mgr/README.md | 41 + .../utilities/apps/sla_mgr/qat_sla_mgr | 116 + .../utilities/apps/sla_mgr/qat_sla_rl.py | 437 ++ .../libusdm_drv/include/qae_mem_utils.h | 131 +- quickassist/utilities/libusdm_drv/qae_mem.h | 46 + .../libusdm_drv/user_space/qae_mem_common.c | 76 +- .../user_space/qae_mem_hugepage_utils.h | 2 + .../user_space/qae_mem_lib_utils.h | 10 +- .../user_space/qae_mem_multi_thread.h | 10 +- .../user_space/qae_mem_multi_thread_utils.c | 56 +- .../user_space/qae_mem_sysfs_utils.c | 173 + .../user_space/qae_mem_sysfs_utils.h | 61 + .../user_space/qae_mem_user_utils.h | 2 + .../user_space/qae_mem_utils_common.c | 42 +- .../user_space/qae_mem_utils_common.h | 41 +- .../user_space/qae_page_table_common.h | 145 +- .../user_space/qae_page_table_defs.h | 21 +- .../vfio/qae_mem_hugepage_utils_vfio.c | 136 +- .../user_space/vfio/qae_mem_utils_vfio.c | 26 +- quickassist/utilities/osal/include/Osal.h | 74 - .../utilities/osal/include/OsalDevDrvCommon.h | 254 - .../osal/src/linux/user_space/OsalServices.c | 2 +- .../src/linux/user_space/OsalUsrKrnProxy.c | 1280 ----- quickassist/utilities/qat_mgr/qat_mgr.c | 2 +- quickassist/utilities/service/qat_init.sh.in | 10 +- versionfile | 4 +- 216 files changed, 26550 insertions(+), 7750 deletions(-) delete mode 100644 m4/.gitkeep create mode 100644 qat_sla_mgr.8 delete mode 100644 quickassist/lookaside/access_layer/include/icp_adf_debug.h create mode 100644 quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c create mode 100644 quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_crypto_qat_comms.h create mode 100644 quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_pro_qat_comms.h create mode 100644 quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c delete mode 100644 quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c create mode 100644 quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c create mode 100644 quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/paper4.gz rename quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/{cpa_zuc_sample.c => zuc128_sample/cpa_zuc128_sample.c} (81%) rename quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/{cpa_zuc_sample_user.c => zuc128_sample/cpa_zuc128_sample_user.c} (84%) delete mode 100644 quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/kernel_space/qae_mem_utils.c create mode 100644 quickassist/lookaside/firmware/include/icp_qat_fw_kpt_pro.h create mode 100644 quickassist/lookaside/firmware/include/icp_qat_hw_51_comp.h create mode 100644 quickassist/lookaside/firmware/include/icp_qat_hw_51_comp_defs.h create mode 100644 quickassist/utilities/apps/sla_mgr/README.md create mode 100755 quickassist/utilities/apps/sla_mgr/qat_sla_mgr create mode 100755 quickassist/utilities/apps/sla_mgr/qat_sla_rl.py create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.h delete mode 100644 quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c diff --git a/INSTALL b/INSTALL index 137802d6..c49a87a7 100644 --- a/INSTALL +++ b/INSTALL @@ -79,6 +79,7 @@ Check System Prerequisites 401xx | 4942 | 4943 402xx | 4944 | 4945 420xx | 4946 | 4947 + 6xxx | 4948 | 4949 --------------------------- Examples in this doc are for the 4940 device. See https://intel.github.io/quickassist/qatlib/requirements.html#supported-devices diff --git a/Makefile.am b/Makefile.am index f80e4012..f7e4a8ab 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,6 @@ libosal_la_SOURCES = \ quickassist/utilities/osal/src/linux/user_space/OsalSpinLock.c \ quickassist/utilities/osal/src/linux/user_space/OsalAtomic.c \ quickassist/utilities/osal/src/linux/user_space/OsalServices.c \ - quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c \ quickassist/utilities/osal/src/linux/user_space/OsalCryptoInterface.c libosal_la_CFLAGS = -I$(srcdir)/quickassist/utilities/osal/src/linux/user_space \ @@ -116,6 +115,7 @@ lib_LTLIBRARIES = lib@LIBUSDMNAME@.la lib@LIBUSDMNAME@_la_SOURCES = \ quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_utils_vfio.c \ quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c \ + quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c \ quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_hugepage_utils_vfio.c if ICP_THREAD_SPECIFIC_USDM_AC lib@LIBUSDMNAME@_la_SOURCES += \ @@ -211,6 +211,8 @@ lib@LIBQATNAME@_la_SOURCES = \ quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_key.c \ quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_sw_precomputes.c \ quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c \ + quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c \ + quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_compression_capabilities.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_create_services.c \ @@ -218,7 +220,7 @@ lib@LIBQATNAME@_la_SOURCES = \ quickassist/lookaside/access_layer/src/common/ctrl/sal_list.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_rl_stubs.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c \ - quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c \ + quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_dc_chain.c \ quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c \ quickassist/lookaside/access_layer/src/common/qat_comms/sal_qat_cmn_msg.c \ @@ -253,6 +255,7 @@ lib@LIBQATNAME@_la_CFLAGS = -I$(srcdir)/quickassist/utilities/libusdm_drv \ -I$(srcdir)/quickassist/lookaside/access_layer/src/common/compression/include \ -I$(srcdir)/quickassist/lookaside/access_layer/src/common/crypto/sym/include \ -I$(srcdir)/quickassist/lookaside/access_layer/src/common/crypto/asym/include \ + -I$(srcdir)/quickassist/lookaside/access_layer/src/common/crypto/kpt/include \ -I$(srcdir)/quickassist/lookaside/firmware/include \ -I$(srcdir)/quickassist/lookaside/access_layer/src/common/include \ -I$(srcdir)/quickassist/lookaside/access_layer/include \ @@ -343,7 +346,12 @@ if SERVICE_AC fi endif -dist_man_MANS = qat_init.sh.8 qatmgr.8 cpa_sample_code.7 +qat_sla_mgrdir = $(sbindir) +dist_qat_sla_mgr_SCRIPTS = quickassist/utilities/apps/sla_mgr/qat_sla_mgr \ + quickassist/utilities/apps/sla_mgr/qat_sla_rl.py + +dist_man_MANS = qat_init.sh.8 qatmgr.8 cpa_sample_code.7 qat_sla_mgr.8 + EXTRA_DIST = INSTALL README.md SECURITY.md LICENSE \ filelist \ @@ -360,6 +368,7 @@ EXTRA_DIST = INSTALL README.md SECURITY.md LICENSE \ quickassist/utilities/libusdm_drv/user_space \ quickassist/utilities/service/qat \ quickassist/utilities/service/99-qat-vfio.rules.in \ + quickassist/utilities/apps/sla_mgr \ quickassist/lookaside/access_layer/src/sample_code DISTCHECK_CONFIGURE_FLAGS = \ diff --git a/README.md b/README.md index 759fab64..e18c2d53 100644 --- a/README.md +++ b/README.md @@ -27,23 +27,24 @@ | Date | Doc Revision | Version | Details | |----------|:-------------:|------:|:------| +| August 2026 | 020 | 26.08 | - Added support for QAT Gen6 6xxx device, including Dictionary, Z-Standard, and KPT features, along with related sample codes.
- Introduced the environment variable `QAT_MAX_2M_HPG_PER_PROCESS` to enable 2MB hugepages.
- Introduced EPOLL coalesce timer support across all QATlib-supported devices.
- Added sla_mgr script for device management related to rate-limiting feature.
- Updated [Features](#features) and [Limitations](#limitations) for 6xxx devices.
- Moved QAT20-42511, QATE-105912 and QAT20-42018 to [Resolved Issues](#resolved-issues). | | February 2026 | 019 | 26.02 | - Added support to configure EPOLL/POLL mode.
- Added USDM APIs to enable zero-copy DMA operations using IOVA mapping with user-allocated memory buffers.
- Simplified file license headers to use SPDX identifiers and only BSD3. Removed unnecessary Dual GPLv2/BSD3 license headers.
- Aligned with CPA API v5.08.
- Bug Fixes. See [Resolved Issues](#resolved-issues). | | September 2025 | 018 | | - Doc update only. Move QATE-106085 errata to Resolved section now that the fix is applied on the LTS kernel. See [Resolved Issues](#resolved-issues). | | August 2025 | 017 | | - Fix and document update for QAT5X-13672. See information in [Open Issues](#open-issues) section. | -| July 2025 | 016 | 25.08 | - Added support for Hugepages.
- Added No-IOMMU support for vfio.
- Added support for programmable CRCs to the DC Service
- Added a new API to query compression capabilities and marked the old API for deprecation.
- Enabled treating a CRC generated by the compression engine as an error. (See --enable-treat-crc-from-comp-engine-as-error).
- Enabled a performance optimization in the case where Queue Pairs are not shared across threads. (See --enable-icp-without-qp-submission-lock).
- Aligned with CPA API v5.06
- Bug Fixes. See [Resolved Issues](#resolved-issues). | +| July 2025 | 016 | 25.08 | - Added support for Hugepages.
- Added No-IOMMU support for vfio.
- Added support for programmable CRCs to the DC service
- Added `cpaDcQueryCapabilityByType` as new API to query compression capabilities and marked the old API `cpaDcQueryCapabilities` for deprecation.
- Enabled treating a CRC generated by the compression engine as an error. (See `--enable-treat-crc-from-comp-engine-as-error`).
- Enabled a performance optimization in the case where Queue Pairs are not shared across threads. (See `--enable-icp-without-qp-submission-lock`).
- Aligned with CPA API v5.06.
- Bug fixes. See [Resolved Issues](#resolved-issues). | | November 2024 | 015 | 24.09 | - Doc update only. Add QAT20-38022 information to [Open Issues](#open-issues) section. | -| September 2024 | 014 | 24.09 | - Improved performance scaling in multi-thread applications (--enable-icp-thread-specific-usdm).
- Bug Fixes. See [Resolved Issues](#resolved-issues).
- Set core affinity mapping based on NUMA node to improve performance (near-linear scaling) on multi-socket platforms. | +| September 2024 | 014 | 24.09 | - Improved performance scaling in multi-thread applications (`--enable-icp-thread-specific-usdm`).
- Bug Fixes. See [Resolved Issues](#resolved-issues).
- Set core affinity mapping based on NUMA node to improve performance (near-linear scaling) on multi-socket platforms. | | July 2024 | 013 | 24.02 | - Doc update only. Updated this table to say that support for the GEN4 402xx device was added in the 24.02 release. Added link to more details in Supported Devices section. | | February 2024 | 012 | 24.02 | - Added Heartbeat support.
- Added support for QAT GEN 5 devices, including support for a range of crypto wireless algorithms.
- RAS - Device error reset and recovery handling.
- Bug Fixes. See [Resolved Issues](#resolved-issues). | | November 2023 | 011 | 23.11 | - Support DC NS (NoSession) APIs.
- Support DC compressBound APIs.
- Support Symmetric Crypto SM3 & SM4.
- Support Asymmetric Crypto SM2.
- Bug Fixes. See [Resolved Issues](#resolved-issues). | | August 2023 | 010 | 23.08 | - Removal of following insecure algorithms: Diffie-Hellman and Elliptic curves less than 256-bits.
- Additional configuration profiles, including sym which facilitates improved symmetric crypto performance.
- DC Chaining (Hash then compress)
- Bug Fixes. See [Resolved Issues](#resolved-issues).
- The shared object version is changed from 3->4. | -| February 2023 | 009 | 23.02 | - Added configuration option --enable-legacy-algorithms to use these insecure crypto algorithms and disabled them by default (AES-ECB, SHA-1, SHA2-224, SHA3-224, RSA512/1024/1536, DSA)
- Refactored code in quickassist/utilities/libusdm_drv
- Bugfixes
- Updated documentation with configuration and tuning information | +| February 2023 | 009 | 23.02 | - Added configuration option `--enable-legacy-algorithms` to use these insecure crypto algorithms and disabled them by default (AES-ECB, SHA-1, SHA2-224, SHA3-224, RSA512/1024/1536, DSA)
- Refactored code in quickassist/utilities/libusdm_drv
- Bug fixes. See [Resolved Issues](#resolved-issues).
- Updated documentation with configuration and tuning information | | November 2022 | 008 | 22.07.2 | - Changed from yasm to nasm for assembly compilation
- Added configuration option to use C implementation of soft CRC implementation instead of asm
- Added support for pkg-config
- Added missing lock around accesses to some global data in qatmgr | | October 2022 | 007 | 22.07.1 | - Fix for QATE-86605 | | July 2022 | 006 | 22.07 | - Added support for lz4/lz4s compression algorithms
- Added support for Compression End-to-end (E2E) integrity check
- Added support for PKE generic point multiply
- Updated QAT APIs (as a result the shared object version changed from 2->3).
- Enabled CPM2.0b
- Split rpm package | | November 2021 | 005 | 21.11 | - Added qatlib-tests rpm package
- Added option to configure script to skip building sample code | | August 2021 | 004 | 21.08 | - Added support for deflate compression - Compress and Verify (CnV) and Compress and Verify and Recover (CnVnR)
- Added Physical Function to Virtual Function (PFVF) communication support | -| May 2021 | 003 | 21.05 | - Added support for AES-CCM 192/265
- Added support for SHA3-224/384/512 (no partials support)
- Added support for ChaCha20-Poly1305
- Added support for PKE 8K (RSA, DH, ModExp, ModInv)
- Fixed device enumeration on different nodes
- Fixed pci_vfio_set_command for 32 bit builds | +| May 2021 | 003 | 21.05 | - Added support for AES-CCM 192/256
- Added support for SHA3-224/384/512 (no partials support)
- Added support for ChaCha20-Poly1305
- Added support for PKE 8K (RSA, DH, ModExp, ModInv)
- Fixed device enumeration on different nodes
- Fixed pci_vfio_set_command for 32 bit builds | | November 2020 | 002 | 20.10 | - Fixed service stopping during uninstallation
- Fixed "Cannot open /sys/kernel/iommu_groups/vfio/devices/" error
- Fixes based on static code analysis
- Fixes based on secure code reviews
- Refactored logging mechanism
- Updated library versioning scheme
- Improvements to make install target
- Fix so service file installed in /usr/lib64 can be properly detected
- Remove execute permissions from non-executable files
- Clarified documentation of licensing
- Removed libudev dependency from the package
- Removed OpenSSL/libcrypto extracts, instead link against system OpenSSL/libcrypto | | August 2020 | 001 | 20.08 | - Initial Release | @@ -54,7 +55,7 @@ compression services from the CPU, thus significantly increasing the performance and efficiency of standard platform solutions. Its services include symmetric encryption and authentication, -asymmetric encryption, digital signatures, RSA, DH and ECC, and +asymmetric encryption (including digital signatures, RSA, DH and ECC), and lossless data compression. This package provides user space libraries that allow access to @@ -97,8 +98,27 @@ The following services are available in qatlib via the QuickAssist API: * End-to-end (E2E) integrity check * DC compressBound APIs * DC NS (No Session) APIs +* Key Protection Technology (KPT) +* Runtime configuration + * EPOLL/POLL mode configuration + * EPOLL coalesce timer duration configuration +* Queue Pair optimization + * When enabled, `--enable-icp-without-qp-submission-lock` applies to both submission and reception paths * Compression Chaining (Deflate only) * Hash then compress +* QAT Gen6 6xxx-specific APIs and behaviors + * Differential Power Analysis (DPA) side-channel protection APIs + * Auto-Select Best (ASB) APIs + * Z-Standard compression algorithm including + * Dictionary support + * compressBound() API + * Programmable CRC64 with dictionary compression + * Decompression as a standalone service + * Chaining modes with all algorithms + * Compress then encrypt and checksum calculation + * Decrypt then decompress and checksum calculation + * Checksum calculation with hash then compress chaining use case + * Compression determinism * Wireless Algorithms (supported on QAT GEN 5 devices) * Ciphers (SNOW3G-UEA2, ZUC-128, AES-F8) * Message digest/hash (SNOW3G-UIA2, ZUC-128) and authentication (AES-CMAC-128, AES-CMAC-192, AES-CMAC-256) @@ -107,7 +127,8 @@ This package includes: * libqat: user space library for QAT devices exposed via the vfio kernel driver * libusdm: user space library for memory management * qatmgr: user space daemon for device management -* Sample codes: applications to demo usage of the libs +* sla_mgr: Service Level Agreement (SLA) Manager scripts +* Sample codes: to demo usage of the libraries ## Insecure Algorithms The following algorithms are considered insecure and are disabled by default. @@ -117,15 +138,15 @@ The following algorithms are considered insecure and are disabled by default. * SHA3-224 * RSA512/1024/1536 * DSA -* Diffie-Helman -* Elliptic Curve Cryptography algorithms with less 256 bits +* Diffie-Hellman +* Elliptic Curve Cryptography algorithms with less than 256 bits * SM4-ECB To enable these algorithms, use the following configuration option: * `--enable-legacy-algorithms` ## Deprecated Features & Planned Deprecations -* The following configuration option will be deprecated after 2023: +* The following configuration option has been marked for deprecation and will be removed in a future release: * `--enable-legacy-lib-names` ## Setup @@ -134,6 +155,7 @@ Please refer to [INSTALL](INSTALL) for details on installing the library. ## Supported Devices * 4xxx, 401xx and 402xx (QAT GEN 4 devices) * 420xx (QAT GEN 5 devices) +* 6xxx (QAT GEN 6 devices) Earlier generations of QAT devices (e.g. c6xx, dh895xxcc, etc.) are not supported. Please refer to [QATlib User’s Guide](https://intel.github.io/quickassist/qatlib/requirements.html#supported-devices) for more information @@ -146,12 +168,29 @@ on supported devices. The following features are not currently supported: * Dynamic instances -* Intel® Key Protection Technology (KPT) * More than 16 processes per end point (16 is the maximum) * accumulateXXHash when combined with autoSelectBestHuffmanTree * accumulateXXHash in Decompression or Combined sessions -* Only 2MB Hugepages are supported. A client can not allocate more +* Only 2MB hugepages are supported. A client cannot allocate more than 2MB in a single allocation with hugepages enabled. + * To use 2MB hugepages, the environment variable `QAT_MAX_2M_HPG_PER_PROCESS` must be configured. + If not configured, the system defaults to the 4KB allocation path. +* On QAT GEN 6 devices: + * Crypto service limitations: + * Only AES-CTR, AES-GCM, AES-XTS and Chacha-Poly algorithms are supported + * Hash-Cipher chaining only supported for AES-GCM and Chacha-Poly + * No support for 192-bit key size + * No support for partial packet processing + * No support for HKDF + * No support for key generation (KeyGen) + * No support for digest truncation + * No support for nested hashing + * Compression service limitations: + * No support for checksum seeding, therefore it is not possible to accumulate checksum across operations. + * No support for static deflate + * In compression direction, the only maximum block size supported is 64KB. + * No support for Compress and Verify and Recover (CnVnR) + * DC overflow is treated as an error rather than an exception ## Environmental Assumptions @@ -178,7 +217,7 @@ Please refer to [Intel® QuickAssist Technology API Programmer's Guide](https:// Known issues relating to the Intel® QAT software are described in this section. -Additional Errata Information +**Additional Errata Information:** While this section covers known issues related to QATlib, users seeking information on errata items specific to QAT kernel drivers and firmware can refer to the Intel QuickAssist Technology @@ -205,32 +244,10 @@ where: \ is one of the following: | Issue ID | Description | |-------------|------------| -| QAT20-42511 | [GEN - QATlib acceleration services may fail due to broken PF/VF communication when compiling with GCC 16.1](#qat20-42511) | -| QATE-102747 | [GEN - Intel QAT Concurrent Initialization Failure in Standalone Mode](#qate-102747) | | QATE-102390 | [GEN - [error] validateConcurrRequest() - : Invalid numConcurrRequests](#qate-102390) | | QATE-3241 | [CY - cpaCySymPerformOp when used with parameter checking may reveal the amount of padding](#qate-3241) | | QATE-76073 | [GEN - If PF device configuration is modified without restarting qatmgr, undefined behavior may occur](#qate-76073) | -## QAT20-42511 -| Title | GEN - QATlib acceleration services may fail due to broken PF/VF communication when compiling with GCC 16.1 | -|----------|:-------------| -| Reference # | QAT20-42511 | -| Description | GCC 16.1 at -O2 may optimize a volatile 32-bit CSR read to a byte access when only one bit is tested. QAT mailbox CSRs require full DWORD transactions; the optimized read causes VF2PF ACK polling to time out, preventing QATlib to retrieve device configuration via PF/VF communication. In this scenario the QATlib process defaults to assuming it's working with an early kernel driver which only supports cryptographic services and fails to start compression or DCC instances. It will start cryptographic instances, but some of the operations may fail unless all QAT PFs are configured with `ServicesEnabled=asym;sym`. | -| Implication | Acceleration services may fail or applications may report no compression instances when built with GCC 16.1. | -| Resolution | Use an earlier version of GCC or if using GCC 16.1 compile with -fno-fuse-ops-with-volatile-access. Use `CFLAGS="-fno-fuse-ops-with-volatile-access" ./configure` | -| Affected OS | Linux | -| Driver/Module | CPM-IA - General | - -## QATE-102747 -| Title | GEN - Intel QAT Concurrent Initialization Failure in Standalone Mode | -|----------|:-------------| -| Reference # | QATE-102747 | -| Description | Concurrent initialization of the qatlib process in standalone mode may fail with an error message like: “err: Open vfio file /dev/vfio/481 failed!” This issue arises due to resource contention, particularly involving systemd-journald, which can hold the mutex required for VFIO operations. | -| Implication | Users may experience failures during the initialization of the qatlib process, leading to unsuccessful attempts to utilize QAT resources. This can affect applications relying on QAT for cryptographic or data compression operations, potentially causing delays or requiring manual intervention. | -| Resolution | The following may help to mitigate this issue: (1) Use kernel v6.14.5+, as this doesn't acquire the device mutex in journald or disable systemd-journald dev-log and restart it. (2) In standalone mode, instantiate QATlib processes sequentially to avoid contention. | -| Affected OS | Linux | -| Driver/Module | QATlib | - ## QATE-102390 | Title | GEN – [error] validateConcurrRequest() - : Invalid numConcurrRequests | |---------------|:-------------------------------------------------------------------| @@ -266,6 +283,9 @@ Resolved issues relating to the Intel® QAT software are described in this secti | Issue ID | Description | |-------------|------------| +| QAT20-42018 | [GEN - QAT Hardware Initialization Failure Due to Hugepage Allocation](#qat20-42018) | +| QAT20-42511 | [GEN - QATlib acceleration services may fail due to broken PF/VF communication when compiling with GCC 16.1](#qat20-42511) | +| QATE-105912 | [GEN - Intel QAT Concurrent Initialization Failure in Standalone Mode](#qate-105912) | | QAT20-41747 | [DC - Initialization fails on VFIO compression-only devices with "Error parsing enabled services from ADF"](#qat20-41747) | | QATE-106300 | [CY – CCP authenticated encryption can cause undefined behaviour if AAD size is not a 64-byte multiple](#qate-106300) | | QATE-106085 | [GEN - A QATlib process fails to start a 4xxx device on kernel v6.1 LTS](#qate-106085) | @@ -294,6 +314,36 @@ Resolved issues relating to the Intel® QAT software are described in this secti | QATE-76846 | [GEN - Forking and re-initializing use-cases do not work](#qate-76846) | | QATE-12241 | [CY - TLS1.2 with secret key lengths greater than 64 are not supported](#qate-12241) | +## QAT20-42018 +| Title | GEN - QAT Hardware Initialization Failure Due to Hugepage Allocation | +|----------|:-------------| +| Reference # | QAT20-42018 | +| Description | Starting with QATLib 25.08, QAT hardware initialization fails in IOMMU mode when hugepages are configured in the system but not available for QATLib use. The error manifests as "Unable to get ringbuf(v:(nil)) for rings in bank(0)" during ring buffer allocation. This occurs because QATLib 25.08 introduced hugepage support for the VFIO memory path, which routes DMA memory allocations through the hugepage path when `nr_hugepages > 0`, with no fallback to regular memory allocation on failure. | +| Implication | QAT hardware offload becomes unavailable in environments where hugepages are configured for other purposes but not intended for QAT use. This particularly affects mixed deployments using both IOMMU and non-IOMMU modes with a single system image, where fallback to non-hugepage memory allocation is required for IOMMU-based deployments. | +| Resolution | Fixed in 26.08. The fix introduces a new environment variable (`QAT_MAX_2M_HPG_PER_PROCESS`). 2MB hugepages will now be enabled only when the user/admin defines this environment variable per process. | +| Affected OS | Linux | +| Driver/Module | QATlib | + +## QAT20-42511 +| Title | GEN - QATlib acceleration services may fail due to broken PF/VF communication when compiling with GCC 16.1 | +|----------|:-------------| +| Reference # | QAT20-42511 | +| Description | GCC 16.1 at -O2 may optimize a volatile 32-bit CSR read to a byte access when only one bit is tested. QAT mailbox CSRs require full DWORD transactions; the optimized read causes VF2PF ACK polling to time out, preventing QATlib to retrieve device configuration via PF/VF communication. In this scenario the QATlib process defaults to assuming it's working with an early kernel driver which only supports cryptographic services and fails to start compression or DCC instances. It will start cryptographic instances, but some of the operations may fail unless all QAT PFs are configured with `ServicesEnabled=asym;sym`. | +| Implication | Acceleration services may fail or applications may report no compression instances when built with GCC 16.1. | +| Resolution | Fixed in 26.08. The fix enforces correct 32-bit CSR MMIO access in PF/VF mailbox handling so GCC 16.1 optimization does not break ACK polling and capability discovery. | +| Affected OS | Linux | +| Driver/Module | CPM-IA - General | + +## QATE-105912 +| Title | GEN - Intel QAT Concurrent Initialization Failure in Standalone Mode | +|----------|:-------------| +| Reference # | QATE-105912 | +| Description | Concurrent initialization of the qatlib process in standalone mode may fail with an error message like: “err: Open vfio file /dev/vfio/481 failed!” This issue arises due to resource contention, particularly involving systemd-journald, which can hold the mutex required for VFIO operations. | +| Implication | Users may experience failures during the initialization of the qatlib process, leading to unsuccessful attempts to utilize QAT resources. This can affect applications relying on QAT for cryptographic or data compression operations, potentially causing delays or requiring manual intervention. | +| Resolution | Fixed in 26.08. For releases prior to 26.08, mitigations include disabling systemd-journald dev-log and starting processes sequentially. | +| Affected OS | Linux | +| Driver/Module | QATlib | + ## QAT20-41747 | Title | DC - Initialization fails on VFIO compression-only devices with "Error parsing enabled services from ADF" | |---------------|:----------------------------------------------------------------------------------------------| @@ -425,11 +475,11 @@ Resolved issues relating to the Intel® QAT software are described in this secti | Driver/Module | CPM-IA - General | ## QATE-99637 -| Title | QAT instances on PCI domains other than 0000 are inaccessible | +| Title | GEN - QAT instances on PCI domains other than 0000 are inaccessible | |----------|:-------------| | Reference # | QATE-99637 | | Description | On multi-domain systems, QuickAssist Technology (QAT) devices that are assigned to PCI domains with identifiers other than the default '0000' are not recognized by the system. Consequently, the QAT instances associated with these devices do not appear available for use or configuration. | -| Implication | The inability to access QAT instances on non-default PCI domains prevents the utilization of QAT devices in those domains. This limitation restricts the deployment of QAT in environments with complex PCI topologies and can lead to under utilization of available hardware acceleration resources. | +| Implication | The inability to access QAT instances on non-default PCI domains prevents the utilization of QAT devices in those domains. This limitation restricts the deployment of QAT in environments with complex PCI topologies and can lead to underutilization of available hardware acceleration resources. | | Resolution | Fixed in 24.09 | | Affected OS | Linux | | Driver/Module | CPM-IA - General | @@ -537,7 +587,7 @@ Resolved issues relating to the Intel® QAT software are described in this secti ## QATE-78459 | Title | DC - cpaDcDeflateCompressBound API returns incorrect output buffer size when input size exceeds 477218588 bytes | |----------|:-------------| -| Reference # | QATE-74786 | +| Reference # | QATE-78459 | | Description | When cpaDcDeflateCompressBound API is called with input size > 477218588 bytes incorrect buffer size is returned. For any buffer input size, the API should not produce output buffer size greater than the max limit (4 GB). | | Implication | Incorrect output buffer size is returned instead of error. | | Resolution | The issue is not present in qatlib. | @@ -558,13 +608,13 @@ Resolved issues relating to the Intel® QAT software are described in this secti | Title | CY - TLS1.2 with secret key lengths greater than 64 are not supported | |----------|:-------------| | Reference # | QATE-12241 | -| Description | Algorithms, as with Diffie-Hellman using 8K parameters that can use a secret key length greater than 64 bytes is not supported.| +| Description | Algorithms such as Diffie-Hellman using 8K parameters, which can use a secret key length greater than 64 bytes, are not supported.| | Implication | Key generation would fail for TLS1.2 algorithms that use more than 64 bytes secret length keys. | | Resolution | Fixed in 22.07 | | Affected OS | Linux | | Driver/Module | CPM-IA - Crypto | - ## Licensing +## Licensing * This product is released under the BSD-3-Clause license. ## Legal @@ -581,7 +631,7 @@ Copyright © 2016-2026, Intel Corporation. All rights reserved. ## Terminology | Term | Description | -|----------|:-------------:| +|:--------:|:--------------| | API | Application Programming Interface | | BIOS | Basic Input/Output System | | BSD | Berkeley Standard Distribution | diff --git a/Samples.am b/Samples.am index c4e050b4..2e93fbcc 100644 --- a/Samples.am +++ b/Samples.am @@ -179,10 +179,23 @@ dc_stateless_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/ $(COMMON_FLAGS) dc_stateless_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la +noinst_PROGRAMS += dc_stateless_sample_dict +dc_stateless_sample_dict_SOURCES = \ + quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c +dc_stateless_sample_dict_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ + $(COMMON_SAMPLE_INCLUDES) \ + $(COMMON_SAMPLE_CFLAGS) \ + $(COMMON_FLAGS) \ + -DSAMPLE_CODE_CORPUS_PATH="\"$(datadir)/qat/\"" +dc_stateless_sample_dict_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la + noinst_PROGRAMS += chaining_sample chaining_sample_SOURCES = \ quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c \ quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c chaining_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ $(COMMON_SAMPLE_INCLUDES) \ @@ -201,6 +214,18 @@ dc_stateless_multi_op_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_l $(COMMON_FLAGS) dc_stateless_multi_op_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la +noinst_PROGRAMS += decomp_stateless_sample +decomp_stateless_sample_SOURCES = \ + quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c +decomp_stateless_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ + $(COMMON_SAMPLE_INCLUDES) \ + $(COMMON_SAMPLE_CFLAGS) \ + $(COMMON_FLAGS) \ + -DSAMPLE_CODE_CORPUS_PATH="\"$(datadir)/qat/\"" +decomp_stateless_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la + noinst_PROGRAMS += algchaining_sample algchaining_sample_SOURCES = \ quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ @@ -360,16 +385,44 @@ ec_montedwds_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/ $(COMMON_FLAGS) ec_montedwds_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la -noinst_PROGRAMS += zuc_sample -zuc_sample_SOURCES = \ +noinst_PROGRAMS += kpt_rsa_sample +kpt_rsa_sample_SOURCES = \ + quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h +kpt_rsa_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ + -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt \ + $(COMMON_SAMPLE_INCLUDES) \ + $(COMMON_SAMPLE_CFLAGS) \ + $(COMMON_FLAGS) +kpt_rsa_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la + +noinst_PROGRAMS += kpt_ecdsa_sample +kpt_ecdsa_sample_SOURCES = \ + quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h +kpt_ecdsa_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ + -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt \ + $(COMMON_SAMPLE_INCLUDES) \ + $(COMMON_SAMPLE_CFLAGS) \ + $(COMMON_FLAGS) +kpt_ecdsa_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la + +noinst_PROGRAMS += zuc128_sample +zuc128_sample_SOURCES = \ quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c \ - quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample.c \ - quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample_user.c -zuc_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ + quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample.c \ + quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample_user.c +zuc128_sample_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/include \ $(COMMON_SAMPLE_INCLUDES) \ $(COMMON_SAMPLE_CFLAGS) \ $(COMMON_FLAGS) -zuc_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la +zuc128_sample_LDADD = $(COMMON_SAMPLE_LDFLAGS) libcpa_sample_code_s.la noinst_PROGRAMS += update_sample update_sample_SOURCES = \ @@ -385,14 +438,18 @@ samples: $(lib_LTLIBRARIES) cpa_sample_code dc_dp_sample dc_stateless_sample \ dc_stateless_multi_op_sample algchaining_sample ccm_sample \ cipher_sample gcm_sample hash_file_sample hash_sample ipsec_sample \ ssl_sample sym_dp_sample dh_sample prime_sample hkdf_sample \ - ec_montedwds_sample eddsa_sample chaining_sample zuc_sample update_sample + ec_montedwds_sample kpt_rsa_sample kpt_ecdsa_sample eddsa_sample \ + chaining_sample zuc128_sample update_sample dc_stateless_sample_dict \ + decomp_stateless_sample samples-install: samples @install -D -m 755 $(srcdir)/.libs/cpa_sample_code $(DESTDIR)$(bindir)/cpa_sample_code @install -D -m 755 $(srcdir)/.libs/dc_dp_sample $(DESTDIR)$(bindir)/dc_dp_sample @install -D -m 755 $(srcdir)/.libs/dc_stateless_sample $(DESTDIR)$(bindir)/dc_stateless_sample + @install -D -m 755 $(srcdir)/.libs/dc_stateless_sample_dict $(DESTDIR)$(bindir)/dc_stateless_sample_dict @install -D -m 755 $(srcdir)/.libs/chaining_sample $(DESTDIR)$(bindir)/chaining_sample @install -D -m 755 $(srcdir)/.libs/dc_stateless_multi_op_sample $(DESTDIR)$(bindir)/dc_stateless_multi_op_sample + @install -D -m 755 $(srcdir)/.libs/decomp_stateless_sample $(DESTDIR)$(bindir)/decomp_stateless_sample @install -D -m 755 $(srcdir)/.libs/algchaining_sample $(DESTDIR)$(bindir)/algchaining_sample @install -D -m 755 $(srcdir)/.libs/ccm_sample $(DESTDIR)$(bindir)/ccm_sample @install -D -m 755 $(srcdir)/.libs/cipher_sample $(DESTDIR)$(bindir)/cipher_sample @@ -407,11 +464,16 @@ samples-install: samples @install -D -m 755 $(srcdir)/.libs/prime_sample $(DESTDIR)$(bindir)/prime_sample @install -D -m 755 $(srcdir)/.libs/hkdf_sample $(DESTDIR)$(bindir)/hkdf_sample @install -D -m 755 $(srcdir)/.libs/ec_montedwds_sample $(DESTDIR)$(bindir)/ec_montedwds_sample - @install -D -m 755 $(srcdir)/.libs/zuc_sample $(DESTDIR)$(bindir)/zuc_sample + @install -D -m 755 $(srcdir)/.libs/zuc128_sample $(DESTDIR)$(bindir)/zuc128_sample + @install -D -m 755 $(srcdir)/.libs/kpt_rsa_sample $(DESTDIR)$(bindir)/kpt_rsa_sample + @install -D -m 755 $(srcdir)/.libs/kpt_ecdsa_sample $(DESTDIR)$(bindir)/kpt_ecdsa_sample @install -D -m 755 $(srcdir)/.libs/update_sample $(DESTDIR)$(bindir)/update_sample @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/performance/compression/calgary $(DESTDIR)$(datadir)/qat/calgary @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/performance/compression/calgary32 $(DESTDIR)$(datadir)/qat/calgary32 @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/performance/compression/canterbury $(DESTDIR)$(datadir)/qat/canterbury + @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict $(DESTDIR)$(datadir)/qat/paper4.dict + @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 $(DESTDIR)$(datadir)/qat/paper4 + @install -D -m 644 $(srcdir)/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/paper4.gz $(DESTDIR)$(datadir)/qat/paper4.gz @echo "" @echo "*******************************************************" @echo "* cpa_sample_code installed under $(DESTDIR)$(bindir) *" @@ -422,8 +484,10 @@ samples-uninstall: @rm -rf $(DESTDIR)$(bindir)/cpa_sample_code @rm -rf $(DESTDIR)$(bindir)/dc_dp_sample @rm -rf $(DESTDIR)$(bindir)/dc_stateless_sample + @rm -rf $(DESTDIR)$(bindir)/dc_stateless_sample_dict @rm -rf $(DESTDIR)$(bindir)/chaining_sample @rm -rf $(DESTDIR)$(bindir)/dc_stateless_multi_op_sample + @rm -rf $(DESTDIR)$(bindir)/decomp_stateless_sample @rm -rf $(DESTDIR)$(bindir)/algchaining_sample @rm -rf $(DESTDIR)$(bindir)/ccm_sample @rm -rf $(DESTDIR)$(bindir)/cipher_sample @@ -438,11 +502,16 @@ samples-uninstall: @rm -rf $(DESTDIR)$(bindir)/prime_sample @rm -rf $(DESTDIR)$(bindir)/hkdf_sample @rm -rf $(DESTDIR)$(bindir)/ec_montedwds_sample - @rm -rf $(DESTDIR)$(bindir)/zuc_sample + @rm -rf $(DESTDIR)$(bindir)/zuc128_sample + @rm -rf $(DESTDIR)$(bindir)/kpt_ecdsa_sample + @rm -rf $(DESTDIR)$(bindir)/kpt_rsa_sample @rm -rf $(DESTDIR)$(bindir)/update_sample @rm -rf $(DESTDIR)$(datadir)/qat/calgary @rm -rf $(DESTDIR)$(datadir)/qat/calgary32 @rm -rf $(DESTDIR)$(datadir)/qat/canterbury + @rm -rf $(DESTDIR)$(datadir)/qat/paper4.dict + @rm -rf $(DESTDIR)$(datadir)/qat/paper4 + @rm -rf $(DESTDIR)$(datadir)/qat/paper4.gz @if test -d $(DESTDIR)$(datadir)/qat; then rmdir --ignore-fail-on-non-empty $(DESTDIR)$(datadir)/qat; fi endif diff --git a/configure.ac b/configure.ac index ee482627..3a75f0f0 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([qatlib], [26.02.0], [qat-linux@intel.com]) +AC_INIT([qatlib], [26.08.0], [qat-linux@intel.com]) AM_INIT_AUTOMAKE([-Wall -Wno-portability foreign subdir-objects tar-pax]) AM_SILENT_RULES([yes]) @@ -11,8 +11,8 @@ AC_USE_SYSTEM_EXTENSIONS AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_HEADERS([config.h]) -AC_SUBST([LIBQAT_VERSION], [9:0:5]) -AC_SUBST([LIBUSDM_VERSION], [2:0:2]) +AC_SUBST([LIBQAT_VERSION], [10:0:6]) +AC_SUBST([LIBUSDM_VERSION], [2:1:2]) # Checks for programs. AC_PROG_AWK diff --git a/filelist b/filelist index 2da5c915..51bbde1c 100644 --- a/filelist +++ b/filelist @@ -11,6 +11,7 @@ filelist libqat.pc.in libusdm.pc.in qat_init.sh.8 +qat_sla_mgr.8 qatlib.pc.in qatlib.spec.in qatlib.sysusers.conf @@ -44,7 +45,6 @@ quickassist/lookaside/access_layer/include/adf_kernel_types.h quickassist/lookaside/access_layer/include/icp_accel_devices.h quickassist/lookaside/access_layer/include/icp_adf_accel_mgr.h quickassist/lookaside/access_layer/include/icp_adf_cfg.h -quickassist/lookaside/access_layer/include/icp_adf_debug.h quickassist/lookaside/access_layer/include/icp_adf_init.h quickassist/lookaside/access_layer/include/icp_adf_poll.h quickassist/lookaside/access_layer/include/icp_adf_transport.h @@ -132,6 +132,10 @@ quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_keygen.c quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_p.h quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats.c quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats_p.h +quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c +quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_crypto_qat_comms.h +quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_pro_qat_comms.h +quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c quickassist/lookaside/access_layer/src/common/crypto/sym/drbg/lac_sym_drbg_api.c quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_session.h @@ -183,8 +187,8 @@ quickassist/lookaside/access_layer/src/common/ctrl/sal_ctrl_services.c quickassist/lookaside/access_layer/src/common/ctrl/sal_dc_chain.c quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c quickassist/lookaside/access_layer/src/common/ctrl/sal_list.c -quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c quickassist/lookaside/access_layer/src/common/ctrl/sal_rl_stubs.c +quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c quickassist/lookaside/access_layer/src/common/include/lac_buffer_desc.h quickassist/lookaside/access_layer/src/common/include/lac_common.h @@ -279,17 +283,31 @@ quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/ quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.h quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample_user.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c +quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample_user.c quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_input.h quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c +quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample_user.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_multi_op_checksum_sample/cpa_dc_stateless_multi_op_checksum_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_sample_user.c quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_stateless_sample.c +quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c +quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c +quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 +quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict +quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c +quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c +quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/paper4.gz quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_cnv_utils.h quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_utils.h quickassist/lookaside/access_layer/src/sample_code/functional/sym/alg_chaining_sample/cpa_algchaining_sample.c @@ -315,8 +333,8 @@ quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/c quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/cpa_sym_dp_sample_user.c quickassist/lookaside/access_layer/src/sample_code/functional/sym/update_sample/cpa_sym_dp_update_sample.c quickassist/lookaside/access_layer/src/sample_code/functional/sym/update_sample/cpa_sym_dp_update_sample_user.c -quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample.c -quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample_user.c +quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample.c +quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample_user.c quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.c quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.h quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_cycles.h @@ -388,7 +406,6 @@ quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sam quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_utils_common.h quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.c quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.h -quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/kernel_space/qae_mem_utils.c quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/user_space/qae_mem_utils.c quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem.h quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem_utils.h @@ -399,6 +416,7 @@ quickassist/lookaside/firmware/include/icp_qat_fw.h quickassist/lookaside/firmware/include/icp_qat_fw_comp.h quickassist/lookaside/firmware/include/icp_qat_fw_dc_chain.h quickassist/lookaside/firmware/include/icp_qat_fw_init_admin.h +quickassist/lookaside/firmware/include/icp_qat_fw_kpt_pro.h quickassist/lookaside/firmware/include/icp_qat_fw_la.h quickassist/lookaside/firmware/include/icp_qat_fw_mmp.h quickassist/lookaside/firmware/include/icp_qat_fw_mmp_ids.h @@ -406,6 +424,11 @@ quickassist/lookaside/firmware/include/icp_qat_fw_pke.h quickassist/lookaside/firmware/include/icp_qat_hw.h quickassist/lookaside/firmware/include/icp_qat_hw_20_comp.h quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h +quickassist/lookaside/firmware/include/icp_qat_hw_51_comp.h +quickassist/lookaside/firmware/include/icp_qat_hw_51_comp_defs.h +quickassist/utilities/apps/sla_mgr/README.md +quickassist/utilities/apps/sla_mgr/qat_sla_mgr +quickassist/utilities/apps/sla_mgr/qat_sla_rl.py quickassist/utilities/libusdm_drv/include/qae_mem_utils.h quickassist/utilities/libusdm_drv/qae_mem.h quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c @@ -413,6 +436,8 @@ quickassist/utilities/libusdm_drv/user_space/qae_mem_hugepage_utils.h quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c +quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c +quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.h quickassist/utilities/libusdm_drv/user_space/qae_mem_user_utils.h quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.h @@ -430,7 +455,6 @@ quickassist/utilities/osal/src/linux/user_space/OsalSemaphore.c quickassist/utilities/osal/src/linux/user_space/OsalServices.c quickassist/utilities/osal/src/linux/user_space/OsalSpinLock.c quickassist/utilities/osal/src/linux/user_space/OsalThread.c -quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c quickassist/utilities/osal/src/linux/user_space/include/OsalDevDrv.h quickassist/utilities/osal/src/linux/user_space/include/OsalOsTypes.h quickassist/utilities/qat_mgr/qat_mgr.c diff --git a/m4/.gitkeep b/m4/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/qat_sla_mgr.8 b/qat_sla_mgr.8 new file mode 100644 index 00000000..d68a8112 --- /dev/null +++ b/qat_sla_mgr.8 @@ -0,0 +1,202 @@ +.\" SPDX-License-Identifier: BSD-3-Clause +.\" Copyright(c) 2007-2026 Intel Corporation +.\" +.\" These contents may have been developed with support from one or more +.\" Intel-operated generative artificial intelligence solutions. +.\" +.TH QAT_SLA_MGR 8 "August 2026" "Intel QAT" "System Administration Commands" +.SH NAME +qat_sla_mgr \- manage QAT rate limiting Service Level Agreements +.SH SYNOPSIS +.B qat_sla_mgr +.I command +.RI [ arguments ] +.SH DESCRIPTION +.B qat_sla_mgr +is the command-line interface for managing rate limiting Service Level +Agreements (SLAs) on Intel QuickAssist Technology (QAT) devices using the +in-tree kernel driver. +.PP +It operates on the sysfs interface exposed by the +.B intel_qat +kernel module. Root access is required. All throughput values are expressed in +Megabits per second (Mbps). +.PP +SLAs are managed at the Physical Function (PF) level. The VF address is only +needed at creation time to derive the ring-pair mask. VFs passed through to a +guest VM are not supported. +.PP +Both +.B qat_sla_mgr +and +.B qat_sla_rl.py +must reside in the same directory. +.SH COMMANDS +.TP +.BI "create " "vf_addr cir pir service" +Create a new SLA for the given VF address. Prints the assigned SLA ID on +success. Use this ID with the PF address for subsequent +.BR update " and " delete +operations. +.RS +.TP +.I vf_addr +PCI Bus:Device.Function address of the VF (e.g. 6b:01.0 or 0000:6b:01.0). +.TP +.I cir +Committed Information Rate in Mbps. Must be a positive integer. +.TP +.I pir +Peak Information Rate in Mbps. Must be greater than or equal to +.IR cir . +.TP +.I service +Service type. One of: +.BR asym ", " sym ", " dc ", " decomp ", " dcc . +.RE +.TP +.BI "update " "pf_addr sla_id cir pir" +Update an existing SLA identified by +.IR sla_id . +.RS +.TP +.I pf_addr +PCI address of the PF. +.TP +.I sla_id +SLA identifier returned by the +.B create +command. +.TP +.I cir +New Committed Information Rate in Mbps. +.TP +.I pir +New Peak Information Rate in Mbps. +.RE +.TP +.BI "delete " "pf_addr sla_id" +Delete the SLA identified by +.IR sla_id . +.TP +.BI "delete_all " "pf_addr" +Delete all SLAs on the given PF. +.TP +.BI "list " "pf_addr" +List all configured SLAs on the given PF. For each SLA, prints the ID, CIR, +PIR (in Mbps), service type, ring-pair mask, and VF address (if SR-IOV is +enabled). +.TP +.BI "caps " "pf_addr" +Print the maximum and remaining capacity (in Mbps) for every service +configured on the device. Services are discovered at runtime via sysfs. +.TP +.B help +Display a brief usage summary. +.SH PCI ADDRESS FORMAT +PCI addresses may be specified with or without the domain prefix: +.RS +.TP +.B BB:DD.F +Bus, Device, Function (domain defaults to 0000). +.TP +.B DDDD:BB:DD.F +Domain, Bus, Device, Function. +.RE +.SH SERVICES +.TP +.B asym +Asymmetric cryptography. +.TP +.B sym +Symmetric cryptography. +.TP +.B dc +Compression. +.TP +.B decomp +Decompression. +.TP +.B dcc +Chained compression and crypto. +.SH EXIT STATUS +.TP +.B 0 +Success. +.TP +.B 1 +Failure. An error message is printed to stdout with details; check the kernel +log for additional information. +.SH EXAMPLES +Query all device capabilities: +.RS +.nf +# ./qat_sla_mgr caps 0000:6b:00.0 +Remaining capacity for 'asym' is: 173750 of: 173750 +Remaining capacity for 'dc' is: 45000 of: 45000 +Remaining capacity for 'sym' is: 95000 of: 95000 +.fi +.RE +.PP +Create an SLA for a VF with 5000 Mbps CIR and 9000 Mbps PIR: +.RS +.nf +# ./qat_sla_mgr create 0000:6b:01.0 5000 9000 sym +SLA ID: 0 +.fi +.RE +.PP +List SLAs on a PF: +.RS +.nf +# ./qat_sla_mgr list 0000:6b:00.0 + SLA ID: 0 + CIR: 5000 + PIR: 9000 + SRV: sym + RP: 0xf + VF: 0000:6b:01.0 +.fi +.RE +.PP +Update SLA 0 to 8000/8000 Mbps: +.RS +.nf +# ./qat_sla_mgr update 0000:6b:00.0 0 8000 8000 +.fi +.RE +.PP +Delete SLA 0: +.RS +.nf +# ./qat_sla_mgr delete 0000:6b:00.0 0 +.fi +.RE +.PP +Delete all SLAs on a PF: +.RS +.nf +# ./qat_sla_mgr delete_all 0000:6b:00.0 +.fi +.RE +.SH ENVIRONMENT +.B qat_sla_mgr +requires the +.B intel_qat +in-tree kernel module to be loaded. If an out-of-tree QAT driver is detected, +an error message directs the user to the appropriate out-of-tree utility. +.SH FILES +.TP +.I /sys/bus/pci/devices//qat_rl/ +Sysfs directory used by the kernel for rate limiting configuration. +.TP +.I /sys/bus/pci/devices//qat/rp2srv +Sysfs file mapping ring pairs to services; used by +.B caps +to discover configured services. +.SH SEE ALSO +Kernel sysfs-driver-qat_rl documentation: +.PP +.I https://docs.kernel.org/ABI/testing/sysfs-driver-qat_rl +.SH AUTHORS +Intel Corporation. diff --git a/qatlib.spec.in b/qatlib.spec.in index 0b0d2ab3..626ad45c 100644 --- a/qatlib.spec.in +++ b/qatlib.spec.in @@ -54,6 +54,15 @@ Requires: %{name}%{?_isa} = %{version}-%{release} This package contains a daemon that manages QAT resources for the Intel QuickAssist Technology user space library (qatlib). +%package tools +Summary: Utilities for Intel QAT device configuration +Requires: %{name}%{?_isa} = %{version}-%{release} +Requires: python3 + +%description tools +This package provides command-line utilities for managing Intel QuickAssist +Technology (QAT) devices. + %prep %autosetup -p1 @@ -110,6 +119,8 @@ fi %attr(0754,-,qat) %{_bindir}/cpa_sample_code %attr(0754,-,qat) %{_bindir}/dc_dp_sample %attr(0754,-,qat) %{_bindir}/dc_stateless_sample +%attr(0754,-,qat) %{_bindir}/dc_stateless_sample_dict +%attr(0754,-,qat) %{_bindir}/decomp_stateless_sample %attr(0754,-,qat) %{_bindir}/chaining_sample %attr(0754,-,qat) %{_bindir}/dc_stateless_multi_op_sample %attr(0754,-,qat) %{_bindir}/algchaining_sample @@ -123,14 +134,19 @@ fi %attr(0754,-,qat) %{_bindir}/sym_dp_sample %attr(0754,-,qat) %{_bindir}/dh_sample %attr(0754,-,qat) %{_bindir}/eddsa_sample +%attr(0754,-,qat) %{_bindir}/kpt_rsa_sample +%attr(0754,-,qat) %{_bindir}/kpt_ecdsa_sample %attr(0754,-,qat) %{_bindir}/prime_sample %attr(0754,-,qat) %{_bindir}/hkdf_sample %attr(0754,-,qat) %{_bindir}/ec_montedwds_sample -%attr(0754,-,qat) %{_bindir}/zuc_sample +%attr(0754,-,qat) %{_bindir}/zuc128_sample %attr(0754,-,qat) %{_bindir}/update_sample %{_datadir}/qat/calgary %{_datadir}/qat/calgary32 %{_datadir}/qat/canterbury +%{_datadir}/qat/paper4 +%{_datadir}/qat/paper4.dict +%{_datadir}/qat/paper4.gz %{_mandir}/man7/cpa_sample_code.7* %files service @@ -141,7 +157,15 @@ fi %{_mandir}/man8/qatmgr.8* %{_mandir}/man8/qat_init.sh.8* +%files tools +%{_sbindir}/qat_sla_mgr +%{_sbindir}/qat_sla_rl.py +%{_mandir}/man8/qat_sla_mgr.8* + %changelog +* Fri Jul 10 2026 Nandhini Srikandan - 26.08.0-1 +- update to qatlib 26.08.0 + * Wed Dec 17 2025 Harshita Bhilwaria - 26.02.0-1 - update to qatlib 26.02.0 diff --git a/quickassist/include/cpa.h b/quickassist/include/cpa.h index 43b32def..917f3df7 100644 --- a/quickassist/include/cpa.h +++ b/quickassist/include/cpa.h @@ -96,7 +96,7 @@ extern "C" { * when minor changes to the API have occurred. * *****************************************************************************/ -#define CPA_API_VERSION_NUM_MINOR (8) +#define CPA_API_VERSION_NUM_MINOR (9) /** ***************************************************************************** @@ -287,7 +287,10 @@ typedef struct * the length is always unchanged. */ Cpa32U reserved; - /**< Reserved for alignment */ + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ CpaPhysicalAddr bufferPhysAddr; /**< The physical address at which the data resides. The data pointed * to is required to be in contiguous physical memory. @@ -311,11 +314,17 @@ typedef struct typedef struct { Cpa64U reserved0; - /**< Reserved for internal usage */ + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ Cpa32U numBuffers; /**< Number of buffers in the list */ Cpa32U reserved1; - /**< Reserved for alignment */ + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ CpaPhysFlatBuffer flatBuffers[]; /**< Array of flat buffer structures, of size numBuffers */ } CpaPhysBufferList; @@ -1134,6 +1143,152 @@ CpaStatus cpaAllocInstance(const CpaAccelerationServiceType serviceType, *****************************************************************************/ CpaStatus cpaFreeInstance(CpaInstanceHandle instanceHandle); +/** + ***************************************************************************** + * @ingroup cpa_BaseDataTypes + * Meta data relating to the interrupt used for collecting responses. + * + * @description + * This struct holds data which is useful when configuring the interrupt + * used to notify users that a service instance has responses ready. + *****************************************************************************/ +typedef struct +{ + Cpa32U coalescingTimerInNs; + /**< The value of the Interrupt Coalescing Timer in nanoseconds */ + Cpa32U coalescingTimerMaxInNs; + /**< The maximum value to which the Interrupt Coalescing Timer can be set + * This may vary for different libraries or devices. + */ + Cpa32U coalescingTimerGranularityInNs; + /**< It may not be possible to configure the hardware to a granularity of + * 1ns, so this indicates the increments which can be differentiated when + * setting the Interrupt Coalescing Timer. + */ + Cpa32U reserved1; + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ + Cpa64U reserved2; + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ +} CpaRxInterruptMetaData; + +/** + ***************************************************************************** + * @ingroup cpa + * Read the Interrupt data for an instance + * + * @description + * Read the currently configured value of the Interrupt Coalescing Timer + * for the instance and metadata useful for re-configuring it. + * + * @context + * This is a synchronous function and it cannot sleep. It can be + * executed in a context that does not permit sleeping. It may be called + * regardless of the CpaInstanceResponseMode configured on the instance, + * though the timer is only used when the mode is set to + * CPA_INST_RX_NOTIFY_BY_EVENT. + * @assumptions + * None + * @sideEffects + * None + * @blocking + * No + * @reentrant + * No + * @threadSafe + * Yes + * + * @param[in] instanceHandle Instance handle. + * @param[in] accelerationServiceType This must match the acceleration service + * supported by the instance, except for + * CPA_ACC_SVC_TYPE_CRYPTO. In this case + * the instance supports two services, so + * this parameter must be set to either + * CPA_ACC_SVC_TYPE_CRYPTO_ASYM or + * CPA_ACC_SVC_TYPE_CRYPTO_SYM. + * @param[out] pInterruptData Pointer to the location where the + * interrupt data will be stored. + * + * @retval CPA_STATUS_SUCCESS Values read successfully. + * @retval CPA_STATUS_FAIL Configuration failed. + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter. + * @retval CPA_STATUS_UNSUPPORTED Not supported. + * + * @see + * cpaInstanceSetIntCoalescingTimer() + * cpaInstanceSetResponseMode() + * cpaInstanceGetResponseMode() + *****************************************************************************/ +CpaStatus cpaInstanceGetRxInterruptMetaData( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + CpaRxInterruptMetaData *pInterruptData); + +/** + ***************************************************************************** + * @ingroup cpa + * Set the Interrupt Coalescing Timer for an instance + * + * @description + * This function configures the Interrupt Coalescing Timer value in + * nanoseconds for a service instance. When the response mode for the + * service is set to CPA_INST_RX_NOTIFY_BY_EVENT, interrupts will be + * coalesced until this timer expires. + * It is recommended to call cpaInstanceGetRxInterruptMetaData to read the + * associated metadata before calling this set API. This set API may be + * passed any value between 0 and coalescingTimerMaxInNs. However the + * actual value configured on the instance may be rounded by + * +/- coalescingTimerGranularityInNs, so it is recommended to + * make changes to the configuration in intervals larger than that. + * Setting it to 0 will effectively disable interrupt coalescing. + * + * @context + * This function MUST NOT be called from an interrupt context as it MAY + * sleep. It may be called regardless of the CpaInstanceResponseMode + * configured on the instance, though the timer is only used when the + * mode is set to CPA_INST_RX_NOTIFY_BY_EVENT. + * @assumptions + * None + * @sideEffects + * None + * @blocking + * This function is synchronous and blocking. + * @reentrant + * No + * @threadSafe + * Yes + * + * @param[in] instanceHandle Instance handle + * @param[in] accelerationServiceType This must match the acceleration service + * supported by the instance, except for + * CPA_ACC_SVC_TYPE_CRYPTO. In this case + * the instance supports two services, and + * the timer can be set independently on each + * so this parameter must be set to either + * CPA_ACC_SVC_TYPE_CRYPTO_ASYM or + * CPA_ACC_SVC_TYPE_CRYPTO_SYM. + * @param[in] coalescingTimerInNs The timer value to be configured. + * + * @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_UNSUPPORTED Function is not supported. + * + * @see + * cpaInstanceSetResponseMode + * cpaInstanceGetRxInterruptMetaData + * + *****************************************************************************/ +CpaStatus cpaInstanceSetIntCoalescingTimer( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + const Cpa32U coalescingTimerInNs); + #ifdef __cplusplus } /* close the extern "C" { */ #endif diff --git a/quickassist/include/dc/cpa_dc_chain.h b/quickassist/include/dc/cpa_dc_chain.h index fd8e9c1a..20521fa4 100644 --- a/quickassist/include/dc/cpa_dc_chain.h +++ b/quickassist/include/dc/cpa_dc_chain.h @@ -317,7 +317,10 @@ typedef struct * were performed successfully and appendCrc was requested. */ CpaBoolean reserved1; - /**< Reserved for future use */ + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ CpaStatus chainStatus; /**< Status of chain command. In the event the request is invalid, * a value of CPA_STATUS_INVALID_PARAM or CPA_STATUS_UNSUPPORTED may diff --git a/quickassist/include/dc/cpa_dc_dp.h b/quickassist/include/dc/cpa_dc_dp.h index 4ac07dd0..b6aa6875 100644 --- a/quickassist/include/dc/cpa_dc_dp.h +++ b/quickassist/include/dc/cpa_dc_dp.h @@ -103,52 +103,51 @@ typedef struct * The physical memory to which this structure points should be * at least 8-byte aligned. * - * All reserved fields SHOULD NOT be written or read by the - * calling code. - * * @see * cpaDcDpEnqueueOp, cpaDcDpEnqueueOpBatch ****************************************************************************/ typedef struct { Cpa64U reserved0; - /**< Reserved for internal use. Source code should not read or write - * this field. + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. */ Cpa32U bufferLenToCompress; /**< The number of bytes from the source buffer to compress. This must be * less than, or more typically equal to, the total size of the source * buffer (or buffer list). */ - Cpa32U bufferLenForData; /**< The maximum number of bytes that should be written to the destination * buffer. This must be less than, or more typically equal to, the total * size of the destination buffer (or buffer list). */ - Cpa64U reserved1; - /**< Reserved for internal use. Source code should not read or write */ - + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ Cpa64U reserved2; - /**< Reserved for internal use. Source code should not read or write */ - + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ Cpa64U reserved3; - /**< Reserved for internal use. Source code should not read or write */ - + /**< Reserved. On passing this struct to the library this field should be + * set to 0. On reading this struct from the library this field should be + * ignored. + */ CpaDcRqResults results; /**< Results of the operation. Contents are valid upon completion. */ - CpaInstanceHandle dcInstance; /**< Instance to which the request is to be enqueued */ - CpaDcSessionHandle pSessionHandle; /**< DC Session associated with the stream of requests. * This field is only valid when using the session based API functions. * This field must be set to NULL if the application wishes to use * the No-Session (Ns) API. */ - CpaPhysicalAddr srcBuffer; /**< Physical address of the source buffer on which to operate. * This is either the location of the data, of length srcBufferLen; or, @@ -156,14 +155,12 @@ typedef struct * srcBuffer contains the location where a @ref CpaPhysBufferList is * stored. */ - Cpa32U srcBufferLen; /**< If the source buffer is a "flat buffer", then this field * specifies the size of the buffer, in bytes. If the source buffer * is a "buffer list" (of type @ref CpaPhysBufferList), then this field * should be set to the value @ref CPA_DP_BUFLIST. */ - CpaPhysicalAddr destBuffer; /**< Physical address of the destination buffer on which to operate. * This is either the location of the data, of length destBufferLen; or, @@ -171,20 +168,17 @@ typedef struct * destBuffer contains the location where a @ref CpaPhysBufferList is * stored. */ - Cpa32U destBufferLen; /**< If the destination buffer is a "flat buffer", then this field * specifies the size of the buffer, in bytes. If the destination buffer * is a "buffer list" (of type @ref CpaPhysBufferList), then this field * should be set to the value @ref CPA_DP_BUFLIST. */ - CpaDcSessionDir sessDirection; /**dc_capabilities; + + if (pDcCapabilities->dcGetMetaSizeForSrcBuffWithDict) + { + (pDcCapabilities->dcGetMetaSizeForSrcBuffWithDict)( + numDictBuffers, numSourceBuffers, pSizeInBytes); + } + else + { + return CPA_STATUS_UNSUPPORTED; + } + + return CPA_STATUS_SUCCESS; } -CpaStatus dcDeflateBoundGen2(void *pService, - CpaDcHuffType huffType, +CpaStatus dcDeflateBoundGen2(CpaDcHuffType huffType, Cpa32U inputSize, Cpa32U *outputSize) { @@ -163,16 +235,12 @@ CpaStatus dcDeflateBoundGen2(void *pService, return CPA_STATUS_SUCCESS; } -CpaStatus dcDeflateBoundGen4(void *pServiceType, - CpaDcHuffType huffType, +CpaStatus dcDeflateBoundGen4(CpaDcHuffType huffType, Cpa32U inputSize, Cpa32U *outputSize) { Cpa64U outputSizeLong; Cpa64U inputSizeLong = (Cpa64U)inputSize; - sal_compression_service_t *pService = NULL; - - pService = (sal_compression_service_t *)pServiceType; switch (huffType) { @@ -183,24 +251,13 @@ CpaStatus dcDeflateBoundGen4(void *pServiceType, DC_DEST_BUFF_EXTRA_DEFLATE_GEN4_STATIC; break; case CPA_DC_HT_FULL_DYNAMIC: + /* Formula for GEN4 dynamic deflate: + * Ceil ((9*sourceLen)/8) + + * ((((8/7) * sourceLen)/ 16KB) * (150+5)) + 512 + */ outputSizeLong = DC_DEST_BUFF_EXTRA_DEFLATE_GEN4_DYN; outputSizeLong += CPA_DC_CEIL_DIV(9 * inputSizeLong, 8); - if (pService->generic_service_info.isGen4_2) - { - /* Formula for GEN4_2 dynamic deflate: - * Ceil ((9*sourceLen)/8) + - * ((((8/7) * sourceLen)/ 4KB) * (150+5)) + 512 - */ - outputSizeLong += ((8 * inputSizeLong * 155) / 7) / (4 * 1024); - } - else - { - /* Formula for GEN4 dynamic deflate: - * Ceil ((9*sourceLen)/8) + - * ((((8/7) * sourceLen)/ 16KB) * (150+5)) + 512 - */ - outputSizeLong += ((8 * inputSizeLong * 155) / 7) / (16 * 1024); - } + outputSizeLong += ((8 * inputSizeLong * 155) / 7) / (16 * 1024); break; default: return CPA_STATUS_INVALID_PARAM; @@ -214,6 +271,74 @@ CpaStatus dcDeflateBoundGen4(void *pServiceType, return CPA_STATUS_SUCCESS; } +CpaStatus dcDeflateBoundGen4_2(CpaDcHuffType huffType, + Cpa32U inputSize, + Cpa32U *outputSize) +{ + Cpa64U outputSizeLong; + Cpa64U inputSizeLong = (Cpa64U)inputSize; + + switch (huffType) + { + case CPA_DC_HT_STATIC: + /* Formula for GEN4.2 (420xx) static deflate: + * ceil((9*sourceLen)/8) + 5 + 1024. */ + outputSizeLong = CPA_DC_CEIL_DIV(9 * inputSizeLong, 8) + + DC_DEST_BUFF_EXTRA_DEFLATE_GEN4_STATIC; + break; + case CPA_DC_HT_FULL_DYNAMIC: + /* Formula for GEN4.2 (420xx) dynamic deflate: + * Ceil ((9*sourceLen)/8) + + * ((((8/7) * sourceLen)/ 4KB) * (150+5)) + 512 + */ + outputSizeLong = DC_DEST_BUFF_EXTRA_DEFLATE_GEN4_DYN; + outputSizeLong += CPA_DC_CEIL_DIV(9 * inputSizeLong, 8); + outputSizeLong += ((8 * inputSizeLong * 155) / 7) / (4 * 1024); + break; + default: + return CPA_STATUS_INVALID_PARAM; + } + + /* Avoid output size overflow */ + if (outputSizeLong & UINT_OVERFLOW) + return CPA_STATUS_INVALID_PARAM; + + *outputSize = (Cpa32U)outputSizeLong; + return CPA_STATUS_SUCCESS; +} + +CpaStatus dcDeflateBoundGen6(CpaDcHuffType huffType, + Cpa32U inputSize, + Cpa32U *outputSize) +{ + Cpa64U outputSizeLong; + Cpa64U inputSizeLong = (Cpa64U)inputSize; + + switch (huffType) + { + case CPA_DC_HT_FULL_DYNAMIC: + /* Formula for GEN6 dynamic deflate: + * srcSize + ((((srcSize)>>12) + 1) * 5) + */ + outputSizeLong = inputSizeLong; + outputSizeLong += (((inputSizeLong >> 12) + 1) * 5); + break; + default: + LAC_INVALID_PARAM_LOG("Invalid huffType value"); + return CPA_STATUS_INVALID_PARAM; + } + + /* Avoid output size overflow */ + if (outputSizeLong & UINT_OVERFLOW) + { + LAC_INVALID_PARAM_LOG("Invalid output size"); + return CPA_STATUS_INVALID_PARAM; + } + + *outputSize = (Cpa32U)outputSizeLong; + return CPA_STATUS_SUCCESS; +} + CpaStatus cpaDcDeflateCompressBound(const CpaInstanceHandle dcInstance, CpaDcHuffType huffType, Cpa32U inputSize, @@ -270,8 +395,7 @@ CpaStatus cpaDcDeflateCompressBound(const CpaInstanceHandle dcInstance, } #endif - return (pDcCapabilities->dcDeflateBound)( - (void *)pService, huffType, inputSize, outputSize); + return (pDcCapabilities->dcDeflateBound)(huffType, inputSize, outputSize); } CpaStatus dcLZ4BoundGen4(Cpa32U inputSize, Cpa32U *outputSize) @@ -292,6 +416,24 @@ CpaStatus dcLZ4BoundGen4(Cpa32U inputSize, Cpa32U *outputSize) return CPA_STATUS_SUCCESS; } +CpaStatus dcLZ4BoundGen6(Cpa32U inputSize, Cpa32U *outputSize) +{ + Cpa64U outputSizeLong; + Cpa64U inputSizeLong = (Cpa64U)inputSize; + + /* Formula for GEN6 LZ4: + * sourceLen + ((((sourceLen)>>16) + 1) * 4) */ + outputSizeLong = inputSizeLong; + outputSizeLong += (((inputSizeLong >> 16) + 1) * 4); + + /* Avoid output size overflow */ + if (outputSizeLong & UINT_OVERFLOW) + return CPA_STATUS_INVALID_PARAM; + + *outputSize = (Cpa32U)outputSizeLong; + return CPA_STATUS_SUCCESS; +} + CpaStatus dcLZ4SBoundGen4(Cpa32U inputSize, Cpa32U *outputSize) { Cpa64U outputSizeLong; @@ -310,6 +452,43 @@ CpaStatus dcLZ4SBoundGen4(Cpa32U inputSize, Cpa32U *outputSize) return CPA_STATUS_SUCCESS; } +CpaStatus dcLZ4SBoundGen6(Cpa32U inputSize, Cpa32U *outputSize) +{ + Cpa64U outputSizeLong; + Cpa64U inputSizeLong = (Cpa64U)inputSize; + + /* Formula for GEN6 LZ4S: + * sourceLen + Ceil(sourceLen/18) * 1 + 1 + * Ignoring "* 1" from the formula */ + outputSizeLong = inputSizeLong + DC_DEST_BUFF_EXTRA_LZ4S_GEN6; + outputSizeLong += CPA_DC_CEIL_DIV(inputSizeLong, 18); + + /* Avoid output size overflow */ + if (outputSizeLong & UINT_OVERFLOW) + return CPA_STATUS_INVALID_PARAM; + + *outputSize = (Cpa32U)outputSizeLong; + return CPA_STATUS_SUCCESS; +} + +CpaStatus dcZstdBoundGen6(Cpa32U inputSize, Cpa32U *outputSize) +{ + Cpa64U outputSizeLong; + Cpa64U inputSizeLong = (Cpa64U)inputSize; + + /* Formula for GEN6 Zstd: + * 14 + sourceLen + ((sourceLen >> 16) + 1) * 3 + 4 */ + outputSizeLong = inputSizeLong + DC_DEST_BUFF_EXTRA_ZSTD_GEN6; + outputSizeLong += ((inputSizeLong >> 16) + 1) * 3; + + /* Avoid output size overflow */ + if (outputSizeLong & UINT_OVERFLOW) + return CPA_STATUS_INVALID_PARAM; + + *outputSize = (Cpa32U)outputSizeLong; + return CPA_STATUS_SUCCESS; +} + CpaStatus cpaDcLZ4CompressBound(const CpaInstanceHandle dcInstance, Cpa32U inputSize, Cpa32U *outputSize) diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_capabilities.c b/quickassist/lookaside/access_layer/src/common/compression/dc_capabilities.c index ac855512..ced32cf9 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_capabilities.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_capabilities.c @@ -117,6 +117,9 @@ dcGetAlgoWindowSizeForCapabilityStatus(dc_capabilities_t *pDcCapabilities, case CPA_DC_CAP_BOOL_WINDOW_SIZE_32K: validBitMask = DC_32K_WINDOW_MASK; break; + case CPA_DC_CAP_BOOL_WINDOW_SIZE_64K: + validBitMask = DC_64K_WINDOW_MASK; + break; default: LAC_UNSUPPORTED_PARAM_LOG("Window size is not supported\n"); return CPA_STATUS_UNSUPPORTED; @@ -433,6 +436,64 @@ dcGetCrcOverBlockCapabilityStatus(dc_extd_ftrs_t *pExtendedFtrs, return CPA_STATUS_SUCCESS; } +STATIC INLINE CpaStatus +dcGetUncompDictSupportCapabilityStatus(dc_capabilities_t *pDcCapabilities, + Cpa32U algo, + Cpa32U dirMask, + CpaBoolean *pCapStatus) +{ +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(pDcCapabilities); + LAC_CHECK_NULL_PARAM(pCapStatus); +#endif + + *pCapStatus = CPA_FALSE; + + switch (algo) + { + case CPA_DC_DEFLATE: + if ((pDcCapabilities->deflate.supported) && + (pDcCapabilities->deflate.dictCompSupported) && + ((pDcCapabilities->deflate.dirMask & dirMask) == dirMask) && + (pDcCapabilities->deflate.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) + { + *pCapStatus = CPA_TRUE; + } + break; + case CPA_DC_LZ4: + if ((pDcCapabilities->lz4.supported) && + (pDcCapabilities->lz4.dictCompSupported) && + ((pDcCapabilities->lz4.dirMask & dirMask) == dirMask) && + (pDcCapabilities->lz4.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) + { + *pCapStatus = CPA_TRUE; + } + break; + case CPA_DC_LZ4S: + if ((pDcCapabilities->lz4s.supported) && + (pDcCapabilities->lz4s.dictCompSupported) && + ((pDcCapabilities->lz4s.dirMask & dirMask) == dirMask) && + (pDcCapabilities->lz4s.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) + { + *pCapStatus = CPA_TRUE; + } + break; + case CPA_DC_ZSTD: + if ((pDcCapabilities->zstd.supported) && + (pDcCapabilities->zstd.dictCompSupported) && + ((pDcCapabilities->zstd.dirMask & dirMask) == dirMask) && + (pDcCapabilities->zstd.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) + { + *pCapStatus = CPA_TRUE; + } + break; + default: + LAC_UNSUPPORTED_PARAM_LOG("Algorithm is not supported\n"); + return CPA_STATUS_UNSUPPORTED; + } + return CPA_STATUS_SUCCESS; +} + CpaStatus cpaDcQueryCapabilityByType(CpaInstanceHandle dcInstance, CpaDcCapabilityReq capabilityReq, CpaDcCapabilityResp *pCapabilityResp) @@ -770,6 +831,12 @@ CpaStatus cpaDcQueryCapabilityByType(CpaInstanceHandle dcInstance, capabilityReq.algo, &pCapabilityResp->boolStatus); break; + case CPA_DC_CAP_BOOL_DICT_ID: + result = dcGetDictIdSupportCapabilityStatus( + pDcCapabilities, + capabilityReq.algo, + &pCapabilityResp->boolStatus); + break; case CPA_DC_CAP_BOOL_E2E_CRC_OVER_COMP_BLOCK: result = dcGetCrcOverBlockCapabilityStatus(pExtendedFtrs, @@ -783,64 +850,6 @@ CpaStatus cpaDcQueryCapabilityByType(CpaInstanceHandle dcInstance, return result; } -inline CpaStatus dcGetUncompDictSupportCapabilityStatus( - dc_capabilities_t *pDcCapabilities, - Cpa32U algo, - Cpa32U dirMask, - CpaBoolean *pCapStatus) -{ -#ifdef ICP_PARAM_CHECK - LAC_CHECK_NULL_PARAM(pDcCapabilities); - LAC_CHECK_NULL_PARAM(pCapStatus); -#endif - - *pCapStatus = CPA_FALSE; - - switch (algo) - { - case CPA_DC_DEFLATE: - if ((pDcCapabilities->deflate.supported) && - (pDcCapabilities->deflate.dictCompSupported) && - ((pDcCapabilities->deflate.dirMask & dirMask) == dirMask) && - (pDcCapabilities->deflate.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) - { - *pCapStatus = CPA_TRUE; - } - break; - case CPA_DC_LZ4: - if ((pDcCapabilities->lz4.supported) && - (pDcCapabilities->lz4.dictCompSupported) && - ((pDcCapabilities->lz4.dirMask & dirMask) == dirMask) && - (pDcCapabilities->lz4.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) - { - *pCapStatus = CPA_TRUE; - } - break; - case CPA_DC_LZ4S: - if ((pDcCapabilities->lz4s.supported) && - (pDcCapabilities->lz4s.dictCompSupported) && - ((pDcCapabilities->lz4s.dirMask & dirMask) == dirMask) && - (pDcCapabilities->lz4s.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) - { - *pCapStatus = CPA_TRUE; - } - break; - case CPA_DC_ZSTD: - if ((pDcCapabilities->zstd.supported) && - (pDcCapabilities->zstd.dictCompSupported) && - ((pDcCapabilities->zstd.dirMask & dirMask) == dirMask) && - (pDcCapabilities->zstd.dictCap & DC_CAPS_UNCOMPRESSED_DICT)) - { - *pCapStatus = CPA_TRUE; - } - break; - default: - LAC_UNSUPPORTED_PARAM_LOG("Algorithm is not supported\n"); - return CPA_STATUS_UNSUPPORTED; - } - return CPA_STATUS_SUCCESS; -} - inline CpaStatus dcGetZeroLengthReqCapabilityStatus( dc_capabilities_t *pDcCapabilities, Cpa32U algo, @@ -1044,3 +1053,36 @@ inline CpaStatus dcGetAeadDecompChainingCapabilityStatus( return CPA_STATUS_SUCCESS; } +inline CpaStatus dcGetDictIdSupportCapabilityStatus( + dc_capabilities_t *pDcCapabilities, + Cpa32U algo, + CpaBoolean *pCapStatus) +{ +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(pDcCapabilities); + LAC_CHECK_NULL_PARAM(pCapStatus); +#endif + + *pCapStatus = CPA_FALSE; + + switch (algo) + { + case CPA_DC_DEFLATE: + case CPA_DC_LZ4: + case CPA_DC_LZ4S: + break; + + case CPA_DC_ZSTD: + if (pDcCapabilities->zstd.dictId) + { + *pCapStatus = CPA_TRUE; + } + break; + + default: + LAC_UNSUPPORTED_PARAM_LOG("Algorithm is not supported\n"); + return CPA_STATUS_UNSUPPORTED; + } + return CPA_STATUS_SUCCESS; +} + diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c b/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c index 6a6e5f83..43fccc65 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c @@ -55,6 +55,24 @@ #include "dc_session.h" #include "dc_crc64.h" +#ifdef QAT_LEGACY_ALGORITHMS +#define CHAIN_HASH_ALGO_CHECK(algo) \ + (algo == CPA_CY_SYM_HASH_SHA1 || algo == CPA_CY_SYM_HASH_SHA224 || \ + algo == CPA_CY_SYM_HASH_SHA256 || algo == CPA_CY_SYM_HASH_SHA384 || \ + algo == CPA_CY_SYM_HASH_SHA512 || algo == CPA_CY_SYM_HASH_SHA3_224 || \ + algo == CPA_CY_SYM_HASH_SHA3_256 || algo == CPA_CY_SYM_HASH_SHA3_384 || \ + algo == CPA_CY_SYM_HASH_SHA3_512) +#else +#define CHAIN_HASH_ALGO_CHECK(algo) \ + (algo == CPA_CY_SYM_HASH_SHA256 || algo == CPA_CY_SYM_HASH_SHA384 || \ + algo == CPA_CY_SYM_HASH_SHA512 || algo == CPA_CY_SYM_HASH_SHA3_256 || \ + algo == CPA_CY_SYM_HASH_SHA3_384 || algo == CPA_CY_SYM_HASH_SHA3_512) +#endif + +#define GENERIC_CHAINING_CIPHER_ALGO(ALGO) \ + (ALGO != CPA_CY_SYM_CIPHER_AES_CTR && ALGO != CPA_CY_SYM_CIPHER_AES_GCM && \ + ALGO != CPA_CY_SYM_CIPHER_AES_XTS) + #define DC_CHAIN_COMPUTE_KEY(huffType, dcDir, sessType) \ ((huffType << 8) | (dcDir << 4) | sessType) #define CY_CHAIN_COMPUTE_KEY(cyOpType, cyDir, sessType) \ @@ -93,11 +111,76 @@ static const dc_chain_cmd_tbl_t dc_chain_cmd_table[] = { 0x0, ICP_QAT_FW_NO_CHAINING, ICP_QAT_FW_CHAINING_20_CMD_DECRYPT_DECOMPRESS }, + /* link0: additional=2(dynamic)|dir=0(compression)|type=0(comp) + * link1: additional=1(cipher)|dir=1(encrypt)|type=1(crypto) + */ + { 0x200, + 0x111, + 0x0, + ICP_QAT_FW_NO_CHAINING, + ICP_QAT_FW_CHAINING_20_CMD_COMPRESS_ENCRYPT }, + /* link0: additional=1(cipher)|dir=2()|type=1(crypto) + * link1: additional=0(rsvd)|dir=1(decomp)|type=0(comp) + */ + { 0x121, + 0x10, + 0x0, + ICP_QAT_FW_NO_CHAINING, + ICP_QAT_FW_CHAINING_20_CMD_DECRYPT_DECOMPRESS }, }; #ifdef ICP_PARAM_CHECK #define NUM_OF_SESSION_SUPPORT 2 +/** + ***************************************************************************** + * @ingroup Dc_Chaining + * Check that chaining CY setup data is valid + * + * @description + * Check that chaining CY setup data in the CpaCySymSessionSetupData is + * valid + * + * @param[in] pDcSetupData Pointer to a CpaCySymSessionSetupData + * structure. + * @param[in] operation Chaining operation type + * + * @retval CPA_STATUS_SUCCESS Function executed successfully + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in + * + *****************************************************************************/ +STATIC CpaStatus +dcChainSession_CheckCySetupData(const CpaCySymSessionSetupData *pCySetupData, + CpaDcChainOperations operation) +{ + CpaCySymCipherSetupData const *pCipherSetupData = NULL; + + pCipherSetupData = &(pCySetupData->cipherSetupData); + LAC_CHECK_NULL_PARAM(pCipherSetupData); + + LAC_CHECK_STATEMENT_LOG( + GENERIC_CHAINING_CIPHER_ALGO(pCipherSetupData->cipherAlgorithm), + "Invalid CY cipherAlgorithm=0x%x for " + "COMPRESS_THEN_AEAD chaining", + pCipherSetupData->cipherAlgorithm); + + LAC_CHECK_STATEMENT_LOG((operation == CPA_DC_CHAIN_COMPRESS_THEN_AEAD) && + (pCipherSetupData->cipherDirection != + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT), + "Invalid CY cipherDirection=0x%x for " + "COMPRESS_THEN_AEAD chaining", + pCipherSetupData->cipherDirection); + + LAC_CHECK_STATEMENT_LOG((operation == CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS) && + (pCipherSetupData->cipherDirection != + CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT), + "Invalid CY cipherDirection=0x%x for " + "AEAD_THEN_DECOMPRESS chaining", + pCipherSetupData->cipherDirection); + + return CPA_STATUS_SUCCESS; +} + /** ***************************************************************************** * @ingroup Dc_Chaining @@ -123,6 +206,23 @@ dcChainSession_CheckHashSetupData(const CpaCySymHashSetupData *pHashSetupData, { LAC_CHECK_NULL_PARAM(pHashSetupData); + if (DC_CAPS_GEN6_HW == hw_gen) + { + if (!CHAIN_HASH_ALGO_CHECK(pHashSetupData->hashAlgorithm)) + { + LAC_INVALID_PARAM_LOG2( + "Invalid Hash algorithm=0x%x for %d chaining operation", + pHashSetupData->hashAlgorithm, + operation); + return CPA_STATUS_INVALID_PARAM; + } + LAC_CHECK_STATEMENT_LOG( + ((CPA_CY_SYM_HASH_MODE_PLAIN != pHashSetupData->hashMode) && + (CPA_CY_SYM_HASH_MODE_AUTH != pHashSetupData->hashMode)), + "Invalid CY hashMode=0x%x", + pHashSetupData->hashMode); + } + else { /* Support SHA1, SHA224 and SHA256 */ LAC_CHECK_STATEMENT_LOG( @@ -255,7 +355,132 @@ dcChainSession_CheckSessionData(CpaInstanceHandle dcInstance, LAC_CHECK_STATUS(status); break; case CPA_DC_CHAIN_COMPRESS_THEN_AEAD: + pDcSetupData = pSessionData[0].pDcSetupData; + pCySetupData = pSessionData[1].pCySetupData; + + LAC_CHECK_NULL_PARAM(pDcSetupData); + LAC_CHECK_NULL_PARAM(pCySetupData); + + /* Check for valid/supported DC Chain parameters */ + LAC_CHECK_STATEMENT_LOG( + (pSessionData[0].sessType != CPA_DC_CHAIN_COMPRESS_DECOMPRESS), + "Invalid Chain dcSessType=0x%x for COMPRESS_THEN_AEAD chaining", + pSessionData[0].sessType); + + LAC_CHECK_STATEMENT_LOG( + (pSessionData[1].sessType != CPA_DC_CHAIN_SYMMETRIC_CRYPTO), + "Invalid Chain cySessType=0x%x for COMPRESS_THEN_AEAD chaining", + pSessionData[1].sessType); + + status = dcGetCompAeadChainingCapabilityStatus( + pDcCapabilities, pDcSetupData->compType, &capSupport); + LAC_CHECK_STATUS(status); + if (capSupport != CPA_TRUE) + { + LAC_INVALID_PARAM_LOG1("Unsupported DC compType=0x%x for " + "COMPRESS_THEN_AEAD chaining", + pDcSetupData->compType); + return CPA_STATUS_UNSUPPORTED; + } + + /* Check for supported and valid DC parameters */ + LAC_CHECK_STATEMENT_LOG( + (pDcSetupData->sessDirection != CPA_DC_DIR_COMPRESS), + "Invalid DC sessDirection=0x%x for COMPRESS_THEN_AEAD chaining", + pDcSetupData->sessDirection); + + LAC_CHECK_STATEMENT_LOG( + (pDcSetupData->huffType != CPA_DC_HT_FULL_DYNAMIC), + "Invalid DC huffType=0x%x for COMPRESS_THEN_AEAD chaining", + pDcSetupData->huffType); + + LAC_CHECK_STATEMENT_LOG( + (pCySetupData->symOperation == + CPA_CY_SYM_OP_ALGORITHM_CHAINING) && + (pCySetupData->algChainOrder != + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH), + "Invalid CY algChainOrder=0x%x for COMPRESS_THEN_AEAD " + "chaining", + pCySetupData->algChainOrder); + + if (pDcSetupData->sessState != CPA_DC_STATELESS) + { + LAC_INVALID_PARAM_LOG2( + "Invalid DC sessState=0x%x for %d chaining operation", + pDcSetupData->sessState, + operation); + return CPA_STATUS_INVALID_PARAM; + } + + LAC_CHECK_STATEMENT_LOG( + (pCySetupData->digestIsAppended == CPA_TRUE), + "Invalid CY digestIsAppended=0x%x for COMPRESS_THEN_AEAD " + "chaining", + pCySetupData->digestIsAppended); + + status = dcChainSession_CheckCySetupData(pCySetupData, operation); + LAC_CHECK_STATUS(status); + break; + case CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS: + pCySetupData = pSessionData[0].pCySetupData; + pDcSetupData = pSessionData[1].pDcSetupData; + + LAC_CHECK_NULL_PARAM(pCySetupData); + LAC_CHECK_NULL_PARAM(pDcSetupData); + + /* Check for supported and valid DC Chain parameters */ + LAC_CHECK_STATEMENT_LOG( + (pSessionData[0].sessType != CPA_DC_CHAIN_SYMMETRIC_CRYPTO), + "Invalid Chain cySessType=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pSessionData[0].sessType); + + LAC_CHECK_STATEMENT_LOG( + (pSessionData[1].sessType != CPA_DC_CHAIN_COMPRESS_DECOMPRESS), + "Invalid Chain dcSessType=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pSessionData[1].sessType); + + status = dcGetAeadDecompChainingCapabilityStatus( + pDcCapabilities, pDcSetupData->compType, &capSupport); + LAC_CHECK_STATUS(status); + if (capSupport != CPA_TRUE) + { + LAC_INVALID_PARAM_LOG1("Unsupported DC compType=0x%x for " + "AEAD_THEN_DECOMPRESS chaining", + pDcSetupData->compType); + return CPA_STATUS_UNSUPPORTED; + } + + LAC_CHECK_STATEMENT_LOG( + (pCySetupData->symOperation == + CPA_CY_SYM_OP_ALGORITHM_CHAINING) && + (pCySetupData->algChainOrder != + CPA_CY_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER), + "Invalid CY algChainOrder=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pCySetupData->algChainOrder); + + /* Check for supported and valid DC parameters */ + LAC_CHECK_STATEMENT_LOG( + (pDcSetupData->sessDirection != CPA_DC_DIR_DECOMPRESS), + "Invalid DC sessDirection=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pDcSetupData->sessDirection); + + status = dcChainSession_CheckCySetupData(pCySetupData, operation); + LAC_CHECK_STATUS(status); + + if (pDcSetupData->sessState != CPA_DC_STATELESS) + { + LAC_INVALID_PARAM_LOG2( + "Invalid DC sessState=0x%x for %d chaining operation", + pDcSetupData->sessState, + operation); + return CPA_STATUS_INVALID_PARAM; + } + break; case CPA_DC_CHAIN_COMPRESS_THEN_HASH: case CPA_DC_CHAIN_COMPRESS_THEN_ENCRYPT: case CPA_DC_CHAIN_COMPRESS_THEN_HASH_ENCRYPT: @@ -331,6 +556,61 @@ dcChainSession_CheckCySessDesc(const lac_session_desc_t *pCySessDesc, pCySessDesc->isAuth); break; + case CPA_DC_CHAIN_COMPRESS_THEN_AEAD: + LAC_CHECK_STATEMENT_LOG( + ((CPA_CY_SYM_OP_ALGORITHM_CHAINING != + pCySessDesc->symOperation) && + (CPA_CY_SYM_OP_CIPHER != pCySessDesc->symOperation)), + "Invalid CY symOperation=0x%x for COMPRESS_THEN_AEAD chaining", + pCySessDesc->symOperation); + + LAC_CHECK_STATEMENT_LOG( + GENERIC_CHAINING_CIPHER_ALGO(pCySessDesc->cipherAlgorithm), + "Invalid CY cipherAlgorithm=0x%x for COMPRESS_THEN_AEAD " + "chaining", + pCySessDesc->cipherAlgorithm); + + LAC_CHECK_STATEMENT_LOG((CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT != + pCySessDesc->cipherDirection), + "Invalid CY cipherDirection=0x%x for " + "COMPRESS_THEN_AEAD chaining", + pCySessDesc->cipherDirection); + + LAC_CHECK_STATEMENT_LOG( + (CPA_CY_SYM_HASH_AES_GCM == pCySessDesc->hashAlgorithm) && + (CPA_CY_SYM_CIPHER_AES_GCM != pCySessDesc->cipherAlgorithm), + "Invalid CY cipherAlgorithm=0x%x for COMPRESS_THEN_AEAD" + "chaining", + pCySessDesc->cipherAlgorithm); + break; + case CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS: + LAC_CHECK_STATEMENT_LOG( + ((CPA_CY_SYM_OP_ALGORITHM_CHAINING != + pCySessDesc->symOperation) && + (CPA_CY_SYM_OP_CIPHER != pCySessDesc->symOperation)), + "Invalid CY symOperation=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pCySessDesc->symOperation); + + LAC_CHECK_STATEMENT_LOG((CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT != + pCySessDesc->cipherDirection), + "Invalid CY cipherDirection=0x%x for " + "AEAD_THEN_DECOMPRESS chaining", + pCySessDesc->cipherDirection); + + LAC_CHECK_STATEMENT_LOG( + GENERIC_CHAINING_CIPHER_ALGO(pCySessDesc->cipherAlgorithm), + "Invalid CY cipherAlgorithm=0x%x for AEAD_THEN_DECOMPRESS " + "chaining", + pCySessDesc->cipherAlgorithm); + + LAC_CHECK_STATEMENT_LOG( + (CPA_CY_SYM_HASH_AES_GCM == pCySessDesc->hashAlgorithm) && + (CPA_CY_SYM_CIPHER_AES_GCM != pCySessDesc->cipherAlgorithm), + "Invalid CY cipherAlgorithm=0x%x for AEAD_THEN_DECOMPRESS" + "chaining", + pCySessDesc->cipherAlgorithm); + break; default: LAC_INVALID_PARAM_LOG1("Unsupported DC chaining operation=0x%x", operation); @@ -447,6 +727,33 @@ dcChainSession_CheckChainSessDesc(const dc_chain_session_head_t *pChainSessDesc, "Invalid chaining dcSessType=0x%x for HASH_THEN_COMPRESS", DC_CHAIN_TYPE_GET(pTemp)); break; + case CPA_DC_CHAIN_COMPRESS_THEN_AEAD: + LAC_CHECK_STATEMENT_LOG( + (DC_CHAIN_TYPE_GET(pTemp) != CPA_DC_CHAIN_COMPRESS_DECOMPRESS), + "Chain Entry[0] type = 0x%x", + DC_CHAIN_TYPE_GET(pTemp)); + + pTemp += (DC_COMP_SESSION_SIZE + sizeof(CpaDcChainSessionType)); + + LAC_CHECK_STATEMENT_LOG( + (DC_CHAIN_TYPE_GET(pTemp) != CPA_DC_CHAIN_SYMMETRIC_CRYPTO), + "COMPRESS_THEN_AEAD Chain Entry[1] type = 0x%x", + DC_CHAIN_TYPE_GET(pTemp)); + break; + + case CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS: + LAC_CHECK_STATEMENT_LOG( + (DC_CHAIN_TYPE_GET(pTemp) != CPA_DC_CHAIN_SYMMETRIC_CRYPTO), + "Chain Entry[0] type = 0x%x", + DC_CHAIN_TYPE_GET(pTemp)); + + pTemp += (LAC_SYM_SESSION_SIZE + sizeof(CpaDcChainSessionType)); + + LAC_CHECK_STATEMENT_LOG( + (DC_CHAIN_TYPE_GET(pTemp) != CPA_DC_CHAIN_COMPRESS_DECOMPRESS), + "AEAD_THEN_DECOMPRESS Chain Entry[1] type = 0x%x", + DC_CHAIN_TYPE_GET(pTemp)); + break; default: LAC_INVALID_PARAM_LOG1("Invalid chaining operation %x", operation); return CPA_STATUS_INVALID_PARAM; @@ -1007,6 +1314,8 @@ STATIC CpaStatus dcChainPrepare_CompRequest(CpaInstanceHandle dcInstance, pDcOpData->flushFlag == CPA_DC_FLUSH_NONE, "%s", "CPA_DC_FLUSH_NONE flag not supported for compression.\n"); + if (pDcOpData->integrityCrcCheck) + LAC_CHECK_NULL_PARAM(pDcOpData->pCrcData); if (CPA_STATUS_SUCCESS != dcChainSession_CheckDcSessDesc(pDcSessDesc, operation, pDcCapabilities)) @@ -1683,7 +1992,26 @@ CpaStatus cpaDcChainPerformOp2(CpaInstanceHandle dcInstance, CpaDcChainRqVResults *pResults, void *callbackTag) { - return CPA_STATUS_UNSUPPORTED; + dc_chain_opdata_ext_t chainOpDataExt = { 0 }; + dc_chain_results_ext_t chainResultsExt = { 0 }; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(pInterBuff); +#endif + chainOpDataExt.opDataType = DC_CHAIN_OPDATA_TYPE1; + chainOpDataExt.pOpData = &opData; + chainResultsExt.resultsType = DC_CHAIN_RESULTS_TYPE1; + chainResultsExt.pResults = pResults; + return dcChainPerformOp(dcInstance, + pSessionHandle, + pSrcBuff, + pDestBuff, + pInterBuff, + opData.operation, + opData.numOpDatas, + &chainOpDataExt, + &chainResultsExt, + callbackTag); } /** @@ -2078,6 +2406,78 @@ void dcChainProcessResults(void *pRespMsg) } #endif +STATIC CpaStatus +dcInitChainSessionCrcControl(CpaInstanceHandle dcInstance, + CpaDcSessionHandle pSessionHandle, + CpaCrcControlData *pCrcControlData) +{ + dc_session_desc_t *pSessionDesc = NULL; + dc_capabilities_t *pDcCapabilities = NULL; + sal_compression_service_t *pService = NULL; + dc_chain_session_head_t *pSessHead = NULL; + CpaBoolean bPcrc64Supported = CPA_FALSE; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(dcInstance); + LAC_CHECK_NULL_PARAM(pSessionHandle); + LAC_CHECK_NULL_PARAM(pCrcControlData); + + /* Check that the parameters defined in the pCrcControlData are valid for + * the device */ + if (CPA_STATUS_SUCCESS != dcCheckSessionCrcControlData(pCrcControlData)) + { + return CPA_STATUS_INVALID_PARAM; + } +#endif + + pSessHead = (dc_chain_session_head_t *)pSessionHandle; + pSessionDesc = pSessHead->pDcSessionDesc; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(pSessionDesc); +#endif + pService = (sal_compression_service_t *)dcInstance; + pDcCapabilities = &pService->dc_capabilities; + status = dcGetPcrc64CapabilityStatus( + pDcCapabilities, pSessionDesc->compType, &bPcrc64Supported); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to get Programmable CRC64 capability"); + return status; + } + + if (!bPcrc64Supported) + { + LAC_LOG_ERROR("Programmable CRC64 is unsupported"); + return CPA_STATUS_UNSUPPORTED; + } + + /* Generate the CRC64 lookup table for the provided polynomial */ + status = dcGenerateLookupTable(pCrcControlData->polynomial, + &pSessionDesc->crcConfig.pCrcLookupTable); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to generate programmable CRC64 lookup table"); + return status; + } + + /* Set CRC parameters provided */ + pSessionDesc->crcConfig.crcParam.crc64Poly = pCrcControlData->polynomial; + pSessionDesc->crcConfig.crcParam.iCrc64Cpr = pCrcControlData->initialValue; + pSessionDesc->crcConfig.crcParam.oCrc64Cpr = pCrcControlData->initialValue; + pSessionDesc->crcConfig.crcParam.reflectIn = + (Cpa32U)pCrcControlData->reflectIn; + pSessionDesc->crcConfig.crcParam.reflectOut = + (Cpa32U)pCrcControlData->reflectOut; + pSessionDesc->crcConfig.crcParam.oCrc64Xlt = pCrcControlData->initialValue; + pSessionDesc->crcConfig.crcParam.xor64Out = pCrcControlData->xorOut; + + pSessionDesc->crcConfig.useProgCrcSetup = CPA_TRUE; + + return CPA_STATUS_SUCCESS; +} + CpaStatus cpaDcChainSetCrcControlData(CpaInstanceHandle dcInstance, CpaDcSessionHandle pSessionHandle, CpaCrcControlData *pCrcControlData) @@ -2088,5 +2488,6 @@ CpaStatus cpaDcChainSetCrcControlData(CpaInstanceHandle dcInstance, (LAC_ARCH_UINT)pSessionHandle, (LAC_ARCH_UINT)pCrcControlData); #endif - return CPA_STATUS_UNSUPPORTED; + return dcInitChainSessionCrcControl( + dcInstance, pSessionHandle, pCrcControlData); } diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_crc64.c b/quickassist/lookaside/access_layer/src/common/compression/dc_crc64.c index 4f4599c3..e5ea6d0c 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_crc64.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_crc64.c @@ -237,6 +237,8 @@ CpaStatus dcGenerateLookupTable(Cpa64U crc64Polynomial, * calculating the checksum. * @param[in] pCrcLookupTable Pointer to the CRC lookup table used for * calculating the checksum. + * @param[in] initialValue Seed value used to start CRC calculation + * for the given flat buffer. * @param[in] pData Pointer to data byte array to calculate CRC * on. * @param[in] computeLength Total number of bytes to calculate CRC on. @@ -248,6 +250,7 @@ CpaStatus dcGenerateLookupTable(Cpa64U crc64Polynomial, */ STATIC CpaStatus dcBufferCalculateCrc64(const CpaCrcControlData *pCrcConfig, const Cpa64U *pCrcLookupTable, + Cpa64U initialValue, const Cpa8U *pData, Cpa64U computeLength, Cpa64U *pCurrentCrc) @@ -263,7 +266,7 @@ STATIC CpaStatus dcBufferCalculateCrc64(const CpaCrcControlData *pCrcConfig, LAC_CHECK_NULL_PARAM(pCrcLookupTable); #endif - *pCurrentCrc = pCrcConfig->initialValue; + *pCurrentCrc = initialValue; for (i = 0; i < computeLength; i++) { nextByte = pData[i]; @@ -309,7 +312,7 @@ STATIC CpaStatus dcBufferCalculateCrc64(const CpaCrcControlData *pCrcConfig, * @retval CPA_STATUS_SUCCESS Function executed successfully * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in */ -CpaStatus dcCalculateProgCrc64(CpaCrcControlData *pCrcConfig, +CpaStatus dcCalculateProgCrc64(const CpaCrcControlData *pCrcConfig, Cpa64U *pCrcLookupTable, const CpaBufferList *pBufferList, Cpa32U consumedBytes, @@ -317,10 +320,13 @@ CpaStatus dcCalculateProgCrc64(CpaCrcControlData *pCrcConfig, { Cpa64U i = 0; Cpa64U computeLength = 0; + Cpa64U runningSeed = 0; Cpa32U flatBufferLength = 0; CpaFlatBuffer *pBuffer = &pBufferList->pBuffers[0]; CpaStatus status = CPA_STATUS_SUCCESS; + runningSeed = pCrcConfig->initialValue; + for (i = 0; i < pBufferList->numBuffers; i++) { flatBufferLength = pBuffer->dataLenInBytes; @@ -338,13 +344,17 @@ CpaStatus dcCalculateProgCrc64(CpaCrcControlData *pCrcConfig, consumedBytes = 0; } - status = dcBufferCalculateCrc64( - pCrcConfig, pCrcLookupTable, pBuffer->pData, computeLength, pSwCrc); + status = dcBufferCalculateCrc64(pCrcConfig, + pCrcLookupTable, + runningSeed, + pBuffer->pData, + computeLength, + pSwCrc); if (CPA_STATUS_SUCCESS != status) { return status; } - pCrcConfig->initialValue = *pSwCrc; + runningSeed = *pSwCrc; pBuffer++; } diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c b/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c index 970b4483..da1e6028 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c @@ -61,6 +61,22 @@ #include "sal_misc_error_stats.h" #define DC_COMP_MAX_BUFF_SIZE (1024 * 64) +/* Reject LZ4 requests that have accumulateXXHash disabled + * but do not use CPA_DC_FLUSH_FINAL */ +#define DC_CHECK_LZ4_XXHASH_FLUSH(pSessionDesc, flushFlag) \ + do \ + { \ + if (CPA_DC_LZ4 == (pSessionDesc)->compType && \ + CPA_FALSE == (pSessionDesc)->accumulateXXHash && \ + CPA_DC_FLUSH_FINAL != (flushFlag)) \ + { \ + LAC_INVALID_PARAM_LOG( \ + "LZ4 requests with accumulateXXHash disabled must use" \ + " CPA_DC_FLUSH_FINAL"); \ + return CPA_STATUS_INVALID_PARAM; \ + } \ + } while (0) + STATIC OsalAtomic dcErrorCount[MAX_DC_ERROR_TYPE]; void dcErrorLog(CpaDcReqStatus dcError) @@ -484,6 +500,24 @@ void dcHandleIntegrityChecksums(dc_compression_cookie_t *pCookie, } } +INLINE void dcGetDictionaryParams(const CpaDcDictionaryData *pDictionaryData, + const dc_capabilities_t *pDcCapabilities, + const Cpa32U dictLenInBytes, + Cpa32U *pDictPrefixLength, + Cpa32U *pDictContentLength) +{ + switch (pDictionaryData->dictionaryType) + { + case CPA_DC_UNCOMPRESSED_DICT: + *pDictPrefixLength = 0; + *pDictContentLength = dictLenInBytes; + break; + default: + LAC_INVALID_PARAM_LOG("Invalid dictionary type"); + break; + } +} + void dcCompression_ProcessCallback(void *pRespMsg) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -1499,6 +1533,53 @@ inline Cpa32U dcCalcAsbRegValue(Cpa32U srcLen, return asbRegVal; } +STATIC INLINE CpaStatus +dcPopulateDictReqParams(const CpaDcDictionaryData *pDictionaryData, + dc_capabilities_t *pDcCapabilities, + const Cpa64U dictionaryLenInBytes, + const dc_session_desc_t *pSessionDesc, + icp_qat_fw_comp_req_t *pMsg) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaBoolean dictIdSupported = CPA_FALSE; + Cpa32U dictionaryPrefixLength = 0; + Cpa32U dictionaryContentLength = 0; + + dcGetDictionaryParams(pDictionaryData, + pDcCapabilities, + (Cpa32U)dictionaryLenInBytes, + &dictionaryPrefixLength, + &dictionaryContentLength); + + /* LW 19 Populate Dictionary Parameters */ + switch (pDictionaryData->dictionaryType) + { + case CPA_DC_UNCOMPRESSED_DICT: + /* Populate the dictionary length */ + pMsg->comp_pars.dictionary_params = + ICP_QAT_FW_COMP_DICTIONARY_PARAMS_BUILD( + ICP_QAT_FW_COMP_DICT_TYPE_UNCOMPRESSED, + dictionaryContentLength); + break; + case CPA_DC_COMPRESSED_DICT: + default: + LAC_UNSUPPORTED_PARAM_LOG("Unsupported dictionary type"); + return CPA_STATUS_UNSUPPORTED; + break; + } + + status = dcGetDictIdSupportCapabilityStatus( + pDcCapabilities, pSessionDesc->compType, &dictIdSupported); + if (CPA_STATUS_SUCCESS != status) + return status; + + if (dictIdSupported) + { + pMsg->u3.zstd_dict_id.dictionary_id = pDictionaryData->dictId; + } + return CPA_STATUS_SUCCESS; +} + /** ***************************************************************************** * @ingroup Dc_DataCompression @@ -1577,7 +1658,6 @@ CpaStatus dcCreateRequest(dc_compression_cookie_t *pCookie, CpaBoolean asbThresholdSupported = CPA_FALSE; Cpa32U asbRegValue = 0; Cpa32U val32 = 0; - icp_qat_fw_comp_dict_type_t fwDictType = ICP_QAT_FW_COMP_DICT_TYPE_NONE; icp_qat_hw_compression_config_t *pCompConfig = NULL; Cpa64U dictionaryLenInBytes = 0; CpaBoolean zeroLengthRequestsSupported = CPA_FALSE; @@ -1976,6 +2056,10 @@ CpaStatus dcCreateRequest(dc_compression_cookie_t *pCookie, if (CPA_TRUE == errorInjectionSupported) { cnvErrorInjection = pSessionDesc->cnvErrorInjection; + if (DC_CAPS_GEN6_HW == pDcCapabilities->deviceData.hw_gen) + { + errorInjectionCode = ICP_QAT_FW_COMP_CNV_ERROR_CHECKSUM; + } } break; case DC_NO_CNV: @@ -2025,19 +2109,13 @@ CpaStatus dcCreateRequest(dc_compression_cookie_t *pCookie, ICP_QAT_HW_COMP_20_CONFIG_CSR_SOM_CONTROL_MASK); pCompConfig->upper_val |= BYTE_SWAP_32(val32); } - /* LW 19 Populate Dictionary Parameters */ - switch (pDictionaryData->dictionaryType) - { - case CPA_DC_UNCOMPRESSED_DICT: - fwDictType = ICP_QAT_FW_COMP_DICT_TYPE_UNCOMPRESSED; - break; - case CPA_DC_COMPRESSED_DICT: - default: - break; - } - pMsg->comp_pars.dictionary_params = - ICP_QAT_FW_COMP_DICTIONARY_PARAMS_BUILD(fwDictType, - dictionaryLenInBytes); + status = dcPopulateDictReqParams(pDictionaryData, + pDcCapabilities, + dictionaryLenInBytes, + pSessionDesc, + pMsg); + if (CPA_STATUS_SUCCESS != status) + return status; } @@ -2566,6 +2644,9 @@ CpaStatus cpaDcCompressData(CpaInstanceHandle dcInstance, #endif pSessionDesc = DC_SESSION_DESC_FROM_CTX_GET(pSessionHandle); + + DC_CHECK_LZ4_XXHASH_FLUSH(pSessionDesc, flushFlag); + #ifdef ICP_PARAM_CHECK if (CPA_STATUS_SUCCESS != dcParamCheck(insHandle, pSessionHandle, @@ -2637,6 +2718,7 @@ CpaStatus cpaDcCompressData2(CpaInstanceHandle dcInstance, CpaInstanceHandle insHandle = NULL; Cpa64U srcBuffSize = 0; dc_cnv_mode_t cnvMode = DC_NO_CNV; + dc_capabilities_t *pDcCapabilities = NULL; #ifdef ICP_PARAM_CHECK LAC_CHECK_NULL_PARAM(pOpData); @@ -2726,6 +2808,8 @@ CpaStatus cpaDcCompressData2(CpaInstanceHandle dcInstance, pSessionDesc = DC_SESSION_DESC_FROM_CTX_GET(pSessionHandle); + DC_CHECK_LZ4_XXHASH_FLUSH(pSessionDesc, pOpData->flushFlag); + if (CPA_TRUE == pOpData->compressAndVerify && CPA_DC_STATEFUL == pSessionDesc->sessState) { @@ -2741,8 +2825,13 @@ CpaStatus cpaDcCompressData2(CpaInstanceHandle dcInstance, return CPA_STATUS_UNSUPPORTED; } + /* Retrieve capabilities */ + pDcCapabilities = &pService->dc_capabilities; + + /* Integrity CRC for LZ4 has restrictions for generation lesser than GEN6 */ if ((CPA_DC_LZ4 == pSessionDesc->compType) && - (CPA_TRUE == pOpData->integrityCrcCheck)) + (CPA_TRUE == pOpData->integrityCrcCheck) && + (pDcCapabilities->deviceData.hw_gen < DC_CAPS_GEN6_HW)) { if (!(pService->generic_service_info.dcExtendedFeatures & DC_LZ4_E2E_COMP_CRC_EXTENDED_CAPABILITY)) @@ -2755,7 +2844,7 @@ CpaStatus cpaDcCompressData2(CpaInstanceHandle dcInstance, if (pSessionDesc->accumulateXXHash) { LAC_INVALID_PARAM_LOG("LZ4 with integrityCrcCheck and " - "acummulateXXHash enabled is not supported"); + "accumulateXXHash enabled is not supported"); return CPA_STATUS_UNSUPPORTED; } if (pSessionDesc->autoSelectBestHuffmanTree != CPA_DC_ASB_DISABLED) @@ -2872,40 +2961,6 @@ CpaStatus cpaDcCompressData2(CpaInstanceHandle dcInstance, NULL); } -CpaStatus dcCheckDictData(CpaDcDictionaryData *pDictionaryData, - sal_compression_service_t *pService, - dc_session_desc_t *pSessionDesc) -{ - CpaBoolean dictCompSupported = CPA_FALSE; -#ifdef ICP_PARAM_CHECK - Cpa64U dictionaryBuffSize = 0; - - LAC_CHECK_NULL_PARAM(pDictionaryData); - LAC_CHECK_NULL_PARAM(pDictionaryData->pDictionaryBuff); - - if (LacBuffDesc_BufferListVerify(pDictionaryData->pDictionaryBuff, - &dictionaryBuffSize, - LAC_NO_ALIGNMENT_SHIFT) != - CPA_STATUS_SUCCESS) - { - LAC_INVALID_PARAM_LOG("Invalid dictionary buffer list parameter"); - return CPA_STATUS_INVALID_PARAM; - } - - if (CPA_DC_UNCOMPRESSED_DICT != pDictionaryData->dictionaryType) - { - LAC_INVALID_PARAM_LOG("Invalid dictionary type"); - return CPA_STATUS_INVALID_PARAM; - } -#endif - - /* Check for uncompressed dictionary support */ - return dcGetUncompDictSupportCapabilityStatus(&pService->dc_capabilities, - pSessionDesc->compType, - pSessionDesc->sessDirection, - &dictCompSupported); -} - CpaStatus cpaDcDecompressData(CpaInstanceHandle dcInstance, CpaDcSessionHandle pSessionHandle, CpaBufferList *pSrcBuff, diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_dictionary.c b/quickassist/lookaside/access_layer/src/common/compression/dc_dictionary.c index ae1a0226..b52e706c 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_dictionary.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_dictionary.c @@ -30,6 +30,57 @@ #include "sal_service_state.h" #include "lac_buffer_desc.h" +STATIC CpaStatus dcCheckDictData(CpaInstanceHandle dc_inst, + CpaDcDictionaryData *pDictionaryData, + sal_compression_service_t *pService, + dc_session_desc_t *pSessionDesc, + const Cpa64U srcBuffSize) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa64U dictionaryBuffSize = 0; + CpaDcCapabilityReq capabilityReq = { 0 }; + CpaDcCapabilityResp capabilityResp = { 0 }; + + LAC_CHECK_NULL_PARAM(pDictionaryData); + LAC_CHECK_NULL_PARAM(pDictionaryData->pDictionaryBuff); + + switch (pDictionaryData->dictionaryType) + { + case CPA_DC_UNCOMPRESSED_DICT: + /* Uncompressed dictionary type is direction agnostic. */ + capabilityReq.capId = CPA_DC_CAP_BOOL_UNCOMPRESSED_DICT; + capabilityReq.algo = pSessionDesc->compType; + capabilityReq.dir = CPA_DC_DIR_COMPRESS; + status = cpaDcQueryCapabilityByType( + dc_inst, capabilityReq, &capabilityResp); + if (CPA_STATUS_SUCCESS != status || + CPA_FALSE == capabilityResp.boolStatus) + { + LAC_UNSUPPORTED_PARAM_LOG( + "Uncompressed dictionary type is not supported"); + return CPA_STATUS_UNSUPPORTED; + } +#ifdef ICP_PARAM_CHECK + /* Check if the dictionary buffer list is valid */ + if (LacBuffDesc_BufferListVerify(pDictionaryData->pDictionaryBuff, + &dictionaryBuffSize, + LAC_NO_ALIGNMENT_SHIFT) != + CPA_STATUS_SUCCESS) + { + LAC_INVALID_PARAM_LOG( + "Invalid dictionary buffer list parameter"); + return CPA_STATUS_INVALID_PARAM; + } +#endif + break; + default: + LAC_UNSUPPORTED_PARAM_LOG("Unsupported dictionary type"); + return CPA_STATUS_UNSUPPORTED; + } /* End switch() */ + + return CPA_STATUS_SUCCESS; +} + CpaStatus cpaDcCompressDataWithDict(CpaInstanceHandle dcInstance, CpaDcSessionHandle pSessionHandle, CpaBufferList *pSrcBuff, @@ -124,7 +175,8 @@ CpaStatus cpaDcCompressDataWithDict(CpaInstanceHandle dcInstance, } #endif - retStatus = dcCheckDictData(pDictionaryData, pService, pSessionDesc); + retStatus = dcCheckDictData( + insHandle, pDictionaryData, pService, pSessionDesc, srcBuffSize); if (CPA_STATUS_SUCCESS != retStatus) { return retStatus; @@ -229,12 +281,6 @@ CpaStatus cpaDcDecompressDataWithDict(CpaInstanceHandle dcInstance, pService = (sal_compression_service_t *)insHandle; pSessionDesc = DC_SESSION_DESC_FROM_CTX_GET(pSessionHandle); - retStatus = dcCheckDictData(pDictionaryData, pService, pSessionDesc); - if (CPA_STATUS_SUCCESS != retStatus) - { - return retStatus; - } - /* This check is outside the parameter checking as it is needed to manage * zero length requests */ if (CPA_STATUS_SUCCESS != @@ -245,6 +291,13 @@ CpaStatus cpaDcDecompressDataWithDict(CpaInstanceHandle dcInstance, return CPA_STATUS_INVALID_PARAM; } + retStatus = dcCheckDictData( + insHandle, pDictionaryData, pService, pSessionDesc, srcBuffSize); + if (CPA_STATUS_SUCCESS != retStatus) + { + return retStatus; + } + #ifdef ICP_PARAM_CHECK if (CPA_STATUS_SUCCESS != dcCheckSourceData(pService, pSessionHandle, diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_ns_datapath.c b/quickassist/lookaside/access_layer/src/common/compression/dc_ns_datapath.c index 8c255b14..1f39ca02 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_ns_datapath.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_ns_datapath.c @@ -32,6 +32,7 @@ #include "cpa_dc_dp.h" #include "icp_qat_hw_20_comp.h" +#include "icp_qat_hw_51_comp.h" /* ******************************************************************************* @@ -160,6 +161,10 @@ void dcNsCompression_ProcessCallback(void *pRespMsg) case ICP_QAT_FW_COMP_20_CMD_LZ4S_COMPRESS: compType = CPA_DC_LZ4S; break; + case ICP_QAT_FW_COMP_51_CMD_ZSTD_COMPRESS: + case ICP_QAT_FW_COMP_51_CMD_ZSTD_DECOMPRESS: + compType = CPA_DC_ZSTD; + break; } if (ICP_QAT_FW_COMP_CMD_DYNAMIC == @@ -710,7 +715,7 @@ STATIC void dcNsCompContentDescPopulate(sal_compression_service_t *pService, pCompControlBlock->comp_cfg_offset = 0; /* Disable all banks */ - pCompControlBlock->ram_bank_flags = 0; + ICP_QAT_FW_COMP_RAM_BANK_FLAGS(pCompControlBlock) = 0; pCompControlBlock->comp_state_addr = 0; @@ -1119,6 +1124,10 @@ STATIC CpaStatus dcNsCreateRequest(dc_compression_cookie_t *pCookie, { cnvErrorInjection = pService->generic_service_info.ns_isCnvErrorInjection; + if (DC_CAPS_GEN6_HW == hw_gen) + { + errorInjectionCode = ICP_QAT_FW_COMP_CNV_ERROR_CHECKSUM; + } } break; case DC_NO_CNV: @@ -1500,6 +1509,7 @@ CpaStatus cpaDcNsCompressData(CpaInstanceHandle dcInstance, CpaInstanceHandle insHandle = NULL; Cpa64U srcBuffSize = 0; dc_cnv_mode_t cnvMode = DC_CNV; + dc_capabilities_t *pDcCapabilities = NULL; LAC_CHECK_NULL_PARAM(pOpData); @@ -1540,6 +1550,9 @@ CpaStatus cpaDcNsCompressData(CpaInstanceHandle dcInstance, pService = (sal_compression_service_t *)insHandle; + /* Retrieve capabilities */ + pDcCapabilities = &pService->dc_capabilities; + #ifdef ICP_PARAM_CHECK /* Ensure this is a compression instance */ SAL_CHECK_INSTANCE_TYPE(insHandle, SAL_SERVICE_TYPE_COMPRESSION); @@ -1579,11 +1592,16 @@ CpaStatus cpaDcNsCompressData(CpaInstanceHandle dcInstance, } if ((CPA_DC_LZ4 == pSetupData->compType) && + (pDcCapabilities->deviceData.hw_gen < DC_CAPS_GEN6_HW) && (CPA_TRUE == pOpData->integrityCrcCheck)) { - LAC_INVALID_PARAM_LOG("LZ4 with integrityCrcCheck is not supported" - " in the compression direction"); - return CPA_STATUS_INVALID_PARAM; + if (!(pService->generic_service_info.dcExtendedFeatures & + DC_LZ4_E2E_COMP_CRC_EXTENDED_CAPABILITY)) + { + LAC_INVALID_PARAM_LOG("LZ4 with integrityCrcCheck is not supported" + " in the compression direction"); + return CPA_STATUS_UNSUPPORTED; + } } if (dcCheckOpData(pService, pOpData, pSetupData->sessDirection) != diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_session.c b/quickassist/lookaside/access_layer/src/common/compression/dc_session.c index 7ea6f3f5..873c2a09 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_session.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_session.c @@ -31,6 +31,8 @@ #include "icp_qat_fw_comp.h" #include "icp_qat_hw.h" #include "icp_qat_hw_20_comp.h" +#include "icp_qat_hw_51_comp.h" + /* ******************************************************************************* * Include private header files @@ -826,13 +828,6 @@ void dcCompHwBlockPopulateGen4(void *pServiceType, ICP_QAT_HW_DECOMP_20_LZ4_BLOCK_CHKSUM_ABSENT; } } - else if (CPA_DC_LZ4S == compType) - { - hw_decomp_lower_csr.algo = - ICP_QAT_HW_DECOMP_20_HW_DECOMP_FORMAT_LZ4S; - hw_decomp_lower_csr.mmctrl = - (icp_qat_hw_decomp_20_min_match_control_t)minMatch; - } else { LAC_LOG_ERROR("Algorithm not supported for Decompression\n"); @@ -844,6 +839,230 @@ void dcCompHwBlockPopulateGen4(void *pServiceType, } } +/** + ***************************************************************************** + * @ingroup Dc_DataCompression + * Populate the compression hardware block for QAT Gen6 + * + * @description + * This function will populate the compression hardware block and update + * for QAT Gen6 the size in bytes of the block + * + * @param[in] pService Pointer to the service + * @param[in] pSessionDesc Pointer to the session descriptor + * @param[in] pSetupData Pointer to setup data + * @param[in] pCompConfig Pointer to slice config word + * @param[in] compDecomp Direction of the operation + * @param[in] bNsOp Boolean to indicate no session operation + * + *****************************************************************************/ +void dcCompHwBlockPopulateGen6(void *pServiceType, + void *pSessionDescp, + CpaDcNsSetupData *pSetupData, + icp_qat_hw_compression_config_t *pCompConfig, + void *compDecompDir, + CpaBoolean bNsOp) +{ + CpaDcCompType compType = 0; + CpaDcCompLvl compLevel = 0; + CpaDcCompLZ4BlockMaxSize lz4BlockMaxSize; + CpaBoolean lz4BlockChecksum; + CpaBoolean lz4BlockIndependence; + CpaDcCompMinMatch minMatch; + sal_compression_service_t *pService = NULL; + dc_capabilities_t *pDcCapabilities = NULL; + dc_session_desc_t *pSessionDesc = NULL; + dc_request_dir_t compDecomp; + + pService = (sal_compression_service_t *)pServiceType; + pSessionDesc = (dc_session_desc_t *)pSessionDescp; + pDcCapabilities = &pService->dc_capabilities; + compDecomp = *(dc_request_dir_t *)compDecompDir; + + if (bNsOp) + { + compType = pSetupData->compType; + compLevel = pSetupData->compLevel; + lz4BlockMaxSize = pSetupData->lz4BlockMaxSize; + lz4BlockChecksum = pSetupData->lz4BlockChecksum; + lz4BlockIndependence = pSetupData->lz4BlockIndependence; + minMatch = pSetupData->minMatch; + } + else + { + compType = pSessionDesc->compType; + compLevel = pSessionDesc->compLevel; + lz4BlockMaxSize = pSessionDesc->lz4BlockMaxSize; + lz4BlockChecksum = pSessionDesc->lz4BlockChecksum; + lz4BlockIndependence = pSessionDesc->lz4BlockIndependence; + minMatch = pSessionDesc->minMatch; + } + + /* Direction: Compression */ + if (DC_COMPRESSION_REQUEST == compDecomp) + { + icp_qat_hw_comp_51_config_csr_upper_t hw_comp_upper_csr; + icp_qat_hw_comp_51_config_csr_lower_t hw_comp_lower_csr; + + osalMemSet(&hw_comp_upper_csr, 0, sizeof hw_comp_upper_csr); + osalMemSet(&hw_comp_lower_csr, 0, sizeof hw_comp_lower_csr); + + /* Disable Literal + Length Limit Block Drop by default */ + hw_comp_lower_csr.lllbd = ICP_QAT_HW_COMP_51_LLLBD_CTRL_LLLBD_DISABLED; + + /* Disable Adaptive Block Drop by default */ + hw_comp_lower_csr.abd = ICP_QAT_HW_COMP_51_ABD_ABD_DISABLED; + + switch (compType) + { + case CPA_DC_DEFLATE: + break; + case CPA_DC_LZ4: + /* LZ4 algorithm settings */ + hw_comp_upper_csr.bms = + (icp_qat_hw_comp_51_bms_t)lz4BlockMaxSize; + + if (CPA_TRUE == lz4BlockIndependence) + { + hw_comp_upper_csr.scb_mode_reset = + ICP_QAT_HW_COMP_51_SCB_MODE_RESET_MASK_RESET_HB_HT; + } + else + { + hw_comp_upper_csr.scb_mode_reset = + ICP_QAT_HW_COMP_51_SCB_MODE_RESET_MASK_DO_NOT_RESET_HB_HT; + } + break; + case CPA_DC_LZ4S: + /* LZ4s algorithm settings */ + /* Set MinMatch depending on API control setting */ + hw_comp_lower_csr.mmctrl = + (icp_qat_hw_comp_51_min_match_control_t)minMatch; + /* Set DMM algorithm */ + hw_comp_upper_csr.edmm = + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_EDMM_ENABLED; + break; + case CPA_DC_ZSTD: + break; + default: + LAC_LOG_ERROR("Compression algorithm not supported\n"); + break; + } + /* Set the search depth */ + switch (compLevel) + { + case CPA_DC_L1: + case CPA_DC_L2: + case CPA_DC_L3: + case CPA_DC_L4: + case CPA_DC_L5: + hw_comp_lower_csr.sd = ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_1; + + if (CPA_DC_ZSTD == compType) + { + /* Set DMM algorithm */ + hw_comp_upper_csr.edmm = + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_EDMM_ENABLED; + } + break; + case CPA_DC_L6: + case CPA_DC_L7: + case CPA_DC_L8: + hw_comp_lower_csr.sd = ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_6; + if (CPA_DC_ZSTD == compType) + { + /* Set DMM algorithm */ + hw_comp_upper_csr.edmm = + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_ZSTD_DMM_LITE; + } + break; + case CPA_DC_L9: + hw_comp_lower_csr.sd = ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_9; + if (CPA_DC_ZSTD == compType) + { + /* Set DMM algorithm */ + hw_comp_upper_csr.edmm = + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_ZSTD_DMM_LITE; + } + break; + default: + hw_comp_lower_csr.sd = + pDcCapabilities->deviceData.highestHwCompressionDepth; + + if (CPA_DC_DEFLATE == compType) + { + /* Enable Literal + Length Limit Block Drop + * with dynamic deflate compression when + * highest compression levels are selected. + */ + hw_comp_lower_csr.lllbd = + ICP_QAT_HW_COMP_51_LLLBD_CTRL_LLLBD_ENABLED; + + /* Enable Adaptive Block Drop for Deflate algorithm + * with higher compression levels + */ + hw_comp_lower_csr.abd = ICP_QAT_HW_COMP_51_ABD_ABD_ENABLED; + } + else if (CPA_DC_ZSTD == compType) + { + /* Set DMM algorithm */ + hw_comp_upper_csr.edmm = + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_ZSTD_DMM_LITE; + } + break; + } + /* Same for all algorithms */ + pCompConfig->upper_val = + ICP_QAT_FW_COMP_51_BUILD_CONFIG_UPPER(hw_comp_upper_csr); + + pCompConfig->lower_val = + ICP_QAT_FW_COMP_51_BUILD_CONFIG_LOWER(hw_comp_lower_csr); + /* Hard-coded HW-specific values */ + } + else /* Direction: Decompression */ + { + icp_qat_hw_decomp_51_config_csr_lower_t hw_decomp_lower_csr; + icp_qat_hw_decomp_51_config_csr_upper_t hw_decomp_upper_csr; + + osalMemSet(&hw_decomp_upper_csr, 0, sizeof hw_decomp_upper_csr); + osalMemSet(&hw_decomp_lower_csr, 0, sizeof hw_decomp_lower_csr); + + switch (compType) + { + case CPA_DC_DEFLATE: + break; + case CPA_DC_LZ4: + /* LZ4 algorithm decompression settings */ + + /* Set LZ4 max block size to 64KB */ + hw_decomp_upper_csr.bms = + (icp_qat_hw_decomp_51_bms_t)lz4BlockMaxSize; + + if (CPA_TRUE == lz4BlockChecksum) + { + hw_decomp_lower_csr.lbc = + ICP_QAT_HW_DECOMP_51_LZ4_BLOCK_CHECKSUM_PRESENT; + } + else + { + hw_decomp_lower_csr.lbc = + ICP_QAT_HW_DECOMP_51_LZ4_BLOCK_CHECKSUM_ABSENT; + } + break; + case CPA_DC_ZSTD: + break; + default: + LAC_LOG_ERROR("Unsupported format in decompression direction"); + break; + } + + pCompConfig->upper_val = + ICP_QAT_FW_DECOMP_51_BUILD_CONFIG_UPPER(hw_decomp_upper_csr); + pCompConfig->lower_val = + ICP_QAT_FW_DECOMP_51_BUILD_CONFIG_LOWER(hw_decomp_lower_csr); + } +} + /** ***************************************************************************** * @ingroup Dc_DataCompression @@ -893,16 +1112,17 @@ STATIC void dcCompContentDescPopulate(sal_compression_service_t *pService, (DC_DECOMPRESSION_REQUEST == compDecomp)) { /* Enable A, B, C, D, and E (CAMs). */ - pCompControlBlock->ram_bank_flags = ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank E */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank D */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank C */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank B */ - ICP_QAT_FW_COMP_BANK_ENABLED); /* Bank A */ + ICP_QAT_FW_COMP_RAM_BANK_FLAGS(pCompControlBlock) = + ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank E */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank D */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank C */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank B */ + ICP_QAT_FW_COMP_BANK_ENABLED); /* Bank A */ bankEnabled = CPA_TRUE; } else if ((CPA_DC_STATEFUL == pSessionDesc->sessState) && @@ -910,31 +1130,33 @@ STATIC void dcCompContentDescPopulate(sal_compression_service_t *pService, (DC_DECOMPRESSION_REQUEST == compDecomp)) { /* Enable A, B, C, and D (no CAMs for LZ4). */ - pCompControlBlock->ram_bank_flags = ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank E */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank D */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank C */ - ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank B */ - ICP_QAT_FW_COMP_BANK_ENABLED); /* Bank A */ + ICP_QAT_FW_COMP_RAM_BANK_FLAGS(pCompControlBlock) = + ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank E */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank D */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank C */ + ICP_QAT_FW_COMP_BANK_ENABLED, /* Bank B */ + ICP_QAT_FW_COMP_BANK_ENABLED); /* Bank A */ bankEnabled = CPA_TRUE; } else { /* Disable all banks */ - pCompControlBlock->ram_bank_flags = ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank E */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank D */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank C */ - ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank B */ - ICP_QAT_FW_COMP_BANK_DISABLED); /* Bank A */ + ICP_QAT_FW_COMP_RAM_BANK_FLAGS(pCompControlBlock) = + ICP_QAT_FW_COMP_RAM_FLAGS_BUILD( + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank I */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank H */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank G */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank F */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank E */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank D */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank C */ + ICP_QAT_FW_COMP_BANK_DISABLED, /* Bank B */ + ICP_QAT_FW_COMP_BANK_DISABLED); /* Bank A */ } if (DC_COMPRESSION_REQUEST == compDecomp) @@ -1103,6 +1325,9 @@ CpaStatus dcGetCompressCommandId(sal_compression_service_t *pService, case CPA_DC_LZ4S: *pDcCmdId = ICP_QAT_FW_COMP_20_CMD_LZ4S_COMPRESS; break; + case CPA_DC_ZSTD: + *pDcCmdId = ICP_QAT_FW_COMP_51_CMD_ZSTD_COMPRESS; + break; default: LAC_LOG_ERROR("Algorithm not supported for compression\n"); status = CPA_STATUS_UNSUPPORTED; @@ -1151,6 +1376,9 @@ CpaStatus dcGetDecompressCommandId(sal_compression_service_t *pService, case CPA_DC_LZ4: *pDcCmdId = ICP_QAT_FW_COMP_20_CMD_LZ4_DECOMPRESS; break; + case CPA_DC_ZSTD: + *pDcCmdId = ICP_QAT_FW_COMP_51_CMD_ZSTD_DECOMPRESS; + break; default: LAC_ENSURE(CPA_FALSE, "Algo not supported for decompression\n"); status = CPA_STATUS_UNSUPPORTED; @@ -1453,29 +1681,8 @@ CpaStatus dcInitSession(CpaInstanceHandle dcInstance, /* Alter auto select best setting depending on the hardware version */ /* Configure CRC parameters based on the hardware version */ - if (DC_CAPS_GEN4_HW != pDcCapabilities->deviceData.hw_gen) - { - /* Gen 2 hardware devices */ - if (CPA_DC_ASB_ENABLED == pSessionDesc->autoSelectBestHuffmanTree) - { - /* Select best compression ratio optimization setting */ - pSessionDesc->autoSelectBestHuffmanTree = - CPA_DC_ASB_UNCOMP_STATIC_DYNAMIC_WITH_STORED_HDRS; - } - - /* Gen2 hardcoded CRC parameters */ - pSessionDesc->crcConfig.crcParam.crcPoly = DC_CRC_POLY_DEFAULT; - pSessionDesc->crcConfig.crcParam.iCrc32Cpr = DC_DEFAULT_CRC; - pSessionDesc->crcConfig.crcParam.oCrc32Cpr = DC_DEFAULT_CRC; - pSessionDesc->crcConfig.crcParam.iCrc32Xlt = DC_DEFAULT_CRC; - pSessionDesc->crcConfig.crcParam.oCrc32Xlt = DC_DEFAULT_CRC; - pSessionDesc->crcConfig.crcParam.xorFlags = DC_XOR_FLAGS_DEFAULT; - pSessionDesc->crcConfig.crcParam.xorOut = DC_XOR_OUT_DEFAULT; - pSessionDesc->crcConfig.crcParam.deflateBlockType = DC_STATIC_TYPE; - } - else { - /* Gen 4 hardware devices */ + /* Gen 4 and Gen 6 hardware devices */ switch (pSessionDesc->autoSelectBestHuffmanTree) { case CPA_DC_ASB_STATIC_DYNAMIC: /* Fall through */ @@ -1490,7 +1697,12 @@ CpaStatus dcInitSession(CpaInstanceHandle dcInstance, /* Keep setting from session setup data */ break; } - /* Gen4 hardcoded CRC parameters */ + if ((DC_CAPS_GEN6_HW == pDcCapabilities->deviceData.hw_gen) && + (CPA_DC_ASB_ENABLED == pSessionDesc->autoSelectBestHuffmanTree)) + { + pSessionDesc->asb_max_block_size = DC_ASB_MAX_BLOCK_SIZE; + } + /* Gen4 and Gen6 hardcoded CRC parameters */ pSessionDesc->crcConfig.crcParam.crc64Poly = DC_CRC64_POLY_DEFAULT; pSessionDesc->crcConfig.crcParam.iCrc64Cpr = DC_DEFAULT_CRC; pSessionDesc->crcConfig.crcParam.oCrc64Cpr = DC_DEFAULT_CRC; diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_stats.c b/quickassist/lookaside/access_layer/src/common/compression/dc_stats.c index 7fffa1fd..a7c442c4 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_stats.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_stats.c @@ -27,7 +27,6 @@ #include "cpa.h" #include "cpa_dc.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* ******************************************************************************* * Include private header files diff --git a/quickassist/lookaside/access_layer/src/common/compression/include/dc_capabilities.h b/quickassist/lookaside/access_layer/src/common/compression/include/dc_capabilities.h index 5cc01951..b64bc789 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/include/dc_capabilities.h +++ b/quickassist/lookaside/access_layer/src/common/compression/include/dc_capabilities.h @@ -121,6 +121,7 @@ extern "C" { #define DC_CAPS_DEFLATE_SUPPORTED (0x1) #define DC_CAPS_LZ4_SUPPORTED (0x4) #define DC_CAPS_LZ4S_SUPPORTED (0x8) +#define DC_CAPS_ZSTD_SUPPORTED (0x64) #define DC_CAPS_PCRC (0x4) #define DC_CAPS_DYNAMIC_HUFF_BUFF_REQ (0x400) #define DC_CAPS_XXHASH32_OFFSET (1) @@ -131,8 +132,12 @@ extern "C" { #define DC_CAPS_ADLER32_OFFSET (1) #define DC_CAPS_PCRC_OFFSET (2) #define DC_CAPS_LZ4S_OFFSET (3) +#define DC_CAPS_ZSTD_OFFSET (6) #define DC_CAPS_CNVNR_EXTENDED_OFFSET (8) +#define DC_CAPS_DICT_ID (0x8) +#define DC_CAPS_DICT_ID_OFFSET (3) + /* Restriction on the source buffer size for compression due to the firmware * processing */ #define DC_SRC_BUFFER_MIN_SIZE (15) @@ -147,6 +152,17 @@ extern "C" { */ #define DC_DEST_BUFFER_STA_MIN_SIZE_GEN4 (1026) +/* Minimum destination buffer size for dynamic deflate + * For 6xxx, there is no skid pad. Min buffer size + * is calculated using deflate compressBound formula + * with 1 as input buffer size + */ +#define DC_DEST_BUFFER_DYN_MIN_SIZE_GEN6 (6) + +/* Minimum destination buffer size for Gen6 is + * 2 bytes + */ +#define DC_DEST_BUFFER_MIN_SIZE_GEN6 (2) /* Size of the history window. * Base 2 logarithm of maximum window size minus 8. Each bit represents a * possible window size. Note: In compression direction only one windows size @@ -605,8 +621,12 @@ typedef struct dc_capabilities_zstd_s * (FALSE) */ Cpa8U dictCompSupported : DC_BITFIELD_SIZE_1; - /**< Dictionary type, see \ref CpaDcDictType */ - Cpa8U dictCap : DC_BITFIELD_SIZE_2; + /**< True if the algorithm supports AEAD_THEN_DECOMPRESS + * chaining operation */ + Cpa8U aeadThenDecompressSupported : DC_BITFIELD_SIZE_1; + + /**< True if the HW supports dictionary ID */ + Cpa8U dictId : DC_BITFIELD_SIZE_1; /**< Session direction, see \ref CpaDcDir */ Cpa8U dirMask : DC_BITFIELD_SIZE_2; @@ -642,12 +662,8 @@ typedef struct dc_capabilities_zstd_s * chaining operation */ Cpa8U compressThenAeadSupported : DC_BITFIELD_SIZE_1; - /**< True if the algorithm supports AEAD_THEN_DECOMPRESS - * chaining operation */ - Cpa8U aeadThenDecompressSupported : DC_BITFIELD_SIZE_1; - - /**< True if the HW supports dictionary ID */ - Cpa8U dictId : DC_BITFIELD_SIZE_1; + /**< Dictionary type, see \ref CpaDcDictType */ + Cpa8U dictCap : DC_BITFIELD_SIZE_2; Cpa8U zstdReserved : DC_BITFIELD_SIZE_5; @@ -660,13 +676,14 @@ typedef struct dc_capabilities_zstd_s * @ingroup dc_capabilities * Supported HW device generations. * @description - * - QAT supported device generations ranging between Gen2 and Gen4. + * - QAT supported device generations ranging between Gen2, Gen4 and Gen6. *****************************************************************************/ typedef enum dc_hw_gen_types { DC_CAPS_GEN2_HW = 2, DC_CAPS_GEN4_HW, DC_CAPS_GEN5_HW, + DC_CAPS_GEN6_HW, } dc_hw_gen_types_t; @@ -755,9 +772,37 @@ typedef struct dc_hw_device_capabilities_s /* sal_compression_device_data */ *****************************************************************************/ typedef struct dc_capabilities_s { + /**< Populate the compression hardware block for QAT */ + void (*dcCompHwBlockPopulate)(void *pService, + void *pSessionDesc, + CpaDcNsSetupData *pSetupData, + icp_qat_hw_compression_config_t *pCompConfig, + void *compDecomp, + CpaBoolean bNsOp); + void (*dcNsCompHwBlockPopulate)( + void *pService, + void *pSessionDesc, + CpaDcNsSetupData *pSetupData, + icp_qat_hw_compression_config_t *pCompConfig, + void *compDecomp, + CpaBoolean bNsOp); + /**< Compress bound API's to calculate destination buffer size */ + CpaStatus (*dcDeflateBound)(CpaDcHuffType huffType, + Cpa32U inputSize, + Cpa32U *outputSize); + CpaStatus (*dcLZ4Bound)(Cpa32U inputSize, Cpa32U *outputSize); + CpaStatus (*dcLZ4SBound)(Cpa32U inputSize, Cpa32U *outputSize); + CpaStatus (*dcZstdBound)(Cpa32U inputSize, Cpa32U *outputSize); + void (*dcGetMetaSizeForSrcBuffWithDict)(Cpa32U numDictBuffers, + Cpa32U numSourceBuffers, + Cpa32U *pSizeInBytes); + /**< Device specific data, see \ref sal_compression_device_data_t */ dc_hw_device_capabilities_t deviceData; + /**< Number of intermediate buffers */ + Cpa16U numInterBuffs; + /**< CRC integrity */ dc_capabilities_crc_integrity_t crcIntegrity; @@ -767,18 +812,9 @@ typedef struct dc_capabilities_s /**< CnV */ dc_capabilities_cnv_t cnv; - /**< Algorithms related content, see \ref CpaDcCompType */ - dc_capabilities_deflate_t deflate; - dc_capabilities_lz4_t lz4; - dc_capabilities_lz4s_t lz4s; - dc_capabilities_zstd_t zstd; - /**< Generic data not related to device and not related * to the type of algorithm */ - /**< Number of intermediate buffers */ - Cpa16U numInterBuffs; - /**< Session state, see \ref CpaDcState */ Cpa8U sessState : DC_BITFIELD_SIZE_2; @@ -817,29 +853,10 @@ typedef struct dc_capabilities_s Cpa8U genericReserve : DC_BITFIELD_SIZE_1; - /**< Populate the compression hardware block for QAT */ - void (*dcCompHwBlockPopulate)( - void *pService, - void *pSessionDesc, - CpaDcNsSetupData *pSetupData, - icp_qat_hw_compression_config_t *pCompConfig, - void *compDecomp, - CpaBoolean bNsOp); - void (*dcNsCompHwBlockPopulate)( - void *pService, - void *pSessionDesc, - CpaDcNsSetupData *pSetupData, - icp_qat_hw_compression_config_t *pCompConfig, - void *compDecomp, - CpaBoolean bNsOp); - /**< Compress bound API's to calculate destination buffer size */ - CpaStatus (*dcDeflateBound)(void *pService, - CpaDcHuffType huffType, - Cpa32U inputSize, - Cpa32U *outputSize); - CpaStatus (*dcLZ4Bound)(Cpa32U inputSize, Cpa32U *outputSize); - CpaStatus (*dcLZ4SBound)(Cpa32U inputSize, Cpa32U *outputSize); - CpaStatus (*dcZstdBound)(Cpa32U inputSize, Cpa32U *outputSize); + dc_capabilities_deflate_t deflate; + dc_capabilities_lz4_t lz4; + dc_capabilities_lz4s_t lz4s; + dc_capabilities_zstd_t zstd; } dc_capabilities_t; /* Type to access extended features bit fields */ @@ -875,6 +892,7 @@ typedef struct fw_caps_s Cpa32U deflate_caps; Cpa16U lz4_caps; Cpa16U lz4s_caps; + Cpa16U zstd_caps; Cpa8U is_fw_caps; } fw_caps_t; @@ -894,12 +912,6 @@ CpaStatus dcGetAsbAlgoSupportCapabilityStatus( Cpa32U algo, CpaBoolean *pCapStatus); -CpaStatus dcGetUncompDictSupportCapabilityStatus( - dc_capabilities_t *pDcCapabilities, - Cpa32U algo, - Cpa32U dirMask, - CpaBoolean *pCapStatus); - CpaStatus dcGetZeroLengthReqCapabilityStatus(dc_capabilities_t *pDcCapabilities, Cpa32U algo, CpaBoolean *pCapStatus); @@ -931,6 +943,10 @@ CpaStatus dcGetAsbEnablePrefCapabilityStatus(dc_capabilities_t *pDcCapabilities, Cpa32U algo, CpaBoolean *pCapStatus); +CpaStatus dcGetDictIdSupportCapabilityStatus(dc_capabilities_t *pDcCapabilities, + Cpa32U algo, + CpaBoolean *pCapStatus); + #ifdef __cplusplus } /* close the extern "C" { */ #endif diff --git a/quickassist/lookaside/access_layer/src/common/compression/include/dc_chain.h b/quickassist/lookaside/access_layer/src/common/compression/include/dc_chain.h index 932078ba..3df7c3df 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/include/dc_chain.h +++ b/quickassist/lookaside/access_layer/src/common/compression/include/dc_chain.h @@ -43,6 +43,8 @@ typedef enum dc_chain_opdata_type_e { DC_CHAIN_OPDATA_TYPE0 = 0, /**< Refer to the API definition for CpaDcChainOpData format */ + DC_CHAIN_OPDATA_TYPE1 +/**< Refer to the API definition for CpaDcChainOpData2 format */ } dc_chain_opdata_type_t; typedef struct dc_chain_opdata_ext_s @@ -60,6 +62,8 @@ typedef enum dc_chain_results_type_e { DC_CHAIN_RESULTS_TYPE0 = 0, /**< Refer to the API definition for CpaDcChainRqResults format */ + DC_CHAIN_RESULTS_TYPE1 +/**< Refer to the API definition for CpaDcChainRqVResults format */ } dc_chain_results_type_t; typedef struct dc_chain_results_ext_s diff --git a/quickassist/lookaside/access_layer/src/common/compression/include/dc_crc64.h b/quickassist/lookaside/access_layer/src/common/compression/include/dc_crc64.h index 1e48ac3c..acd84e62 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/include/dc_crc64.h +++ b/quickassist/lookaside/access_layer/src/common/compression/include/dc_crc64.h @@ -101,7 +101,7 @@ CpaStatus dcGenerateLookupTable(Cpa64U crc64Polynomial, * @retval CPA_STATUS_SUCCESS Function executed successfully * @retval CPA_STATUS_INVALID_PARAM Invalid parameter passed in */ -CpaStatus dcCalculateProgCrc64(CpaCrcControlData *pCrcConfig, +CpaStatus dcCalculateProgCrc64(const CpaCrcControlData *pCrcConfig, Cpa64U *pCrcLookupTable, const CpaBufferList *pBufferList, Cpa32U consumedBytes, diff --git a/quickassist/lookaside/access_layer/src/common/compression/include/dc_datapath.h b/quickassist/lookaside/access_layer/src/common/compression/include/dc_datapath.h index c38a5f1f..ee91659e 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/include/dc_datapath.h +++ b/quickassist/lookaside/access_layer/src/common/compression/include/dc_datapath.h @@ -414,8 +414,9 @@ CpaStatus dcCheckOpData(sal_compression_service_t *pService, CpaDcOpData *pOpData, CpaDcSessionDir sessDirection); -CpaStatus dcCheckDictData(CpaDcDictionaryData *pDictionaryData, - sal_compression_service_t *pService, - dc_session_desc_t *pSessionDesc); - +void dcGetDictionaryParams(const CpaDcDictionaryData *pDictionaryData, + const dc_capabilities_t *pDcCapabilities, + const Cpa32U dictLenInBytes, + Cpa32U *pDictPrefixLength, + Cpa32U *pDictContentLength); #endif /* DC_DATAPATH_H_ */ diff --git a/quickassist/lookaside/access_layer/src/common/compression/include/dc_session.h b/quickassist/lookaside/access_layer/src/common/compression/include/dc_session.h index 604ac61a..514e7074 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/include/dc_session.h +++ b/quickassist/lookaside/access_layer/src/common/compression/include/dc_session.h @@ -500,6 +500,30 @@ void dcCompHwBlockPopulateGen4(void *pService, void *compDecomp, CpaBoolean bNsOp); +/** + ***************************************************************************** + * @ingroup Dc_DataCompression + * Populate the compression hardware block for QAT Gen6 + * + * @description + * This function will populate the compression hardware block and update + * for QAT Gen6 the size in bytes of the block + * + * @param[in] pService Pointer to the service + * @param[in] pSessionDesc Pointer to the session descriptor + * @param[in] pSetupData Pointer to setup data + * @param[in] pCompConfig Pointer to slice config word + * @param[in] compDecomp Direction of the operation + * @param[in] bNsOp Boolean to indicate no session operation + * + *****************************************************************************/ +void dcCompHwBlockPopulateGen6(void *pService, + void *pSessionDesc, + CpaDcNsSetupData *pSetupData, + icp_qat_hw_compression_config_t *pCompConfig, + void *compDecomp, + CpaBoolean bNsOp); + /** ***************************************************************************** * @ingroup Dc_DataCompression @@ -548,18 +572,29 @@ void dcNsCompHwBlockPopulate(void *pService, void *compDecomp, CpaBoolean bNsOp); -CpaStatus dcDeflateBoundGen2(void *pServiceType, - CpaDcHuffType huffType, +CpaStatus dcDeflateBoundGen2(CpaDcHuffType huffType, Cpa32U inputSize, Cpa32U *outputSize); -CpaStatus dcDeflateBoundGen4(void *pServiceType, - CpaDcHuffType huffType, +CpaStatus dcDeflateBoundGen4(CpaDcHuffType huffType, Cpa32U inputSize, Cpa32U *outputSize); +CpaStatus dcDeflateBoundGen4_2(CpaDcHuffType huffType, + Cpa32U inputSize, + Cpa32U *outputSize); + +CpaStatus dcDeflateBoundGen6(CpaDcHuffType huffType, + Cpa32U inputSize, + Cpa32U *outputSize); CpaStatus dcLZ4BoundGen4(Cpa32U inputSize, Cpa32U *outputSize); CpaStatus dcLZ4SBoundGen4(Cpa32U inputSize, Cpa32U *outputSize); +CpaStatus dcLZ4BoundGen6(Cpa32U inputSize, Cpa32U *outputSize); +CpaStatus dcLZ4SBoundGen6(Cpa32U inputSize, Cpa32U *outputSize); +CpaStatus dcZstdBoundGen6(Cpa32U inputSize, Cpa32U *outputSize); +void dcGetMetaSizeForSrcBuffWithDictGen6(Cpa32U numDictBuffers, + Cpa32U numSourceBuffers, + Cpa32U *pSizeInBytes); /** ***************************************************************************** * @ingroup Dc_DataCompression diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_control_path.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_control_path.c index 89ca40b5..8ac43d7c 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_control_path.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_control_path.c @@ -39,7 +39,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_data_path.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_data_path.c index 470c8abb..77c36dd2 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_data_path.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_data_path.c @@ -97,7 +97,6 @@ /* ADF includes */ #include "icp_accel_devices.h" #include "icp_adf_init.h" -#include "icp_adf_debug.h" #include "icp_adf_transport.h" /* Look Aside Includes */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_stats.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_stats.c index 87b53583..e5214edc 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_stats.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/diffie_hellman/lac_dh_stats.c @@ -28,7 +28,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/dsa/lac_dsa.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/dsa/lac_dsa.c index 87d4c957..80717cfc 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/dsa/lac_dsa.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/dsa/lac_dsa.c @@ -40,7 +40,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec.c index 8042477d..965ccee9 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec.c @@ -56,7 +56,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* QAT FW includes */ #include "icp_qat_fw_la.h" @@ -90,6 +89,7 @@ typedef struct _OptCurveParams Cpa32U dataOperationSizeBytes; Cpa32U function_point; Cpa32U function_generator; + CpaBoolean dpa_support; const Cpa8U *p; const Cpa8U *h; const Cpa8U *a; @@ -119,6 +119,13 @@ typedef const CpaCyEcCurveParametersWeierstrass *LacEc_WSCurvePtr; /**< number of 'out' arguments in the arguments size list for the P256 and P384 * Point Multiply operation */ #define LAC_POINT_MULTIPLY_P256P384_NUM_OUT_ARGS 2 +/**< number of bytes of random data for DPA */ +#define LAC_EC_DPA_P384_RANDOM_DATA_SIZE 96 +/**< DPA empty initialiser */ +#define EC_NON_DPA_INITIALISER \ + { \ + .pRandom = NULL, .createRandomData = CPA_FALSE, .dpa = CPA_FALSE \ + } /**< number of EC statistics */ #define LAC_EC_NUM_STATS (sizeof(CpaCyEcStats64) / sizeof(Cpa64U)) @@ -150,6 +157,7 @@ typedef struct _PointMultiplyOpData const CpaFlatBuffer *a; const CpaFlatBuffer *b; const CpaFlatBuffer *k; + const CpaFlatBuffer *r; const CpaFlatBuffer *pXk; const CpaFlatBuffer *pYk; } PointMultiplyOpData; @@ -185,6 +193,19 @@ typedef struct _PointMultiplyOpData * macro to write in/out parameters for the Generator * Point Multiply operation*/ +#define LacDpaEcGeneratorPointMultiplyWrite(in, out, data) \ + do \ + { \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.k, (data)->k); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.r, (data)->r); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.xr, (data)->pXk); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.yr, (data)->pYk); \ + } while (0); +/**< @ingroup Lac_Ec + * macro to write in/out parameters for the DPA Generator + * Point Multiply operation + */ + #define LacEcP256P384PointMultiplyWrite(in, out, data) \ do \ { \ @@ -196,6 +217,18 @@ typedef struct _PointMultiplyOpData * macro to write in/out parameters for the Generic P256 and P384 * Point Multiply operation*/ +#define LacDpaEcP384PointMultiplyWrite(in, out, data) \ + do \ + { \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.xp, (data)->xg); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.yp, (data)->yg); \ + LacDpaEcGeneratorPointMultiplyWrite(in, out, data) \ + } while (0); +/**< @ingroup Lac_Ec + * macro to write in/out parameters for the DPA Generic P384 + * Point Multiply operation + */ + #define LacEcPointVerifyFillStruct(in, px, py, pp, pa, pb) \ do \ { \ @@ -414,6 +447,7 @@ STATIC CpaStatus LacEc_GenericPointMultiplyBasicParamCheck( const CpaCyEcGenericPointMultiplyOpData *pOpData, const CpaBoolean *pMultiplyStatus, + const lac_pke_dpa_op_data_t *pDpa, const CpaFlatBuffer *pOutX, const CpaFlatBuffer *pOutY) { @@ -428,6 +462,10 @@ CpaStatus LacEc_GenericPointMultiplyBasicParamCheck( LAC_CHECK_FLAT_BUFFER_PARAM(pOutX, CHECK_NONE, 0); LAC_CHECK_FLAT_BUFFER_PARAM(pOutY, CHECK_NONE, 0); + if (pDpa->dpa) + LAC_CHECK_FLAT_BUFFER_PARAM( + pDpa->pRandom, CHECK_EQUALS, LAC_EC_DPA_P384_RANDOM_DATA_SIZE); + /* Currently we require Weierstrass curve - no other type is supported */ return LacEc_BasicParamCheckWeierstrass(pOpData->pCurve); } @@ -463,6 +501,7 @@ CpaStatus LacEcc_CommonPathPointMultiplyOperation( void *pCallbackTag, const CpaCyEcPointMultiplyOpData *pOpData_Legacy, const CpaCyEcGenericPointMultiplyOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY); @@ -478,6 +517,7 @@ CpaStatus LacEc_CommonPathPointMultiplySynchronous( const CpaInstanceHandle instanceHandle, const CpaCyEcPointMultiplyOpData *pOpData_Legacy, const CpaCyEcGenericPointMultiplyOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY) @@ -496,6 +536,7 @@ CpaStatus LacEc_CommonPathPointMultiplySynchronous( pSyncCallbackData, pOpData_Legacy, pOpData, + pDpa, pMultiplyStatus, pOutX, pOutY); @@ -792,6 +833,7 @@ CpaBoolean LacEc_GetOptFunctionId(const sal_crypto_service_t *pService, const CpaFlatBuffer *pH, const CpaFlatBuffer *pA, const CpaFlatBuffer *pB, + CpaBoolean dpa, Cpa32U *dataOperationSizeBytes, Cpa32U *function, CpaBoolean generator) @@ -808,6 +850,7 @@ CpaBoolean LacEc_GetOptFunctionId(const sal_crypto_service_t *pService, { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_256_BITS), .function_point = PKE_EC_POINT_MULTIPLICATION_P256, .function_generator = PKE_EC_GENERATOR_MULTIPLICATION_P256, + .dpa_support = CPA_FALSE, .p = nist_p256_p, .h = nist_p256_h, .a = nist_p256_a, @@ -816,6 +859,16 @@ CpaBoolean LacEc_GetOptFunctionId(const sal_crypto_service_t *pService, { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_384_BITS), .function_point = PKE_EC_POINT_MULTIPLICATION_P384, .function_generator = PKE_EC_GENERATOR_MULTIPLICATION_P384, + .dpa_support = CPA_FALSE, + .p = nist_p384_p, + .h = nist_p384_h, + .a = nist_p384_a, + .b = nist_p384_b }, + /* DPA P384 */ + { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_384_BITS), + .function_point = PKE_DPA_EC_POINT_MULTIPLICATION_P384, + .function_generator = PKE_DPA_EC_GENERATOR_MULTIPLICATION_P384, + .dpa_support = CPA_TRUE, .p = nist_p384_p, .h = nist_p384_h, .a = nist_p384_a, @@ -835,6 +888,9 @@ CpaBoolean LacEc_GetOptFunctionId(const sal_crypto_service_t *pService, res = (NULL == pH->pData) || LacPke_CompareFlatAndPtr( pH, curves[i].h, curves[i].dataOperationSizeBytes); + if (!res) + continue; + res = (dpa == curves[i].dpa_support); if (!res) continue; res = LacPke_CompareFlatAndPtr( @@ -896,6 +952,7 @@ CpaStatus LacEcc_CommonPathPointMultiply( void *pCallbackTag, const CpaCyEcPointMultiplyOpData *pOpData_Legacy, const CpaCyEcGenericPointMultiplyOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY); @@ -913,6 +970,7 @@ CpaStatus cpaCyEcPointMultiply(const CpaInstanceHandle instanceHandle, CpaFlatBuffer *pXk, CpaFlatBuffer *pYk) { + lac_pke_dpa_op_data_t dpa = EC_NON_DPA_INITIALISER; LAC_CHECK_NULL_PARAM(pOpData); return LacEcc_CommonPathPointMultiply(instanceHandle, @@ -920,6 +978,7 @@ CpaStatus cpaCyEcPointMultiply(const CpaInstanceHandle instanceHandle, pCallbackTag, pOpData, NULL, + &dpa, pMultiplyStatus, pXk, pYk); @@ -1079,6 +1138,7 @@ CpaStatus LacEcc_CommonPathPointMultiplyOperation( void *pCallbackTag, const CpaCyEcPointMultiplyOpData *pOpData_Legacy, const CpaCyEcGenericPointMultiplyOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY) @@ -1122,6 +1182,7 @@ CpaStatus LacEcc_CommonPathPointMultiplyOperation( /* Basic NULL Param Checking */ status = LacEc_GenericPointMultiplyBasicParamCheck(pOpData, pMultiplyStatus, + pDpa, pOutX, pOutY); LAC_CHECK_STATUS(status); @@ -1171,6 +1232,7 @@ CpaStatus LacEcc_CommonPathPointMultiplyOperation( .a = pA, .b = pB, .k = pK, + .r = pDpa->pRandom, .pXk = pOutX, .pYk = pOutY }; @@ -1181,10 +1243,15 @@ CpaStatus LacEcc_CommonPathPointMultiplyOperation( pH, pA, pB, + pDpa->dpa, &dataOperationSizeBytes, &functionID, generator); + /* DPA EC only supports P384 */ + if (pDpa->dpa && !optimisedSupported) + return CPA_STATUS_UNSUPPORTED; + if (!optimisedSupported) { status = LacEcc_CommonPathUnoptimised(pOpData_Legacy, @@ -1306,6 +1373,16 @@ CpaStatus LacEcc_PointMultiplyFillMMPStructsOpDataWrite( out->mmp_ec_point_multiplication_p384, data); return CPA_STATUS_SUCCESS; + case PKE_DPA_EC_POINT_MULTIPLICATION_P384: + LAC_EC_SET_LIST_PARAMS(inSizes, 4, size); + LAC_EC_SET_LIST_PARAMS(inAlloc, 4, externallyAllocated); + LAC_EC_SET_LIST_PARAMS(outSizes, 2, size); + LAC_EC_SET_LIST_PARAMS(outAlloc, 2, externallyAllocated); + LacDpaEcP384PointMultiplyWrite( + in->mmp_dpa_ec_point_multiplication_p384, + out->mmp_dpa_ec_point_multiplication_p384, + data); + return CPA_STATUS_SUCCESS; case PKE_EC_GENERATOR_MULTIPLICATION_P384: LAC_EC_SET_LIST_PARAMS(inSizes, 1, size); LAC_EC_SET_LIST_PARAMS(inAlloc, 1, externallyAllocated); @@ -1316,6 +1393,16 @@ CpaStatus LacEcc_PointMultiplyFillMMPStructsOpDataWrite( out->mmp_ec_generator_multiplication_p384, data); return CPA_STATUS_SUCCESS; + case PKE_DPA_EC_GENERATOR_MULTIPLICATION_P384: + LAC_EC_SET_LIST_PARAMS(inSizes, 2, size); + LAC_EC_SET_LIST_PARAMS(inAlloc, 2, externallyAllocated); + LAC_EC_SET_LIST_PARAMS(outSizes, 2, size); + LAC_EC_SET_LIST_PARAMS(outAlloc, 2, externallyAllocated); + LacDpaEcGeneratorPointMultiplyWrite( + in->mmp_dpa_ec_generator_multiplication_p384, + out->mmp_dpa_ec_generator_multiplication_p384, + data); + return CPA_STATUS_SUCCESS; } LAC_ASSERT(0 == *function, "Here *functionID should be 0"); @@ -1757,6 +1844,7 @@ CpaStatus LacEcc_CommonPathPointMultiply( void *pCallbackTag, const CpaCyEcPointMultiplyOpData *pOpData_Legacy, const CpaCyEcGenericPointMultiplyOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY) @@ -1772,6 +1860,7 @@ CpaStatus LacEcc_CommonPathPointMultiply( status = LacEc_CommonPathPointMultiplySynchronous(usedInstanceHandle, pOpData_Legacy, pOpData, + pDpa, pMultiplyStatus, pOutX, pOutY); @@ -1783,6 +1872,7 @@ CpaStatus LacEcc_CommonPathPointMultiply( pCallbackTag, pOpData_Legacy, pOpData, + pDpa, pMultiplyStatus, pOutX, pOutY); @@ -1797,6 +1887,7 @@ CpaStatus LacEcc_CommonPathPointMultiply( (LAC_ARCH_UINT)pOpData_Legacy, (LAC_ARCH_UINT)pOpData, (LAC_ARCH_UINT)pMultiplyStatus); + LAC_LOG1(" 0x%lx,", (LAC_ARCH_UINT)pDpa); LAC_LOG2(" 0x%lx, 0x%lx\n)", (LAC_ARCH_UINT)pOutX, (LAC_ARCH_UINT)pOutY); #endif @@ -1827,6 +1918,7 @@ CpaStatus cpaCyEcGenericPointMultiply( CpaFlatBuffer *pOutX, CpaFlatBuffer *pOutY) { + lac_pke_dpa_op_data_t dpa = EC_NON_DPA_INITIALISER; LAC_CHECK_NULL_PARAM(pOpData); return LacEcc_CommonPathPointMultiply(instanceHandle, @@ -1834,6 +1926,7 @@ CpaStatus cpaCyEcGenericPointMultiply( pCallbackTag, NULL, pOpData, + &dpa, pMultiplyStatus, pOutX, pOutY); @@ -1850,5 +1943,27 @@ CpaStatus cpaCyEcDpaGenericPointMultiply( CpaFlatBuffer *pXk, CpaFlatBuffer *pYk) { - return CPA_STATUS_UNSUPPORTED; + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + lac_pke_dpa_op_data_t dpa = { .pRandom = pRandom, + .createRandomData = createRandomData, + .dpa = CPA_TRUE }; + + LAC_CHECK_NULL_PARAM(pOpData); + LAC_CHECK_NULL_PARAM(pRandom); + LAC_CHECK_NULL_PARAM(pCryptoService); + + if (!pCryptoService->generic_service_info.dpaSupport || + dpa.createRandomData == CPA_TRUE) + return CPA_STATUS_UNSUPPORTED; + + return LacEcc_CommonPathPointMultiply(instanceHandle, + pCb, + pCallbackTag, + NULL, + pOpData, + &dpa, + pMultiplyStatus, + pXk, + pYk); } diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec_common.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec_common.c index 13eedd99..7c9b6a3b 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec_common.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ec_common.c @@ -61,7 +61,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" @@ -293,6 +292,21 @@ void LacEc_StatsShow(CpaInstanceHandle instanceHandle) ecdsaStats.numEcdsaSignRSCompleted, ecdsaStats.numEcdsaSignRSCompletedErrors, ecdsaStats.numEcdsaSignRSCompletedOutputInvalid); + /* KPT ECDSA Sign RS requests */ + osalLog(OSAL_LOG_LVL_USER, + OSAL_LOG_DEV_STDOUT, + BORDER + " KPT ECDSA Sign RS Requests-Succ: %16llu " BORDER "\n" BORDER + " KPT ECDSA Sign RS Request-Err: %16llu " BORDER "\n" BORDER + " KPT ECDSA Sign RS Completed-Succ: %16llu " BORDER "\n" BORDER + " KPT ECDSA Sign RS Completed-Err: %16llu " BORDER "\n" BORDER + " KPT ECDSA Sign RS Output Invalid: %16llu " BORDER + "\n" SEPARATOR, + ecdsaStats.numKptEcdsaSignRSRequests, + ecdsaStats.numKptEcdsaSignRSRequestErrors, + ecdsaStats.numKptEcdsaSignRSCompleted, + ecdsaStats.numKptEcdsaSignRSCompletedErrors, + ecdsaStats.numKptEcdsaSignRSCompletedOutputInvalid); /* verify requests */ osalLog(OSAL_LOG_LVL_USER, OSAL_LOG_DEV_STDOUT, diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdh.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdh.c index a3f0645d..49de8daf 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdh.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdh.c @@ -56,7 +56,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* Include QAT files */ #include "icp_qat_fw_mmp.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdsa.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdsa.c index 4b48c29f..305888c1 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdsa.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecdsa.c @@ -89,7 +89,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* QAT includes */ #include "icp_qat_fw_la.h" @@ -113,6 +112,9 @@ #include "sal_statistics.h" #include "lac_ec_nist_curves.h" +/**< Number of bytes of ECDSA cryptographically secure random data for DPA */ +#define LAC_ECDSA_DPA_P384_RANDOM_DATA_SIZE 48 + typedef struct _OptCurveParams { Cpa32U dataOperationSizeBytes; @@ -121,6 +123,7 @@ typedef struct _OptCurveParams const Cpa8U *n; const Cpa8U *a; const Cpa8U *b; + CpaBoolean dpa_support; } OptCurveParams; /* @@ -256,6 +259,21 @@ typedef struct _OptCurveParams LAC_MEM_SHARED_WRITE_FROM_PTR(out.s, pS); \ } while (0); +/* Macro to populate DPA Sign RS parameters */ +#define LacDpaEcdsaP384SignRSOpDataWrite(in, out, pOpData, random, pR, pS) \ + do \ + { \ + /* Populate input parameters */ \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.rnd, random); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.k, &pOpData->k); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.e, &pOpData->m); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.d, &pOpData->d); \ + \ + /* Populate output parameters */ \ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.r, pR); \ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.s, pS); \ + } while (0); + /**< @ingroup Lac_Ec * macro to write in/out parameters for the P256 and P384 * Ecdsa SignRS operation */ @@ -278,6 +296,7 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, const CpaCyEcdsaSignRSCbFunc pCb, void *pCallbackTag, const CpaCyEcdsaSignRSOpData *pOpData, + lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pR, CpaFlatBuffer *pS); @@ -460,6 +479,7 @@ STATIC void LacEc_FlatBuffToConcate(Cpa8U **ptr, ***************************************************************************/ STATIC CpaBoolean LacEcdsa_SignRSGetOptFunctionId(CpaCyEcFieldType primeRepresentation, + CpaBoolean dpa, const CpaFlatBuffer *pP, const CpaFlatBuffer *pN, const CpaFlatBuffer *pA, @@ -473,6 +493,7 @@ LacEcdsa_SignRSGetOptFunctionId(CpaCyEcFieldType primeRepresentation, /* P256 */ { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_256_BITS), .functionRS = PKE_ECDSA_SIGN_RS_P256, + .dpa_support = CPA_FALSE, .p = nist_p256_p, .n = nist_p256_n, .a = nist_p256_a, @@ -481,6 +502,15 @@ LacEcdsa_SignRSGetOptFunctionId(CpaCyEcFieldType primeRepresentation, /* P384 */ { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_384_BITS), .functionRS = PKE_ECDSA_SIGN_RS_P384, + .dpa_support = CPA_FALSE, + .p = nist_p384_p, + .n = nist_p384_n, + .a = nist_p384_a, + .b = nist_p384_b }, + /* DPA P384 */ + { .dataOperationSizeBytes = LAC_BITS_TO_BYTES(LAC_384_BITS), + .functionRS = PKE_DPA_ECDSA_SIGN_RS_P384, + .dpa_support = CPA_TRUE, .p = nist_p384_p, .n = nist_p384_n, .a = nist_p384_a, @@ -499,6 +529,9 @@ LacEcdsa_SignRSGetOptFunctionId(CpaCyEcFieldType primeRepresentation, if (!res) continue; + res = (dpa == curves[i].dpa_support); + if (!res) + continue; res = LacPke_CompareFlatAndPtr( pN, curves[i].n, curves[i].dataOperationSizeBytes); if (!res) @@ -540,6 +573,7 @@ LacEcdsa_SignRSFillMMPStructsOpt(icp_qat_fw_mmp_input_param_t *in, Cpa32U function, Cpa32U size, const CpaCyEcdsaSignRSOpData *pOpData, + const lac_pke_dpa_op_data_t *pDpa, CpaFlatBuffer *pR, CpaFlatBuffer *pS) { @@ -577,6 +611,15 @@ LacEcdsa_SignRSFillMMPStructsOpt(icp_qat_fw_mmp_input_param_t *in, pS); break; + case PKE_DPA_ECDSA_SIGN_RS_P384: + LacDpaEcdsaP384SignRSOpDataWrite(in->mmp_dpa_ecdsa_sign_rs_p384, + out->mmp_dpa_ecdsa_sign_rs_p384, + pOpData, + pDpa->pRandom, + pR, + pS); + break; + default: status = CPA_STATUS_INVALID_PARAM; break; @@ -1531,6 +1574,7 @@ CpaStatus cpaCyEcdsaSignS(const CpaInstanceHandle instanceHandle_in, ***************************************************************************/ STATIC CpaStatus LacEcdsa_SignRSSyn(const CpaInstanceHandle instanceHandle, const CpaCyEcdsaSignRSOpData *pOpData, + lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pR, CpaFlatBuffer *pS) @@ -1551,6 +1595,7 @@ STATIC CpaStatus LacEcdsa_SignRSSyn(const CpaInstanceHandle instanceHandle, LacSync_GenDualFlatBufVerifyCb, pSyncCallbackData, pOpData, + pDpa, pMultiplyStatus, pR, pS); @@ -1660,6 +1705,7 @@ void LacEcdsa_SignRSCallback(CpaStatus status, STATIC CpaStatus LacEcdsa_SignRSBasicParamCheck(const CpaInstanceHandle instanceHandle, const CpaCyEcdsaSignRSOpData *pOpData, + lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pR, CpaFlatBuffer *pS) @@ -1694,6 +1740,9 @@ CpaStatus LacEcdsa_SignRSBasicParamCheck(const CpaInstanceHandle instanceHandle, LAC_CHECK_SIZE(pR, CHECK_NONE, 0); LAC_CHECK_NULL_PARAM(pS->pData); LAC_CHECK_SIZE(pS, CHECK_NONE, 0); + if (pDpa->dpa) + LAC_CHECK_FLAT_BUFFER_PARAM( + pDpa->pRandom, CHECK_EQUALS, LAC_ECDSA_DPA_P384_RANDOM_DATA_SIZE); if (CPA_CY_EC_FIELD_TYPE_PRIME != pOpData->fieldType && CPA_CY_EC_FIELD_TYPE_BINARY != pOpData->fieldType) { @@ -1715,7 +1764,8 @@ CpaStatus LacEcdsa_OptimisedSignRS(const CpaInstanceHandle instanceHandle, void *pCallbackTag, const CpaCyEcdsaSignRSOpData *pOpData, CpaFlatBuffer *pR, - CpaFlatBuffer *pS) + CpaFlatBuffer *pS, + const lac_pke_dpa_op_data_t *pDpa) { CpaStatus status = CPA_STATUS_SUCCESS; sal_crypto_service_t *pCryptoService = NULL; @@ -1751,6 +1801,7 @@ CpaStatus LacEcdsa_OptimisedSignRS(const CpaInstanceHandle instanceHandle, } #endif optCurve = LacEcdsa_SignRSGetOptFunctionId(pOpData->fieldType, + pDpa->dpa, &(pOpData->q), &(pOpData->n), &(pOpData->a), @@ -1792,6 +1843,7 @@ CpaStatus LacEcdsa_OptimisedSignRS(const CpaInstanceHandle instanceHandle, functionID, dataOperationSize, pOpData, + pDpa, pR, pS); /* Send pke request */ @@ -1837,6 +1889,10 @@ CpaStatus cpaCyEcdsaSignRS(const CpaInstanceHandle instanceHandle_in, CpaFlatBuffer *pR, CpaFlatBuffer *pS) { + /* DPA is disabled for non DPA API calls */ + lac_pke_dpa_op_data_t dpa = { .pRandom = NULL, + .createRandomData = CPA_FALSE, + .dpa = CPA_FALSE }; #ifdef ICP_TRACE LAC_LOG7("Called with params (0x%lx, 0x%lx, 0x%lx, 0x%lx, " "0x%lx, 0x%lx, 0x%lx)\n", @@ -1853,6 +1909,7 @@ CpaStatus cpaCyEcdsaSignRS(const CpaInstanceHandle instanceHandle_in, pCb, pCallbackTag, pOpData, + &dpa, pMultiplyStatus, pR, pS); @@ -1862,6 +1919,7 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, const CpaCyEcdsaSignRSCbFunc pCb, void *pCallbackTag, const CpaCyEcdsaSignRSOpData *pOpData, + lac_pke_dpa_op_data_t *pDpa, CpaBoolean *pMultiplyStatus, CpaFlatBuffer *pR, CpaFlatBuffer *pS) @@ -1904,6 +1962,9 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, SAL_CHECK_INSTANCE_CRYPTO_CAPABILITY(instanceHandle, ecdsa); pCryptoService = (sal_crypto_service_t *)instanceHandle; + if (pDpa->dpa && (!pCryptoService->generic_service_info.dpaSupport || + pDpa->createRandomData == CPA_TRUE)) + return CPA_STATUS_UNSUPPORTED; /* Check if the API has been called in synchronous mode */ if (NULL == pCb) @@ -1911,6 +1972,7 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, /* Call synchronous mode function */ return LacEcdsa_SignRSSyn(instanceHandle, pOpData, + pDpa, pMultiplyStatus, pR, pS); @@ -1920,6 +1982,7 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, /* Basic Param Checking */ status = LacEcdsa_SignRSBasicParamCheck(instanceHandle, pOpData, + pDpa, pMultiplyStatus, pR, pS); @@ -1942,7 +2005,7 @@ STATIC CpaStatus LacEcdsa_EcdsaSignRS(const CpaInstanceHandle instanceHandle_in, CpaStatus isSupported = CPA_STATUS_SUCCESS; isSupported = LacEcdsa_OptimisedSignRS( - instanceHandle, pCb, pCallbackTag, pOpData, pR, pS); + instanceHandle, pCb, pCallbackTag, pOpData, pR, pS, pDpa); /* If LacEcdsa_OptimisedSignRS returns CPA_STATUS_UNSUPPORTED, * this means that the optimised path is not supported for the curve. @@ -2310,7 +2373,27 @@ CpaStatus cpaCyEcdsaDpaSignRS(const CpaInstanceHandle instanceHandle, CpaFlatBuffer *pR, CpaFlatBuffer *pS) { - return CPA_STATUS_UNSUPPORTED; + lac_pke_dpa_op_data_t dpa = { .pRandom = pRandom, + .createRandomData = createRandomData, + .dpa = CPA_TRUE }; + +#ifdef ICP_TRACE + LAC_LOG9("Called with params (0x%lx, 0x%lx, 0x%lx, 0x%lx, " + "0x%lx, %d, 0x%lx, 0x%lx, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pCb, + (LAC_ARCH_UINT)pCallbackTag, + (LAC_ARCH_UINT)pOpData, + (LAC_ARCH_UINT)pRandom, + (LAC_ARCH_UINT)createRandomData, + (LAC_ARCH_UINT)pSignStatus, + (LAC_ARCH_UINT)pR, + (LAC_ARCH_UINT)pS); +#endif + LAC_CHECK_NULL_PARAM(pRandom); + + return LacEcdsa_EcdsaSignRS( + instanceHandle, pCb, pCallbackTag, pOpData, &dpa, pSignStatus, pR, pS); } /** diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecsm2.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecsm2.c index 0f6d8ae3..2275adfb 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecsm2.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_ecsm2.c @@ -59,7 +59,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* QAT Includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_kpt_ecdsa.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_kpt_ecdsa.c index ed45f80e..7272f329 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_kpt_ecdsa.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/ecc/lac_kpt_ecdsa.c @@ -29,6 +29,318 @@ #include "cpa_cy_ecdsa.h" #include "cpa_cy_kpt.h" +/* +******************************************************************************* +* Include private header files +******************************************************************************* +*/ + +/* OSAL Includes */ +#include "Osal.h" + +/* FW includes */ +#include "icp_qat_fw_mmp.h" +#include "icp_qat_fw_mmp_ids.h" + +/* SAL includes */ +#include "lac_log.h" +#include "lac_common.h" +#include "lac_mem.h" +#include "lac_pke_utils.h" +#include "lac_pke_qat_comms.h" +#include "lac_sync.h" +#include "lac_ec.h" +#include "sal_service_state.h" +#include "lac_sal_types_crypto.h" +#include "sal_statistics.h" +#include "lac_kpt_crypto_qat_comms.h" +#include "lac_kpt_pro_qat_comms.h" + +/* +******************************************************************************* +* Intel KPT ECDSA Wrapped Private Key(WPK) has a fix format as: +* (d)'||AuthTag. +* The size of WPK is: sizeof(d) + sizeof(AuthTag). +* E.g. Size of PKE_KPT_ECDSA_SIGN_RS_P256 WPK is: 32 + 16 = 48 +******************************************************************************* +*/ +#define KPT_ECDSA_SIGN_RS_P256 (48) +/* KPT WPK size of curve NIST P-256 */ +#define KPT_ECDSA_SIGN_RS_P384 (64) +/* KPT WPK size of curve NIST P-384 */ +#define KPT_ECDSA_SIGN_RS_P521 (88) +/* KPT WPK size of curve NIST P-521 */ + +#define KPT_ECDSA_CURVE_NUM (3) +/* Available EC curves count for KPT, KPT supports 3 EC curves so far. */ +static const Cpa8U p256_aad[] = { 0x06, 0x08, 0x2A, 0x86, 0x48, + 0xCE, 0x3D, 0x03, 0x01, 0x07 }; +/* Additional Authenticated Data (AAD) for curve NIST P-256 */ +static const Cpa8U p384_aad[] = { 0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x22 }; +/* Additional Authenticated Data (AAD) for curve NIST P-384 */ +static const Cpa8U p521_aad[] = { 0x06, 0x05, 0x2B, 0x81, 0x04, 0x00, 0x23 }; +/* Additional Authenticated Data (AAD) for curve NIST P-521 */ +#define LAC_KPT_ECDSA_SIGNRS_NUM_OUT_ARGS (2) +/* Number of 'out' arguments in the argument size list */ + +#define LAC_EC_SIZE_QW6_IN_BYTES LAC_BITS_TO_BYTES(LAC_384_BITS) + +struct KptEcdsaAadIdMap +{ + Cpa32U aadLen; + Cpa32U functionID; + const Cpa8U *aad; +}; + +static struct KptEcdsaAadIdMap lacKptEcdsaAadIdMap[KPT_ECDSA_CURVE_NUM] = { + { sizeof(p256_aad), PKE_KPT_ECDSA_SIGN_RS_P256, p256_aad }, + { sizeof(p384_aad), PKE_KPT_ECDSA_SIGN_RS_P384, p384_aad }, + { sizeof(p521_aad), PKE_KPT_ECDSA_SIGN_RS_P521, p521_aad } +}; +/* MMP function ID & AAD mapping table */ + +/** + *************************************************************************** + * @ingroup Lac_KptEc + * Macro to increment a KPT ECDSA stat (derives offset into array of + * atomics) + * + ***************************************************************************/ +#ifndef DISABLE_STATS +#define LAC_KPT_ECDSA_STAT_INC(statistic, pCryptoService) \ + do \ + { \ + if (CPA_TRUE == \ + pCryptoService->generic_service_info.stats->bEccStatsEnabled) \ + { \ + osalAtomicInc(&pCryptoService->pLacEcdsaStatsArr \ + [(offsetof(CpaCyEcdsaStats64, statistic)) / \ + sizeof(Cpa64U)]); \ + } \ + } while (0) +#else +#define LAC_KPT_ECDSA_STAT_INC(statistic, pCryptoService) \ + (pCryptoService) = (pCryptoService) +#endif + +/** + *************************************************************************** + * @ingroup Lac_KptEc + * Get the size of KPT ECDSA Wrapped Private Key (WPK). + * + ***************************************************************************/ +STATIC Cpa32U LacKptEcdsa_GetKeyLength(const CpaFlatBuffer *pBuffer) +{ + Cpa32U keyLengthInBytes = LAC_KPT_PKE_INVALID_KEY_SIZE; + + switch (pBuffer->dataLenInBytes) + { + case KPT_ECDSA_SIGN_RS_P256: + keyLengthInBytes = LAC_EC_SIZE_QW4_IN_BYTES; + break; + + case KPT_ECDSA_SIGN_RS_P384: + keyLengthInBytes = LAC_EC_SIZE_QW6_IN_BYTES; + break; + + case KPT_ECDSA_SIGN_RS_P521: + keyLengthInBytes = LAC_EC_SIZE_QW9_IN_BYTES; + break; + + default: + LAC_LOG_ERROR("Invalid Wrapped Private Key Length."); + } + + return keyLengthInBytes; +} + +/** + *************************************************************************** + * @ingroup Lac_KptEc + * Get MMP function ID according to curve AAD + * + ***************************************************************************/ +STATIC Cpa32U LacKptEcdsa_GetMmpId(CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + Cpa32U functionID = LAC_PKE_INVALID_FUNC_ID; + Cpa32U i; + + for (i = 0; i < KPT_ECDSA_CURVE_NUM; i++) + { + if (!memcmp(lacKptEcdsaAadIdMap[i].aad, + pKptUnwrapContext->additionalAuthData, + lacKptEcdsaAadIdMap[i].aadLen)) + functionID = lacKptEcdsaAadIdMap[i].functionID; + } + + return functionID; +} + +/** + *************************************************************************** + * @ingroup Lac_KptEc + * KPT ECDSA Sign R & S internal callback + * + ***************************************************************************/ +STATIC +void LacKptEcdsa_SignRSCallback(CpaStatus status, + CpaBoolean signStatus, + CpaInstanceHandle instanceHandle, + lac_pke_op_cb_data_t *pCbData) +{ + CpaCyEcdsaSignRSCbFunc pCb = NULL; + void *pCallbackTag = NULL; + CpaCyEcdsaSignRSOpData *pOpData = NULL; + CpaFlatBuffer *pR = NULL; + CpaFlatBuffer *pS = NULL; + Cpa8U *pMemPool = NULL; + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + + /* Extract info from callback data structure */ + LAC_ASSERT_NOT_NULL(pCbData); + pCb = (CpaCyEcdsaSignRSCbFunc)pCbData->pClientCb; + pCallbackTag = pCbData->pCallbackTag; + pOpData = (CpaCyEcdsaSignRSOpData *)pCbData->pClientOpData; + pR = pCbData->pOutputData1; + pS = pCbData->pOutputData2; + pMemPool = (Cpa8U *)(pCbData->pOpaqueData); + + LAC_ASSERT_NOT_NULL(pCb); + LAC_ASSERT_NOT_NULL(pOpData); + LAC_ASSERT_NOT_NULL(pR); + LAC_ASSERT_NOT_NULL(pR->pData); + LAC_ASSERT_NOT_NULL(pS); + LAC_ASSERT_NOT_NULL(pS->pData); + + /* Free memory pool entry */ + if (pMemPool) + LacKpt_MemPoolFree(pMemPool); + + /* Increment stats */ + if (CPA_STATUS_SUCCESS == status) + { + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSCompleted, pCryptoService); + } + else + { + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSCompletedErrors, + pCryptoService); + } + + if ((CPA_FALSE == signStatus) && (CPA_STATUS_SUCCESS == status)) + { + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSCompletedOutputInvalid, + pCryptoService); + } + + /* Invoke the user callback */ + pCb(pCallbackTag, status, pOpData, signStatus, pR, pS); +} + +#ifdef ICP_PARAM_CHECK +/** + *************************************************************************** + * @ingroup Lac_KptEc + * KPT ECDSA Sign R & S parameter check + * + ***************************************************************************/ +STATIC +CpaStatus LacKptEcdsa_SignRSBasicParamCheck( + const CpaCyKptEcdsaSignRSOpData *pOpData, + CpaBoolean *pSignStatus, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + /* Check for NULL pointers */ + LAC_CHECK_NULL_PARAM(pSignStatus); + LAC_CHECK_NULL_PARAM(pOpData); + LAC_CHECK_NULL_PARAM(pR); + LAC_CHECK_NULL_PARAM(pS); + LAC_CHECK_NULL_PARAM(pKptUnwrapContext); + + /* Check flat buffers in pOpData for NULL and dataLen of 0 */ + LAC_CHECK_NULL_PARAM(pOpData->privateKey.pData); + LAC_CHECK_SIZE(&(pOpData->privateKey), CHECK_NONE, 0); + LAC_CHECK_NULL_PARAM(pOpData->m.pData); + LAC_CHECK_SIZE(&(pOpData->m), CHECK_NONE, 0); + LAC_CHECK_NULL_PARAM(pR->pData); + LAC_CHECK_SIZE(pR, CHECK_NONE, 0); + LAC_CHECK_NULL_PARAM(pS->pData); + LAC_CHECK_SIZE(pS, CHECK_NONE, 0); + + return CPA_STATUS_SUCCESS; +} +#endif + +/** + *************************************************************************** + * @ingroup Lac_KptEc + * KPT ECDSA Sign R & S synchronous function + * + ***************************************************************************/ +STATIC CpaStatus LacKptEcdsa_SignRSSyn(const CpaInstanceHandle instanceHandle, + const CpaCyKptEcdsaSignRSOpData *pOpData, + CpaBoolean *pSignStatus, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + lac_sync_op_data_t *pSyncCallbackData = NULL; + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + + status = LacSync_CreateSyncCookie(&pSyncCallbackData); + /* + * Call the asynchronous version of the function + * with the generic synchronous callback function as a parameter. + */ + if (CPA_STATUS_SUCCESS == status) + { + status = cpaCyKptEcdsaSignRS(instanceHandle, + LacSync_GenDualFlatBufVerifyCb, + pSyncCallbackData, + pOpData, + pSignStatus, + pR, + pS, + pKptUnwrapContext); + } + else + { + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSRequestErrors, pCryptoService); + return status; + } + + if (CPA_STATUS_SUCCESS == status) + { + CpaStatus wCbStatus = CPA_STATUS_FAIL; + wCbStatus = LacSync_WaitForCallback(pSyncCallbackData, + LAC_PKE_SYNC_CALLBACK_TIMEOUT, + &status, + pSignStatus); + if (CPA_STATUS_SUCCESS != wCbStatus) + { + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSCompletedErrors, + pCryptoService); + LacSync_SetSyncCookieComplete(pSyncCallbackData); + status = wCbStatus; + } + } + else + { + /* As the request was not sent successfully, the callback will never + * be called, so need to indicate that we are finished with cookie so + * that it can be destroyed. */ + LacSync_SetSyncCookieComplete(pSyncCallbackData); + } + + LacSync_DestroySyncCookie(&pSyncCallbackData); + return status; +} + /** *************************************************************************** * @ingroup Lac_KptEc @@ -44,5 +356,168 @@ CpaStatus cpaCyKptEcdsaSignRS(const CpaInstanceHandle instanceHandle, CpaFlatBuffer *pS, CpaCyKptUnwrapContext *pKptUnwrapContext) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + sal_crypto_service_t *pCryptoService = instanceHandle; + Cpa32U keyLengthInBytes = 0; + Cpa8U *pMemPool = NULL; + Cpa32U functionID = LAC_PKE_INVALID_FUNC_ID; + CpaFlatBuffer *pUnwrapCtxBuf = NULL; + icp_qat_fw_mmp_input_param_t in = { .flat_array = { 0 } }; + icp_qat_fw_mmp_output_param_t outRS = { .flat_array = { 0 } }; + lac_pke_op_cb_data_t cbData = { 0 }; + + /* Holding the calculated size of the input/output parameters */ + Cpa32U inArgSizeList[LAC_MAX_MMP_INPUT_PARAMS] = { 0 }; + Cpa32U outArgSizeList[LAC_MAX_MMP_OUTPUT_PARAMS] = { 0 }; + CpaBoolean internalMemInList[LAC_MAX_MMP_INPUT_PARAMS] = { CPA_FALSE }; + CpaBoolean internalMemOutList[LAC_MAX_MMP_OUTPUT_PARAMS] = { CPA_FALSE }; + +#ifdef ICP_TRACE + LAC_LOG7("Called with params (0x%lx, 0x%lx, 0x%lx, 0x%lx, " + "%d, 0x%lx, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pCb, + (LAC_ARCH_UINT)pCallbackTag, + (LAC_ARCH_UINT)pOpData, + (LAC_ARCH_UINT)pR, + (LAC_ARCH_UINT)pS, + (LAC_ARCH_UINT)pKptUnwrapContext); +#endif +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); +#endif + SAL_RUNNING_CHECK(instanceHandle); +#ifdef ICP_PARAM_CHECK + /* Check that the input parameters are valid */ + status = LacKptEcdsa_SignRSBasicParamCheck( + pOpData, pSignStatus, pR, pS, pKptUnwrapContext); +#endif + if (CPA_STATUS_SUCCESS == status) + { + /* Check if KPT is enabled on the service instance */ + SAL_GET_INSTANCE_CRYPTO_CAPABILITY_STATUS(status, instanceHandle, kpt); + if (CPA_STATUS_SUCCESS != status) + LAC_LOG_ERROR("KPT is not supported on this instance."); + } + + /* Check if the API has been called in synchronous mode */ + if ((CPA_STATUS_SUCCESS == status) && (NULL == pCb)) + { + /* Call synchronous mode function */ + return LacKptEcdsa_SignRSSyn( + instanceHandle, pOpData, pSignStatus, pR, pS, pKptUnwrapContext); + } + + if (CPA_STATUS_SUCCESS == status) + { + keyLengthInBytes = LacKptEcdsa_GetKeyLength(&(pOpData->privateKey)); + if (LAC_KPT_PKE_INVALID_KEY_SIZE == keyLengthInBytes) + { + LAC_INVALID_PARAM_LOG("Invalid KPT Clear Private Key Size"); + status = CPA_STATUS_INVALID_PARAM; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + functionID = LacKptEcdsa_GetMmpId(pKptUnwrapContext); + if (LAC_PKE_INVALID_FUNC_ID == functionID) + { + LAC_INVALID_PARAM_LOG("Invalid Function ID"); + status = CPA_STATUS_INVALID_PARAM; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + status = + LacKpt_MemPoolAlloc(&pMemPool, pCryptoService->lac_pke_kpt_pool); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Clear output buffers */ + osalMemSet(pR->pData, 0, pR->dataLenInBytes); + osalMemSet(pS->pData, 0, pS->dataLenInBytes); + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_kpt_ecdsa_sign_rs_p256.kpt_wrapped, + &(pOpData->privateKey)); + inArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, + kpt_wrapped)] = + pOpData->privateKey.dataLenInBytes; + /* Input memory to QAT is external allocated */ + internalMemInList[LAC_IDX_OF( + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, kpt_wrapped)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_kpt_ecdsa_sign_rs_p256.e, + &(pOpData->m)); + inArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, + e)] = keyLengthInBytes; + internalMemInList[LAC_IDX_OF( + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, e)] = CPA_FALSE; + + LacKpt_BuildUnwrapCtxMemBuffer(pMemPool, pKptUnwrapContext); + pUnwrapCtxBuf = + (CpaFlatBuffer *)(pMemPool + LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES); + pUnwrapCtxBuf->dataLenInBytes = LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES; + pUnwrapCtxBuf->pData = pMemPool; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_kpt_ecdsa_sign_rs_p256.key_unwrap_context, pUnwrapCtxBuf); + inArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, + key_unwrap_context)] = + LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES; + internalMemInList[LAC_IDX_OF( + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t, + key_unwrap_context)] = CPA_TRUE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(outRS.mmp_kpt_ecdsa_sign_rs_p256.r, pR); + LAC_MEM_SHARED_WRITE_FROM_PTR(outRS.mmp_kpt_ecdsa_sign_rs_p256.s, pS); + /* Output memory to QAT is externally allocated */ + LAC_EC_SET_LIST_PARAMS( + internalMemOutList, LAC_KPT_ECDSA_SIGNRS_NUM_OUT_ARGS, CPA_FALSE); + LAC_EC_SET_LIST_PARAMS(outArgSizeList, + LAC_KPT_ECDSA_SIGNRS_NUM_OUT_ARGS, + keyLengthInBytes); + + /* Populate callback data */ + cbData.pClientCb = pCb; + cbData.pCallbackTag = pCallbackTag; + cbData.pClientOpData = pOpData; + cbData.pOpaqueData = pMemPool; + cbData.pOutputData1 = pR; + cbData.pOutputData2 = pS; + + /* Create and send KPT request to the QAT */ + status = LacPkeKpt_SendSingleRequest(functionID, + inArgSizeList, + outArgSizeList, + &in, + &outRS, + internalMemInList, + internalMemOutList, + LacKptEcdsa_SignRSCallback, + &cbData, + instanceHandle); + + if (CPA_STATUS_SUCCESS != status) + { + /* Free memory pool entry */ + LacKpt_MemPoolFree(pMemPool); + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Increment stats */ + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSRequests, pCryptoService); + } + else + { + /* Increment stats */ + LAC_KPT_ECDSA_STAT_INC(numKptEcdsaSignRSRequestErrors, pCryptoService); + } + + return status; } diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_ec.h b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_ec.h index dfc6f7db..e7bdfdc8 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_ec.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_ec.h @@ -37,6 +37,7 @@ #define LAC_EC_H #include "cpa_cy_ecdsa.h" +#include "lac_pke_qat_comms.h" #define LAC_EC_SIZE_BYTES_MAX LAC_BITS_TO_BYTES(LAC_576_BITS) #define LAC_EC_SIZE_BYTES_MIN LAC_BITS_TO_BYTES(LAC_256_BITS) @@ -252,8 +253,8 @@ CpaStatus LacEc_CheckCurve9QWGF2(const CpaFlatBuffer *pQ, * Check if there is optimised ecdsa SignRS MMP function id for the curve. * * @description - * If the there is optimised ecdsa SignRS MMP function for the curve it - * sends a request to firmware with optimised function ID. + * Check if there is SignRS MMP optimized function for the curve and sends + * a request to firmware with optimized function ID. * * @param[in] instanceHandle Instance handle. * @param[in] pCb Callback function pointer. If this is set to a @@ -267,6 +268,12 @@ CpaStatus LacEc_CheckCurve9QWGF2(const CpaFlatBuffer *pQ, * it is returned in the callback. * @param[out] pR ECDSA message signature r. * @param[out] pS ECDSA message signature s. + * @param[in] pDpa Data structure holding the data buffer filled + * with cryptographically safe random data, DPA + * enable boolean and control to create the random + * data internally. + * Creation of random data internally is not + * currently supported. * * @retval CPA_STATUS_SUCCESS Function executed successfully. * @retval CPA_STATUS_FAIL Function failed. @@ -275,7 +282,7 @@ CpaStatus LacEc_CheckCurve9QWGF2(const CpaFlatBuffer *pQ, * @retval CPA_STATUS_RESOURCE Error related to system resources. * @retval CPA_STATUS_RESTARTING API implementation is restarting. Resubmit * the request. - * @retval CPA_STATUS_UNSUPPORTED Optimised EcdsaSignRS is not supported for + * @retval CPA_STATUS_UNSUPPORTED Optimised EcdsaSignRS is not supported by * the platform or the curve. * *****************************************************************************/ @@ -285,6 +292,7 @@ CpaStatus LacEcdsa_OptimisedSignRS(const CpaInstanceHandle instanceHandle, void *pCallbackTag, const CpaCyEcdsaSignRSOpData *pOpData, CpaFlatBuffer *pR, - CpaFlatBuffer *pS); + CpaFlatBuffer *pS, + const lac_pke_dpa_op_data_t *pDpa); #endif /* LAC_EC_H */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_qat_comms.h b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_qat_comms.h index 049fd7de..3840885c 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_qat_comms.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_qat_comms.h @@ -157,6 +157,23 @@ typedef struct lac_pke_op_cb_data_s #endif } lac_pke_op_cb_data_t; +/** + ***************************************************************************** + * @ingroup LacAsymCommonQatComms + * + * @description + * Contains the internal data associated with DPA + * + *****************************************************************************/ +typedef struct lac_pke_dpa_op_data_s +{ + const CpaFlatBuffer *pRandom; + /**< input random data pointer */ + CpaBoolean createRandomData; + /**< true: FW creates the random data */ + CpaBoolean dpa; +} lac_pke_dpa_op_data_t; + /** ***************************************************************************** * @ingroup LacAsymCommonQatComms @@ -489,4 +506,66 @@ CpaStatus LacPke_SendSingleRequest(Cpa32U functionalityId, lac_pke_op_cb_data_t *pCbData, CpaInstanceHandle instanceHandle); +/** + ******************************************************************************* + * @ingroup LacAsymCommonQatComms + * Sends a single (unchained) KPT PKE request to the QAT. + * + * @description + * This function takes the parameters for a KPT service request, it creates + * the request, fills in the KPT service flag and sends it to QAT device. + * It does not block waiting for a response. Instead the callback function + * is invoked from the response when QAT device has processed the request. + * + * @param[in] functionalityId PKE functionality id. + * @param[in] pInArgSizeList Pointer to a list of input sizes required by + * QAT. The client-provided input flat buffers + * greater than or equal to their corresponding + * size will be passed to QAT. Buffers that are + * less than the required size will be copied + * into internal driver buffers before being + * passed to QAT. + * @param[in] pOutArgSizeList Pointer to a list of output sizes required + * by QAT. + * @param[in] pInArgList Pointer to the list of input params. This + * should contain the client-provided flat + * buffer pointers. Any entries in the list + * which are not used must be set to 0. + * @param[in] pOutArgList Pointer to the list of output params. This + * should contain the client-provided flat + * buffer pointers. Any entries in the list + * which are not used must be set to 0. + * @param[in] pInternalInMemList Pointer to a list of Booleans that indicates + * if input data buffers passed to QAT are + * internally or externally allocated. + * This information needs to be tracked to + * ensure we use the correct virt2phys function. + * @param[in] pInternalInMemList Pointer to a list of Booleans that indicates + * if output data buffers passed to QAT are + * internally or externally allocated. + * @param[in] pPkeOpCbFunc Callback function invoked when the response + * is received from the QAT + * @param[in] pCbData Callback data to be returned (by copy) + * unchanged in the callback. + * @param[in] instanceHandle Instance handle + * + * @retval CPA_STATUS_SUCCESS No error + * @retval CPA_STATUS_RESOURCE Resource error (e.g. failed memory + * allocation) + * @retval CPA_STATUS_RETRY Ring full + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter + * @retval CPA_STATUS_FAIL Failed to send the request + * + ******************************************************************************/ +CpaStatus LacPkeKpt_SendSingleRequest( + Cpa32U functionalityId, + Cpa32U *pInArgSizeList, + Cpa32U *pOutArgSizeList, + icp_qat_fw_mmp_input_param_t *pInArgList, + icp_qat_fw_mmp_output_param_t *pOutArgList, + CpaBoolean *pInternalInMemList, + CpaBoolean *pInternalOutMemList, + lac_pke_op_cb_func_t pPkeOpCbFunc, + lac_pke_op_cb_data_t *pCbData, + CpaInstanceHandle instanceHandle); #endif /* _LAC_PKE_QAT_COMMS_H_ */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_utils.h b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_utils.h index 09ec8e2a..0615833b 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_utils.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/include/lac_pke_utils.h @@ -80,6 +80,8 @@ #define LAC_QAT_ASYM_REQ_SZ_LW 16 /**< @ingroup LacAsymCommon * LAC PKE QAT Request message size) */ +#define LAC_QAT_ASYM_REQ_SZ_IN_BYTES \ + (LAC_QAT_ASYM_REQ_SZ_LW * LAC_LONG_WORD_IN_BYTES) #define LAC_QAT_ASYM_RESP_SZ_LW 8 /**< @ingroup LacAsymCommon diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/large_number/lac_ln.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/large_number/lac_ln.c index 5dfa839d..8a696032 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/large_number/lac_ln.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/large_number/lac_ln.c @@ -43,7 +43,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_qat_comms.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_qat_comms.c index e0599f1a..48d3384e 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_qat_comms.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_qat_comms.c @@ -35,7 +35,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* QAT includes */ #include "icp_qat_fw_la.h" @@ -52,6 +51,7 @@ #include "lac_pke_qat_comms.h" #include "lac_pke_utils.h" #include "lac_pke_mmp.h" +#include "lac_kpt_pro_qat_comms.h" #include "sal_misc_error_stats.h" /* @@ -409,6 +409,12 @@ void LacPke_MsgCallback(void *pRespMsg) "The PCIe End Point Push/Pull or TI/RI Parity error detected."); } + if (LAC_KPT_PRO_SERVICE_TYPE == pPkeRespMsg->pke_resp_hdr.response_type) + { + LacKpt_Pro_RspHandler(pRespMsg); + return; + } + /* extract request data pointer from the opaque data */ LAC_MEM_SHARED_READ_TO_PTR(pPkeRespMsg->opaque_data, pReqData); @@ -784,6 +790,8 @@ CpaStatus LacPke_SendRequest(lac_pke_request_handle_t *pRequestHandle, Cpa64U seq_num = ICP_ADF_INVALID_SEND_SEQ; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)instanceHandle; + Cpa32U size = 0; + void *pMsg = NULL; LAC_ASSERT_NOT_NULL(pRequestHandle); @@ -791,10 +799,14 @@ CpaStatus LacPke_SendRequest(lac_pke_request_handle_t *pRequestHandle, pHeadReqData = *pRequestHandle; LAC_ASSERT_NOT_NULL(pHeadReqData); + { + pMsg = (void *)&(pHeadReqData->u1.request); + size = LAC_QAT_ASYM_REQ_SZ_LW; + } /* send the request (chain) */ status = SalQatMsg_transPutMsg(pCryptoService->trans_handle_asym_tx, - (void *)&(pHeadReqData->u1.request), - LAC_QAT_ASYM_REQ_SZ_LW, + pMsg, + size, LAC_LOG_MSG_PKE, &seq_num); @@ -851,3 +863,144 @@ CpaStatus LacPke_SendSingleRequest(Cpa32U functionalityId, return status; } +/** + ******************************************************************************* + * @ingroup LacAsymCommonQatComms + * Creates a single (unchained) KPT service request for the QAT. + * + * @description + * This function invokes LacPke_CreateRequest first to create a normal + * PKE request, then sets the KPT service flag in serv_specif_flags field + * of PKE request header. + * The request can subsequently be sent to the QAT device using + * LacPke_SendSingleRequest(). In the event of an error this function will + * tidy up any resources associated with the request handle and set it to + * PKE_INVALID_HANDLE. + * + * @pre + * The requests in the request pool have been initialised using + * Lac_MemPoolInitAsymRequest(). + * + * @param[in,out] pRequestHandle Pointer to hold the handle for the request + * created by this call. For a single request, + * the passed in handle value must be zero. + * (i.e. LAC_PKE_INVALID_HANDLE). + * + * @param[in] functionalityId KPT PKE service functionality id. + * @param[in] pInArgSizeList Pointer to a list of input sizes required + * by QAT. The client-provided input flat + * buffers greater than or equal to their + * corresponding size will be passed to QAT. + * Buffers that are less than the required + * size will be copied into internal driver + * buffers before being passed to QAT. + * @param[in] pOutArgSizeList Pointer to a list of output sizes required + * by QAT. + * @param[in] pInArgList Pointer to the list of input params. This + * should contain the client-provided flat + * buffer pointers. Any entries in the list + * which are not used must be set to 0. + * @param[in] pOutArgList Pointer to the list of output params. This + * should contain the client-provided flat + * buffer pointers. Any entries in the list + * which are not used must be set to 0. + * @param[in] pInternalInMemList Pointer to a list of Booleans that + * indicates if input data buffers passed to + * QAT are internally or externally allocated. + * This information needs to be tracked to + * ensure we use the correct virt2phys + * function. + * @param[in] pInternalInMemList Pointer to a list of Booleans that indicates + * if output data buffers passed to QAT are + * internally or externally allocated. + * @param[in] pPkeOpCbFunc Callback function invoked when the response + * is received from the QAT + * @param[in] pCbData Callback data to be returned (by copy) + * unchanged in the callback. + * @param[in] instanceHandle Instance handle + * + * @retval CPA_STATUS_SUCCESS No error + * @retval CPA_STATUS_RESOURCE Resource error (e.g. failed memory + * allocation) + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter + * + ******************************************************************************/ +STATIC +CpaStatus LacPkeKpt_CreateSingleRequest( + lac_pke_request_handle_t *pRequestHandle, + Cpa32U functionalityId, + Cpa32U *pInArgSizeList, + Cpa32U *pOutArgSizeList, + icp_qat_fw_mmp_input_param_t *pInArgList, + icp_qat_fw_mmp_output_param_t *pOutArgList, + CpaBoolean *pInternalInMemList, + CpaBoolean *pInternalOutMemList, + lac_pke_op_cb_func_t pPkeOpCbFunc, + lac_pke_op_cb_data_t *pCbData, + CpaInstanceHandle instanceHandle) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + status = LacPke_CreateRequest(pRequestHandle, + functionalityId, + pInArgSizeList, + pOutArgSizeList, + pInArgList, + pOutArgList, + pInternalInMemList, + pInternalOutMemList, + pPkeOpCbFunc, + pCbData, + instanceHandle); + + if (CPA_STATUS_SUCCESS == status) + { + lac_pke_qat_req_data_t *pReqData = *pRequestHandle; + SalQatMsg_KptFlagHdrWrite( + &(pReqData->u1.request.pke_hdr.extended_serv_specif_flags)); + } + + return status; +} + +/** + *************************************************************************** + * @ingroup LacAsymCommonQatComms + * KPT PKE request create and send to QAT + ***************************************************************************/ +CpaStatus LacPkeKpt_SendSingleRequest( + Cpa32U functionalityId, + Cpa32U *pInArgSizeList, + Cpa32U *pOutArgSizeList, + icp_qat_fw_mmp_input_param_t *pInArgList, + icp_qat_fw_mmp_output_param_t *pOutArgList, + CpaBoolean *pInMemBool, + CpaBoolean *pOutMemBool, + lac_pke_op_cb_func_t pPkeOpCbFunc, + lac_pke_op_cb_data_t *pCbData, + CpaInstanceHandle instanceHandle) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + lac_pke_request_handle_t requestHandle = LAC_PKE_INVALID_HANDLE; + + /* prepare the request */ + status = LacPkeKpt_CreateSingleRequest(&requestHandle, + functionalityId, + pInArgSizeList, + pOutArgSizeList, + pInArgList, + pOutArgList, + pInMemBool, + pOutMemBool, + pPkeOpCbFunc, + pCbData, + instanceHandle); + + if (CPA_STATUS_SUCCESS == status) + { + /* send the request */ + status = LacPke_SendRequest(&requestHandle, instanceHandle); + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_utils.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_utils.c index 8c643971..b163ef90 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_utils.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/pke_common/lac_pke_utils.c @@ -37,7 +37,6 @@ /* ADF includes */ #include "icp_accel_devices.h" #include "icp_adf_init.h" -#include "icp_adf_debug.h" #include "icp_adf_transport.h" #include "icp_adf_poll.h" #include "icp_accel_devices.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/prime/lac_prime.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/prime/lac_prime.c index e7b9c921..073f018a 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/prime/lac_prime.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/prime/lac_prime.c @@ -47,7 +47,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* Include LAC files */ #include "lac_common.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_kpt_rsa_decrypt.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_kpt_rsa_decrypt.c index 9a6f0f62..3305bb65 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_kpt_rsa_decrypt.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_kpt_rsa_decrypt.c @@ -28,6 +28,515 @@ #include "cpa_cy_rsa.h" #include "cpa_cy_kpt.h" +/* +******************************************************************************** +* Include private header files +******************************************************************************** +*/ + +/* Osal includes */ +#include "Osal.h" + +/* FW includes */ +#include "icp_qat_fw_mmp_ids.h" + +/* SAL includes */ +#include "lac_common.h" +#include "lac_pke_qat_comms.h" +#include "lac_pke_utils.h" +#include "lac_pke_mmp.h" +#include "sal_service_state.h" +#include "lac_sal_types_crypto.h" +#include "lac_rsa_stats_p.h" +#include "lac_mem.h" +#include "lac_kpt_crypto_qat_comms.h" +#include "lac_kpt_pro_qat_comms.h" + +/* +******************************************************************************* +* Intel KPT RSA Wrapped Private Key(WPK) type1 has a fix format as: +* (d||n)'||AuthTag. +* The size of WPK is: sizeof(d) + sizeof(n) + sizeof(AuthTag). +* E.g. Size of RSA512 WPK is: 64 + 64 + 16 = 144 +******************************************************************************* +*/ +#define LAC_KPT_RSA_512_DP1_KEY_SIZE_IN_BYTES (144) +#define LAC_KPT_RSA_1024_DP1_KEY_SIZE_IN_BYTES (272) +#define LAC_KPT_RSA_1536_DP1_KEY_SIZE_IN_BYTES (400) +#define LAC_KPT_RSA_2048_DP1_KEY_SIZE_IN_BYTES (528) +#define LAC_KPT_RSA_3072_DP1_KEY_SIZE_IN_BYTES (784) +#define LAC_KPT_RSA_4096_DP1_KEY_SIZE_IN_BYTES (1040) +#define LAC_KPT_RSA_8192_DP1_KEY_SIZE_IN_BYTES (2064) + +/* +******************************************************************************* +* Intel KPT RSA Wrapped Private Key(WPK) type2 has a fix format as: +* (p||q||dp||dq||qinv||e)'||AuthTag. +* The size of WPK is: sizeof(p) * 5 + sizeof(e) + sizeof(AuthTag). +* E.g. Size of RSA512 WPK is: 32 * 5 + 64 + 16 = 240 +******************************************************************************* +*/ +#define LAC_KPT_RSA_512_DP2_KEY_SIZE_IN_BYTES (240) +#define LAC_KPT_RSA_1024_DP2_KEY_SIZE_IN_BYTES (464) +#define LAC_KPT_RSA_1536_DP2_KEY_SIZE_IN_BYTES (688) +#define LAC_KPT_RSA_2048_DP2_KEY_SIZE_IN_BYTES (912) +#define LAC_KPT_RSA_3072_DP2_KEY_SIZE_IN_BYTES (1360) +#define LAC_KPT_RSA_4096_DP2_KEY_SIZE_IN_BYTES (1808) +#define LAC_KPT_RSA_8192_DP2_KEY_SIZE_IN_BYTES (3600) + +/* +******************************************************************************** +* Static Variables +******************************************************************************** +*/ +/**< + * Maps between operation sizes and PKE function ids */ +static const Cpa32U lacKptRsaSizeIdMap[][LAC_PKE_NUM_COLUMNS] = { + { LAC_KPT_RSA_512_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_512 }, + { LAC_KPT_RSA_1024_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_1024 }, + { LAC_KPT_RSA_1536_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_1536 }, + { LAC_KPT_RSA_2048_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_2048 }, + { LAC_KPT_RSA_3072_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_3072 }, + { LAC_KPT_RSA_4096_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_4096 }, + { LAC_KPT_RSA_8192_DP1_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP1_8192 }, + { LAC_KPT_RSA_512_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_512 }, + { LAC_KPT_RSA_1024_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_1024 }, + { LAC_KPT_RSA_1536_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_1536 }, + { LAC_KPT_RSA_2048_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_2048 }, + { LAC_KPT_RSA_3072_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_3072 }, + { LAC_KPT_RSA_4096_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_4096 }, + { LAC_KPT_RSA_8192_DP2_KEY_SIZE_IN_BYTES, PKE_KPT_RSA_DP2_8192 } +}; + +/**< + * Maps between operation sizes and clear private key sizes */ +static const Cpa32U lacKptRsaSizeMap[][LAC_PKE_NUM_COLUMNS] = { + { LAC_KPT_RSA_512_DP1_KEY_SIZE_IN_BYTES, + LAC_512_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_1024_DP1_KEY_SIZE_IN_BYTES, + LAC_1024_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_1536_DP1_KEY_SIZE_IN_BYTES, + LAC_1536_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_2048_DP1_KEY_SIZE_IN_BYTES, + LAC_2048_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_3072_DP1_KEY_SIZE_IN_BYTES, + LAC_3072_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_4096_DP1_KEY_SIZE_IN_BYTES, + LAC_4096_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_8192_DP1_KEY_SIZE_IN_BYTES, + LAC_8192_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_512_DP2_KEY_SIZE_IN_BYTES, + LAC_512_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_1024_DP2_KEY_SIZE_IN_BYTES, + LAC_1024_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_1536_DP2_KEY_SIZE_IN_BYTES, + LAC_1536_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_2048_DP2_KEY_SIZE_IN_BYTES, + LAC_2048_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_3072_DP2_KEY_SIZE_IN_BYTES, + LAC_3072_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_4096_DP2_KEY_SIZE_IN_BYTES, + LAC_4096_BITS / LAC_NUM_BITS_IN_BYTE }, + { LAC_KPT_RSA_8192_DP2_KEY_SIZE_IN_BYTES, + LAC_8192_BITS / LAC_NUM_BITS_IN_BYTE } +}; + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * Get the size of RSA Wrapped Private Key (WPK). + * + *****************************************************************************/ +STATIC +Cpa32U LacKptRsa_GetPrivateKeyOpSize(const CpaCyKptRsaPrivateKey *pPrivateKey) +{ + LAC_ASSERT_NOT_NULL(pPrivateKey); + + switch (pPrivateKey->privateKeyRepType) + { + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1: + return pPrivateKey->privateKeyRep1.privateKey.dataLenInBytes; + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_2: + return pPrivateKey->privateKeyRep2.privateKey.dataLenInBytes; + default: + { + LAC_LOG_ERROR("Invalid Private Key Type."); + return LAC_KPT_PKE_INVALID_KEY_SIZE; + } + } +} + +#ifdef ICP_PARAM_CHECK +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * Check KPT RSA Wrapped Private Key (WPK) parameters. + * + *****************************************************************************/ +STATIC +CpaStatus LacKptRsa_CheckPrivateKeyParam(CpaCyKptRsaPrivateKey *pPrivateKey) +{ + LAC_CHECK_NULL_PARAM(pPrivateKey); + + if (CPA_CY_RSA_VERSION_TWO_PRIME != pPrivateKey->version) + { + LAC_INVALID_PARAM_LOG("Invalid pPrivateKey->version"); + return CPA_STATUS_INVALID_PARAM; + } + + switch (pPrivateKey->privateKeyRepType) + { + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1: + { + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pPrivateKey->privateKeyRep1.privateKey), CHECK_NONE, 0); + } + break; + + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_2: + { + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pPrivateKey->privateKeyRep2.privateKey), CHECK_NONE, 0); + } + break; + + default: + { + LAC_INVALID_PARAM_LOG("Invalid pPrivateKey->privateKeyRepType"); + return CPA_STATUS_INVALID_PARAM; + } + } + + return CPA_STATUS_SUCCESS; +} + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * Check KPT RSA decryption parameters. + * + *****************************************************************************/ +STATIC +CpaStatus LacKptRsa_DecryptParamsCheck( + const CpaCyKptRsaDecryptOpData *pDecryptOpData, + CpaFlatBuffer *pOutputData, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U wpkSizeInBytes = 0; + Cpa32U cpkSizeInBytes = 0; + + /* Check user parameters */ + LAC_CHECK_NULL_PARAM(pDecryptOpData); + LAC_CHECK_NULL_PARAM(pKptUnwrapContext); + + /* Check the WPK is of correct version, type and NULL params */ + status = + LacKptRsa_CheckPrivateKeyParam(pDecryptOpData->pRecipientPrivateKey); + LAC_CHECK_STATUS(status); + + /* Get the WPK size */ + wpkSizeInBytes = + LacKptRsa_GetPrivateKeyOpSize(pDecryptOpData->pRecipientPrivateKey); + + /* Get the size of Clear Private Key (CPK) */ + cpkSizeInBytes = LacKpt_GetCpkSize( + wpkSizeInBytes, lacKptRsaSizeMap, LAC_ARRAY_LEN(lacKptRsaSizeMap)); + if (LAC_KPT_PKE_INVALID_KEY_SIZE == cpkSizeInBytes) + { + LAC_INVALID_PARAM_LOG("Invalid Private Key Size - " + "pDecryptOpData->pRecipientPrivateKey"); + return CPA_STATUS_INVALID_PARAM; + } + + /* Check message and ciphertext buffers */ + LAC_CHECK_FLAT_BUFFER_PARAM_PKE(&(pDecryptOpData->inputData), + CHECK_LESS_EQUALS, + cpkSizeInBytes, + CPA_FALSE); + + /* Standards based check: inputData > 0 */ + if (CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1 == + pDecryptOpData->pRecipientPrivateKey->privateKeyRepType) + LAC_CHECK_NON_ZERO_PARAM(&(pDecryptOpData->inputData)); + + LAC_CHECK_FLAT_BUFFER_PARAM( + pOutputData, CHECK_GREATER_EQUALS, cpkSizeInBytes); + + return status; +} +#endif + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * Get RSA Wrapped Private Key(WPK) flat buffer. + * + *****************************************************************************/ +STATIC +CpaFlatBuffer *getWpkFlatBuf(CpaCyKptRsaPrivateKey *pPrivateKey) +{ + switch (pPrivateKey->privateKeyRepType) + { + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1: + return &(pPrivateKey->privateKeyRep1.privateKey); + case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_2: + return &(pPrivateKey->privateKeyRep2.privateKey); + default: + { + LAC_LOG_ERROR("Invalid private key type."); + return NULL; + } + } +} + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * KPT RSA decryption internal callback. + * + *****************************************************************************/ +STATIC +void LacKptRsa_ProcessDecCb(CpaStatus status, + CpaBoolean pass, + CpaInstanceHandle instanceHandle, + lac_pke_op_cb_data_t *pCbData) +{ + CpaCyGenFlatBufCbFunc pCb = NULL; + void *pCallbackTag = NULL; + CpaCyKptRsaDecryptOpData *pOpData = NULL; + CpaFlatBuffer *pOutputData = NULL; + Cpa8U *pMemPool = NULL; + + /* Extract info from callback data structure */ + LAC_ASSERT_NOT_NULL(pCbData); + pCallbackTag = (void *)pCbData->pCallbackTag; + + pOpData = + (CpaCyKptRsaDecryptOpData *)LAC_CONST_PTR_CAST(pCbData->pClientOpData); + LAC_ASSERT_NOT_NULL(pOpData); + + pCb = (CpaCyGenFlatBufCbFunc)LAC_CONST_PTR_CAST(pCbData->pClientCb); + LAC_ASSERT_NOT_NULL(pCb); + + pOutputData = pCbData->pOutputData1; + LAC_ASSERT_NOT_NULL(pOutputData); + + pMemPool = (Cpa8U *)(pCbData->pOpaqueData); + /* Free memory pool entry */ + if (pMemPool) + LacKpt_MemPoolFree(pMemPool); + + /* Increment stats */ + LAC_RSA_STAT_INC(numKptRsaDecryptCompleted, instanceHandle); + if ((CPA_STATUS_SUCCESS != status) || (CPA_FALSE == pass)) + { + LAC_RSA_STAT_INC(numKptRsaDecryptCompletedErrors, instanceHandle); + } + + if ((CPA_FALSE == pass) && ((CPA_STATUS_SUCCESS) == status)) + { + status = CPA_STATUS_FAIL; + } + + /* Invoke the user callback */ + pCb(pCallbackTag, status, pOpData, pOutputData); +} + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * KPT RSA decryption synchronous function. + * + *****************************************************************************/ +STATIC +CpaStatus LacKptRsa_DecryptSync(const CpaInstanceHandle instanceHandle, + const CpaCyKptRsaDecryptOpData *pDecryptOpData, + CpaFlatBuffer *pOutputData, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + CpaStatus status = CPA_STATUS_FAIL; + lac_sync_op_data_t *pSyncCallbackData = NULL; + CpaStatus wCbStatus = CPA_STATUS_FAIL; + status = LacSync_CreateSyncCookie(&pSyncCallbackData); + /* + * Call the async version of the function + * with the sync callback function as a parameter. + */ + if (CPA_STATUS_SUCCESS == status) + { + status = cpaCyKptRsaDecrypt(instanceHandle, + LacSync_GenFlatBufCb, + pSyncCallbackData, + pDecryptOpData, + pOutputData, + pKptUnwrapContext); + } + else + { + LAC_RSA_STAT_INC(numKptRsaDecryptRequestErrors, instanceHandle); + return status; + } + if (CPA_STATUS_SUCCESS == status) + { + wCbStatus = LacSync_WaitForCallback( + pSyncCallbackData, LAC_PKE_SYNC_CALLBACK_TIMEOUT, &status, NULL); + if (CPA_STATUS_SUCCESS != wCbStatus) + { + /* + * Increment stats only if the wait for callback failed. + */ + LAC_RSA_STAT_INC(numKptRsaDecryptCompletedErrors, instanceHandle); + LacSync_SetSyncCookieComplete(pSyncCallbackData); + status = wCbStatus; + } + } + else + { + /* As the request was not sent the callback will never + * be called, so need to indicate that we are finished + * with cookie so that it can be destroyed. */ + LacSync_SetSyncCookieComplete(pSyncCallbackData); + } + LacSync_DestroySyncCookie(&pSyncCallbackData); + return status; +} + +/** + ***************************************************************************** + * @ingroup Lac_KptRsa + * Internal KPT RSA decryption function. + * + *****************************************************************************/ +STATIC +CpaStatus LacKptRsa_Decrypt(const CpaInstanceHandle instanceHandle, + const CpaCyGenFlatBufCbFunc pRsaDecryptCb, + void *pCallbackTag, + const CpaCyKptRsaDecryptOpData *pDecryptOpData, + CpaFlatBuffer *pOutputData, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + Cpa32U wpkSizeInBytes = 0; + Cpa32U cpkSizeInBytes = 0; + Cpa32U functionalityId = LAC_PKE_INVALID_FUNC_ID; + Cpa32U pInArgSizeList[LAC_MAX_MMP_INPUT_PARAMS] = { 0 }; + Cpa32U pOutArgSizeList[LAC_MAX_MMP_OUTPUT_PARAMS] = { 0 }; + CpaBoolean internalMemInList[LAC_MAX_MMP_INPUT_PARAMS] = { CPA_FALSE }; + CpaBoolean internalMemOutList[LAC_MAX_MMP_OUTPUT_PARAMS] = { CPA_FALSE }; + CpaStatus status = CPA_STATUS_SUCCESS; + lac_pke_op_cb_data_t cbData = { 0 }; + icp_qat_fw_mmp_input_param_t in = { .flat_array = { 0 } }; + icp_qat_fw_mmp_output_param_t out = { .flat_array = { 0 } }; + CpaFlatBuffer *pUnwrapCtxBuf = NULL; + CpaFlatBuffer *pWpkBuf = NULL; + Cpa8U *pMemPool = NULL; + sal_crypto_service_t *pCryptoService = NULL; + + LAC_ASSERT_NOT_NULL(pDecryptOpData); + LAC_ASSERT_NOT_NULL(pOutputData); + LAC_ASSERT_NOT_NULL(pKptUnwrapContext); + + pWpkBuf = getWpkFlatBuf(pDecryptOpData->pRecipientPrivateKey); + if (NULL == pWpkBuf) + { + LAC_INVALID_PARAM_LOG("Invalid KPT Private Key Buffer - " + "pDecryptOpData->pRecipientPrivateKey"); + return CPA_STATUS_INVALID_PARAM; + } + + wpkSizeInBytes = + LacKptRsa_GetPrivateKeyOpSize(pDecryptOpData->pRecipientPrivateKey); + if (LAC_KPT_PKE_INVALID_KEY_SIZE == wpkSizeInBytes) + { + LAC_INVALID_PARAM_LOG("Invalid KPT Wrapped Private Key Size - " + "pDecryptOpData->pRecipientPrivateKey"); + return CPA_STATUS_INVALID_PARAM; + } + + functionalityId = LacPke_GetMmpId( + wpkSizeInBytes, lacKptRsaSizeIdMap, LAC_ARRAY_LEN(lacKptRsaSizeIdMap)); + if (LAC_PKE_INVALID_FUNC_ID == functionalityId) + { + LAC_INVALID_PARAM_LOG("Invalid KPT Private Key Size - " + "pDecryptOpData->pRecipientPrivateKey"); + return CPA_STATUS_INVALID_PARAM; + } + + cpkSizeInBytes = LacKpt_GetCpkSize( + wpkSizeInBytes, lacKptRsaSizeMap, LAC_ARRAY_LEN(lacKptRsaSizeMap)); + if (LAC_KPT_PKE_INVALID_KEY_SIZE == cpkSizeInBytes) + { + LAC_INVALID_PARAM_LOG("Invalid KPT Clear Private Key Size"); + return CPA_STATUS_INVALID_PARAM; + } + + pCryptoService = (sal_crypto_service_t *)instanceHandle; + status = LacKpt_MemPoolAlloc(&pMemPool, pCryptoService->lac_pke_kpt_pool); + if (CPA_STATUS_SUCCESS == status) + { + /* Zero MSB bytes of output buffer */ + osalMemSet(pOutputData->pData, + 0, + (pOutputData->dataLenInBytes - cpkSizeInBytes)); + + /* Populate input parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_kpt_rsa_dp1_512.c, + &(pDecryptOpData->inputData)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t, c)] = + cpkSizeInBytes; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_kpt_rsa_dp1_512.kpt_wrapped, + pWpkBuf); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t, + kpt_wrapped)] = wpkSizeInBytes; + + LacKpt_BuildUnwrapCtxMemBuffer(pMemPool, pKptUnwrapContext); + + pUnwrapCtxBuf = + (CpaFlatBuffer *)(pMemPool + LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES); + pUnwrapCtxBuf->dataLenInBytes = LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES; + pUnwrapCtxBuf->pData = pMemPool; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_kpt_rsa_dp1_512.kpt_unwrap_context, + pUnwrapCtxBuf); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t, + kpt_unwrap_context)] = + LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t, + kpt_unwrap_context)] = CPA_TRUE; + + /* Populate output parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_kpt_rsa_dp1_512.m, pOutputData); + pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_kpt_rsa_dp1_512_output_t, + m)] = cpkSizeInBytes; + + /* Populate callback data */ + cbData.pClientCb = pRsaDecryptCb; + cbData.pCallbackTag = pCallbackTag; + cbData.pClientOpData = pDecryptOpData; + cbData.pOutputData1 = pOutputData; + cbData.pOpaqueData = pMemPool; + + /* Send a PKE KPT request to the QAT */ + status = LacPkeKpt_SendSingleRequest(functionalityId, + pInArgSizeList, + pOutArgSizeList, + &in, + &out, + internalMemInList, + internalMemOutList, + LacKptRsa_ProcessDecCb, + &cbData, + instanceHandle); + } + if (CPA_STATUS_SUCCESS != status) + { + /* Free memory pool entry */ + LacKpt_MemPoolFree(pMemPool); + } + return status; +} + /** ***************************************************************************** * @ingroup Lac_KptRsa @@ -42,5 +551,59 @@ CpaStatus cpaCyKptRsaDecrypt(const CpaInstanceHandle instanceHandle, CpaCyKptUnwrapContext *pKptUnwrapContext) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_TRACE + LAC_LOG6("Called with params (0x%lx, 0x%lx, 0x%lx, 0x%lx, " + "0x%lx, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pRsaDecryptCb, + (LAC_ARCH_UINT)pCallbackTag, + (LAC_ARCH_UINT)pDecryptOpData, + (LAC_ARCH_UINT)pOutputData, + (LAC_ARCH_UINT)pKptUnwrapContext); +#endif +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); +#endif + SAL_RUNNING_CHECK(instanceHandle); +#ifdef ICP_PARAM_CHECK + /* Check RSA Decrypt params and return an error if invalid */ + status = LacKptRsa_DecryptParamsCheck( + pDecryptOpData, pOutputData, pKptUnwrapContext); +#endif + if (CPA_STATUS_SUCCESS == status) + { + /* Check if KPT is enabled on the service instance */ + SAL_GET_INSTANCE_CRYPTO_CAPABILITY_STATUS(status, instanceHandle, kpt); + if (CPA_STATUS_SUCCESS != status) + LAC_LOG_ERROR("KPT is not supported on this instance."); + } + /* Check if the API has been called in sync mode */ + if ((CPA_STATUS_SUCCESS == status) && (NULL == pRsaDecryptCb)) + { + return LacKptRsa_DecryptSync( + instanceHandle, pDecryptOpData, pOutputData, pKptUnwrapContext); + } + if (CPA_STATUS_SUCCESS == status) + { + status = LacKptRsa_Decrypt(instanceHandle, + pRsaDecryptCb, + pCallbackTag, + pDecryptOpData, + pOutputData, + pKptUnwrapContext); + } + + /* Increment stats */ + if (CPA_STATUS_SUCCESS == status) + { + LAC_RSA_STAT_INC(numKptRsaDecryptRequests, instanceHandle); + } + else + { + LAC_RSA_STAT_INC(numKptRsaDecryptRequestErrors, instanceHandle); + } + + return status; } diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa.c index a9508c45..0263ca7d 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa.c @@ -218,7 +218,10 @@ CpaStatus LacRsa_Type2StdsCheck(CpaCyRsaPrivateKeyRep2 *pPrivateKeyRep2) return CPA_STATUS_SUCCESS; } -CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey) +CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey, + const CpaFlatBuffer *pRsaPrimeP, + const CpaFlatBuffer *pRsaPrimeQ, + CpaBoolean dpaEnabled) { LAC_CHECK_NULL_PARAM(pPrivateKey); @@ -234,8 +237,16 @@ CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey) { LAC_CHECK_FLAT_BUFFER_PARAM( &(pPrivateKey->privateKeyRep1.privateExponentD), CHECK_NONE, 0); - LAC_CHECK_FLAT_BUFFER_PARAM( - &(pPrivateKey->privateKeyRep1.modulusN), CHECK_NONE, 0); + if (dpaEnabled) + { + LAC_CHECK_FLAT_BUFFER_PARAM(pRsaPrimeP, CHECK_NONE, 0); + LAC_CHECK_FLAT_BUFFER_PARAM(pRsaPrimeQ, CHECK_NONE, 0); + } + else + { + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pPrivateKey->privateKeyRep1.modulusN), CHECK_NONE, 0); + } } break; @@ -265,7 +276,10 @@ CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey) return CPA_STATUS_SUCCESS; } -Cpa32U LacRsa_GetPrivateKeyOpSize(const CpaCyRsaPrivateKey *pPrivateKey) +Cpa32U LacRsa_GetPrivateKeyOpSize(const CpaCyRsaPrivateKey *pPrivateKey, + const CpaFlatBuffer *pRsaPrimeP, + const CpaFlatBuffer *pRsaPrimeQ, + CpaBoolean dpaEnabled) { Cpa32U sizeInBytes = 0; LAC_ASSERT_NOT_NULL(pPrivateKey); @@ -274,8 +288,25 @@ Cpa32U LacRsa_GetPrivateKeyOpSize(const CpaCyRsaPrivateKey *pPrivateKey) { case CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1: { - sizeInBytes += - LacPke_GetMinBytes(&(pPrivateKey->privateKeyRep1.modulusN)); + if (dpaEnabled) + { + sizeInBytes = LacPke_GetMinBytes(pRsaPrimeP); + if (sizeInBytes != LacPke_GetMinBytes(pRsaPrimeQ)) + { + LAC_LOG_ERROR("pRsaPrimeP.dataLenInBytes != " + "pRsaPrimeQ.dataLenInBytes"); + sizeInBytes = 0; + } + else + { + sizeInBytes = sizeInBytes << 1; + } + } + else + { + sizeInBytes += + LacPke_GetMinBytes(&(pPrivateKey->privateKeyRep1.modulusN)); + } } break; diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_control_path.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_control_path.c index 0f2dec2f..9fc98e26 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_control_path.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_control_path.c @@ -40,7 +40,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_decrypt.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_decrypt.c index c4ae4fbd..7c776a66 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_decrypt.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_decrypt.c @@ -40,7 +40,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" @@ -58,6 +57,9 @@ #include "lac_rsa_p.h" #include "lac_rsa_stats_p.h" +#define RSA_PRIME(dpaEnabled, rsaPrime) (dpaEnabled) ? (rsaPrime) : NULL +#define LAC_DPA_RSA_RANDOM_BITS (4608) + /* ******************************************************************************** * Static Variables @@ -102,6 +104,8 @@ STATIC CpaStatus LacRsa_DecryptParamsCheck(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData); #endif @@ -121,6 +125,8 @@ STATIC CpaStatus LacRsa_Type1Decrypt(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, void *pCallbackTag, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData); /* @@ -130,6 +136,8 @@ STATIC CpaStatus LacRsa_Type2Decrypt(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, void *pCallbackTag, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData); /* @@ -137,12 +145,16 @@ STATIC CpaStatus LacRsa_Type2Decrypt(const CpaInstanceHandle instanceHandle, */ STATIC CpaStatus LacRsa_DecryptSynch(const CpaInstanceHandle instanceHandle, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData); STATIC CpaStatus LacRsa_Decrypt(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, void *pCallbackTag, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -164,6 +176,8 @@ STATIC CpaStatus LacRsa_Decrypt(const CpaInstanceHandle instanceHandle, { return LacRsa_DecryptSynch(instanceHandle, pDecryptData, + pDpaDecryptData, + dpaEnabled, pOutputData); } #ifdef ICP_PARAM_CHECK @@ -171,6 +185,8 @@ STATIC CpaStatus LacRsa_Decrypt(const CpaInstanceHandle instanceHandle, status = LacRsa_DecryptParamsCheck(instanceHandle, pRsaDecryptCb, pDecryptData, + pDpaDecryptData, + dpaEnabled, pOutputData); #endif if (CPA_STATUS_SUCCESS == status) @@ -182,6 +198,8 @@ STATIC CpaStatus LacRsa_Decrypt(const CpaInstanceHandle instanceHandle, pRsaDecryptCb, pCallbackTag, pDecryptData, + pDpaDecryptData, + dpaEnabled, pOutputData); } else /* Must be type2 key as param check has passed */ @@ -190,6 +208,8 @@ STATIC CpaStatus LacRsa_Decrypt(const CpaInstanceHandle instanceHandle, pRsaDecryptCb, pCallbackTag, pDecryptData, + pDpaDecryptData, + dpaEnabled, pOutputData); } } @@ -245,6 +265,8 @@ CpaStatus cpaCyRsaDecrypt(const CpaInstanceHandle instanceHandle_in, pRsaDecryptCb, pCallbackTag, pDecryptData, + NULL, + CPA_FALSE, pOutputData); return status; @@ -257,11 +279,63 @@ CpaStatus cpaCyRsaDpaDecrypt(const CpaInstanceHandle instanceHandle_in, const CpaCyRsaDpaOpData *pDpaOpData, CpaFlatBuffer *pOutputData) { - return CPA_STATUS_UNSUPPORTED; + sal_crypto_service_t *pCryptoService = NULL; + CpaInstanceHandle instanceHandle = NULL; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_TRACE + LAC_LOG6("Called with params (0x%lx, 0x%lx, 0x%lx, 0x%lx, " + "0x%lx, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle_in, + (LAC_ARCH_UINT)pRsaDecryptCb, + (LAC_ARCH_UINT)pCallbackTag, + (LAC_ARCH_UINT)pDecryptData, + (LAC_ARCH_UINT)pDpaOpData, + (LAC_ARCH_UINT)pOutputData); +#endif +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(pDpaOpData); +#endif + if (pDpaOpData->createRandomData) + { + LAC_LOG_ERROR("Creating random data for DPA is not supported"); + return CPA_STATUS_UNSUPPORTED; + } + LAC_CHECK_NULL_PARAM(pDpaOpData->pRandom); + + if (CPA_INSTANCE_HANDLE_SINGLE == instanceHandle_in) + { + instanceHandle = Lac_GetFirstHandle(SAL_SERVICE_TYPE_CRYPTO_ASYM); + } + else + { + instanceHandle = instanceHandle_in; + } +#ifdef ICP_PARAM_CHECK + LAC_CHECK_INSTANCE_HANDLE(instanceHandle); +#endif + pCryptoService = (sal_crypto_service_t *)instanceHandle; + if (!pCryptoService->generic_service_info.dpaSupport) + { + LAC_LOG_ERROR1("%s: DPA not supported on this device\n", __func__); + return CPA_STATUS_UNSUPPORTED; + } + + status = LacRsa_Decrypt(instanceHandle, + pRsaDecryptCb, + pCallbackTag, + pDecryptData, + pDpaOpData, + CPA_TRUE, + pOutputData); + + return status; } STATIC CpaStatus LacRsa_DecryptSynch(const CpaInstanceHandle instanceHandle, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData) { CpaStatus status = CPA_STATUS_FAIL; @@ -278,6 +352,8 @@ STATIC CpaStatus LacRsa_DecryptSynch(const CpaInstanceHandle instanceHandle, LacSync_GenFlatBufCb, pSyncCallbackData, pDecryptData, + pDpaDecryptData, + dpaEnabled, pOutputData); } else @@ -316,6 +392,8 @@ STATIC CpaStatus LacRsa_DecryptParamsCheck(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -327,12 +405,19 @@ LacRsa_DecryptParamsCheck(const CpaInstanceHandle instanceHandle, LAC_CHECK_NULL_PARAM(pDecryptData); /* Check the Private Key is correct version, type and for NULL params */ status = - LacRsa_CheckPrivateKeyParam(pDecryptData->pRecipientPrivateKey); + LacRsa_CheckPrivateKeyParam( + pDecryptData->pRecipientPrivateKey, + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeP), + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeQ), + dpaEnabled); LAC_CHECK_STATUS(status); /* Get the opSize */ - opSizeInBytes = - LacRsa_GetPrivateKeyOpSize(pDecryptData->pRecipientPrivateKey); + opSizeInBytes = LacRsa_GetPrivateKeyOpSize( + pDecryptData->pRecipientPrivateKey, + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeP), + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeQ), + dpaEnabled); if (CPA_FALSE == LacRsa_IsValidRsaSize(opSizeInBytes)) { LAC_INVALID_PARAM_LOG( @@ -350,23 +435,33 @@ LacRsa_DecryptParamsCheck(const CpaInstanceHandle instanceHandle, if (CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_1 == pDecryptData->pRecipientPrivateKey->privateKeyRepType) { - /* Check MSB and LSB of the modulus */ - LAC_CHECK_RSA_BUFFER_MSB_LSB( - &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.modulusN), - opSizeInBytes, - CPA_TRUE, - CPA_TRUE); - - /* Standards based check: 0 < inputData < n */ - LAC_CHECK_NON_ZERO_PARAM(&(pDecryptData->inputData)); - if (LacPke_Compare( - &(pDecryptData->inputData), - 0, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.modulusN), - 0) >= 0) + if (dpaEnabled) + { + LAC_CHECK_FLAT_BUFFER_PARAM( + pDpaDecryptData->pRandom, + CHECK_EQUALS, + LAC_BITS_TO_BYTES(LAC_DPA_RSA_RANDOM_BITS)); + } + else { - LAC_INVALID_PARAM_LOG("inputData must be < modulusN"); - return CPA_STATUS_INVALID_PARAM; + /* Check MSB and LSB of the modulus */ + LAC_CHECK_RSA_BUFFER_MSB_LSB( + &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.modulusN), + opSizeInBytes, + CPA_TRUE, + CPA_TRUE); + + /* Standards based check: 0 < inputData < n */ + LAC_CHECK_NON_ZERO_PARAM(&(pDecryptData->inputData)); + if (LacPke_Compare(&(pDecryptData->inputData), + 0, + &(pDecryptData->pRecipientPrivateKey + ->privateKeyRep1.modulusN), + 0) >= 0) + { + LAC_INVALID_PARAM_LOG("inputData must be < modulusN"); + return CPA_STATUS_INVALID_PARAM; + } } } else @@ -397,6 +492,8 @@ CpaStatus LacRsa_Type1Decrypt(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, void *pCallbackTag, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData) { Cpa32U opSizeInBytes = 0; @@ -412,11 +509,22 @@ CpaStatus LacRsa_Type1Decrypt(const CpaInstanceHandle instanceHandle, LAC_ASSERT_NOT_NULL(pDecryptData); LAC_ASSERT_NOT_NULL(pOutputData); - opSizeInBytes = - LacRsa_GetPrivateKeyOpSize(pDecryptData->pRecipientPrivateKey); - functionalityId = LacPke_GetMmpId(LAC_BYTES_TO_BITS(opSizeInBytes), - lacRsaDp1SizeIdMap, - LAC_ARRAY_LEN(lacRsaDp1SizeIdMap)); + opSizeInBytes = LacRsa_GetPrivateKeyOpSize( + pDecryptData->pRecipientPrivateKey, + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeP), + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeQ), + dpaEnabled); + if (dpaEnabled) + { + if (LAC_BYTES_TO_BITS(opSizeInBytes) == LAC_3072_BITS) + functionalityId = PKE_DPA_RSA_DP1_3072; + } + else + { + functionalityId = LacPke_GetMmpId(LAC_BYTES_TO_BITS(opSizeInBytes), + lacRsaDp1SizeIdMap, + LAC_ARRAY_LEN(lacRsaDp1SizeIdMap)); + } if (LAC_PKE_INVALID_FUNC_ID == functionalityId) { @@ -429,36 +537,92 @@ CpaStatus LacRsa_Type1Decrypt(const CpaInstanceHandle instanceHandle, osalMemSet( pOutputData->pData, 0, (pOutputData->dataLenInBytes - opSizeInBytes)); - /* populate input parameters */ - LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp1_1024.c, - &(pDecryptData->inputData)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, c)] = - opSizeInBytes; - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, c)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp1_1024.d, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.privateExponentD)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, d)] = - opSizeInBytes; - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, d)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp1_1024.n, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.modulusN)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, n)] = - opSizeInBytes; - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, n)] = - CPA_FALSE; - - /* populate output parameters */ - LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_rsa_dp1_1024.m, pOutputData); - pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_output_t, m)] = - opSizeInBytes; - internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_output_t, m)] = - CPA_FALSE; + if (dpaEnabled) + { + /* populate input parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.c, + &(pDecryptData->inputData)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, c)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + c)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.d, + &(pDecryptData->pRecipientPrivateKey + ->privateKeyRep1.privateExponentD)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, d)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + d)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.e, + (pDpaDecryptData->pRsaPublicE)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, e)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + e)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.p, + (pDpaDecryptData->pRsaPrimeP)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, p)] = + pDpaDecryptData->pRsaPrimeP->dataLenInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + p)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.q, + (pDpaDecryptData->pRsaPrimeQ)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, q)] = + pDpaDecryptData->pRsaPrimeQ->dataLenInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + q)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp1_3072.r, + (pDpaDecryptData->pRandom)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, r)] = + pDpaDecryptData->pRandom->dataLenInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t, + r)] = CPA_FALSE; + + /* populate output parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_dpa_rsa_dp1_3072.m, pOutputData); + pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_t, + m)] = opSizeInBytes; + internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_t, + m)] = CPA_FALSE; + } + else + { + /* populate input parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp1_1024.c, + &(pDecryptData->inputData)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, c)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, c)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp1_1024.d, + &(pDecryptData->pRecipientPrivateKey + ->privateKeyRep1.privateExponentD)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, d)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, d)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_rsa_dp1_1024.n, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep1.modulusN)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, n)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_input_t, n)] = + CPA_FALSE; + + /* populate output parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_rsa_dp1_1024.m, pOutputData); + pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_output_t, m)] = + opSizeInBytes; + internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp1_output_t, m)] = + CPA_FALSE; + } /* populate callback data */ cbData.pClientCb = pRsaDecryptCb; @@ -483,6 +647,8 @@ CpaStatus LacRsa_Type2Decrypt(const CpaInstanceHandle instanceHandle, const CpaCyGenFlatBufCbFunc pRsaDecryptCb, void *pCallbackTag, const CpaCyRsaDecryptOpData *pDecryptData, + const CpaCyRsaDpaOpData *pDpaDecryptData, + CpaBoolean dpaEnabled, CpaFlatBuffer *pOutputData) { Cpa32U opSizeInBytes = 0; @@ -499,11 +665,22 @@ CpaStatus LacRsa_Type2Decrypt(const CpaInstanceHandle instanceHandle, LAC_ASSERT_NOT_NULL(pDecryptData); LAC_ASSERT_NOT_NULL(pOutputData); - opSizeInBytes = - LacRsa_GetPrivateKeyOpSize(pDecryptData->pRecipientPrivateKey); - functionalityId = LacPke_GetMmpId(LAC_BYTES_TO_BITS(opSizeInBytes), - lacRsaDp2SizeIdMap, - LAC_ARRAY_LEN(lacRsaDp2SizeIdMap)); + opSizeInBytes = LacRsa_GetPrivateKeyOpSize( + pDecryptData->pRecipientPrivateKey, + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeP), + RSA_PRIME(dpaEnabled, pDpaDecryptData->pRsaPrimeQ), + dpaEnabled); + if (dpaEnabled) + { + if (LAC_BYTES_TO_BITS(opSizeInBytes) == LAC_3072_BITS) + functionalityId = PKE_DPA_RSA_DP2_3072; + } + else + { + functionalityId = LacPke_GetMmpId(LAC_BYTES_TO_BITS(opSizeInBytes), + lacRsaDp2SizeIdMap, + LAC_ARRAY_LEN(lacRsaDp2SizeIdMap)); + } if (LAC_PKE_INVALID_FUNC_ID == functionalityId) { @@ -514,60 +691,137 @@ CpaStatus LacRsa_Type2Decrypt(const CpaInstanceHandle instanceHandle, /* Zero ms bytes of output buffer */ osalMemSet( pOutputData->pData, 0, (pOutputData->dataLenInBytes - opSizeInBytes)); - /* populate input parameters */ - LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp2_1024.c, - &(pDecryptData->inputData)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, c)] = - opSizeInBytes; - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, c)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp2_1024.p, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime1P)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, p)] = - LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, p)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp2_1024.q, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime2Q)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, q)] = - LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, q)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp2_1024.dp, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent1Dp)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dp)] = - LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dp)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp2_1024.dq, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent2Dq)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dq)] = - LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dq)] = - CPA_FALSE; - - LAC_MEM_SHARED_WRITE_FROM_PTR( - in.mmp_rsa_dp2_1024.qinv, - &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.coefficientQInv)); - pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, qinv)] = - LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); - internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, qinv)] = - CPA_FALSE; - - /* populate output parameters */ - LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_rsa_dp2_1024.m, pOutputData); - pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_output_t, m)] = - opSizeInBytes; - internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_output_t, m)] = - CPA_FALSE; + if (dpaEnabled) + { + /* populate input parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp2_3072.c, + &(pDecryptData->inputData)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, c)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + c)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp2_3072.e, + pDpaDecryptData->pRsaPublicE); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, e)] = + pDpaDecryptData->pRsaPublicE->dataLenInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + e)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_dpa_rsa_dp2_3072.p, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime1P)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, p)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + p)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_dpa_rsa_dp2_3072.q, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime2Q)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, q)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + q)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_dpa_rsa_dp2_3072.dp, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent1Dp)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + dp)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + dp)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_dpa_rsa_dp2_3072.dq, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent2Dq)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + dq)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + dq)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp2_3072.qinv, + &(pDecryptData->pRecipientPrivateKey + ->privateKeyRep2.coefficientQInv)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + qinv)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + qinv)] = CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_dpa_rsa_dp2_3072.r, + (pDpaDecryptData->pRandom)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, r)] = + pDpaDecryptData->pRandom->dataLenInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t, + r)] = CPA_FALSE; + + /* populate output parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_dpa_rsa_dp2_3072.m, pOutputData); + pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_t, + m)] = opSizeInBytes; + internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_t, + m)] = CPA_FALSE; + } + else + { + /* populate input parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp2_1024.c, + &(pDecryptData->inputData)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, c)] = + opSizeInBytes; + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, c)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_rsa_dp2_1024.p, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime1P)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, p)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, p)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_rsa_dp2_1024.q, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.prime2Q)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, q)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, q)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_rsa_dp2_1024.dp, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent1Dp)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dp)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dp)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR( + in.mmp_rsa_dp2_1024.dq, + &(pDecryptData->pRecipientPrivateKey->privateKeyRep2.exponent2Dq)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dq)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, dq)] = + CPA_FALSE; + + LAC_MEM_SHARED_WRITE_FROM_PTR(in.mmp_rsa_dp2_1024.qinv, + &(pDecryptData->pRecipientPrivateKey + ->privateKeyRep2.coefficientQInv)); + pInArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, qinv)] = + LAC_RSA_TYPE_2_BUF_SIZE_GET(opSizeInBytes); + internalMemInList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_input_t, qinv)] = + CPA_FALSE; + + /* populate output parameters */ + LAC_MEM_SHARED_WRITE_FROM_PTR(out.mmp_rsa_dp2_1024.m, pOutputData); + pOutArgSizeList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_output_t, m)] = + opSizeInBytes; + internalMemOutList[LAC_IDX_OF(icp_qat_fw_mmp_rsa_dp2_output_t, m)] = + CPA_FALSE; + } /* populate callback data */ cbData.pClientCb = pRsaDecryptCb; diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_encrypt.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_encrypt.c index dfdaefad..e8cb103f 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_encrypt.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_encrypt.c @@ -41,7 +41,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_keygen.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_keygen.c index 72d91e2a..e9651f36 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_keygen.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_keygen.c @@ -41,7 +41,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_p.h b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_p.h index 6ebaf5e7..40536454 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_p.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_p.h @@ -105,12 +105,18 @@ CpaBoolean LacRsa_IsValidRsaSize(Cpa32U opSizeInBytes); * @description * This function checks that the given RSA private key is valid * - * @param[in] pPrivateKey the private key to be checked + * @param[in] pPrivateKey The private key to be checked + * @param[in] pRsaPrimeP Pointer to RSA prime P data buffer + * @param[in] pRsaPrimeQ Pointer to RSA prime Q data buffer + * @param[in] dpaEnabled Flag to indicate if DPA is enabled or not * * @retval CPA_STATUS_SUCCESS * @retval CPA_STATUS_INVALID_PARAM ******************************************************************************/ -CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey); +CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey, + const CpaFlatBuffer *pRsaPrimeP, + const CpaFlatBuffer *pRsaPrimeQ, + CpaBoolean dpaEnabled); /** ******************************************************************************* @@ -124,10 +130,16 @@ CpaStatus LacRsa_CheckPrivateKeyParam(CpaCyRsaPrivateKey *pPrivateKey); * length of p + the length of q for the type 2 keys. * * @param[in] pPrivateKey the RSA private key - either type 1 or type 2 - * - * @retval the size of the operation based on this private key in bytes. + * @param[in] pRsaPrimeP Pointer to RSA prime P data buffer + * @param[in] pRsaPrimeQ Pointer to RSA prime Q data buffer + * @param[in] dpaEnabled Flag to indicate if DPA is enabled or not + * * + * @retval the size of the operation based on input parameters. ******************************************************************************/ -Cpa32U LacRsa_GetPrivateKeyOpSize(const CpaCyRsaPrivateKey *pPrivateKey); +Cpa32U LacRsa_GetPrivateKeyOpSize(const CpaCyRsaPrivateKey *pPrivateKey, + const CpaFlatBuffer *pRsaPrimeP, + const CpaFlatBuffer *pRsaPrimeQ, + CpaBoolean dpaEnabled); /* * Performs standards based checks for type2 rsa keys diff --git a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats.c b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats.c index 5c54769e..9c2a1539 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/asym/rsa/lac_rsa_stats.c @@ -39,7 +39,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" @@ -248,4 +247,17 @@ void LacRsa_StatsShow(CpaInstanceHandle instanceHandle) rsaStats.numRsaDecryptRequestErrors, rsaStats.numRsaDecryptCompleted, rsaStats.numRsaDecryptCompletedErrors); + /* Perform Info */ + osalLog(OSAL_LOG_LVL_USER, + OSAL_LOG_DEV_STDOUT, + BORDER + " KPT RSA Decrypt Requests: %16llu " BORDER "\n" BORDER + " KPT RSA Decrypt Request Errors: %16llu " BORDER "\n" BORDER + " KPT RSA Decrypt Completed: %16llu " BORDER "\n" BORDER + " KPT RSA Decrypt Completed Errors: %16llu " BORDER + "\n" SEPARATOR, + rsaStats.numKptRsaDecryptRequests, + rsaStats.numKptRsaDecryptRequestErrors, + rsaStats.numKptRsaDecryptCompleted, + rsaStats.numKptRsaDecryptCompletedErrors); } diff --git a/quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c b/quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c new file mode 100644 index 00000000..5bc95047 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/common/crypto/kpt/crypto/lac_kpt_crypto_qat_comms.c @@ -0,0 +1,128 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + ***************************************************************************** + * + * @file lac_kpt_crypto_qat_comms.c + * + * @ingroup LacKptCryptoQatComms + * + * This file implements the common functions used in KPT crypto services. + * + *****************************************************************************/ + +/* +******************************************************************************** +* Include public/global header files +******************************************************************************** +*/ +#include "cpa.h" + +/* +**************************************************************************** +* Include private header files +**************************************************************************** +*/ +/* SAL includes */ +#include "lac_common.h" +#include "lac_kpt_crypto_qat_comms.h" + +/* KPT WPK size array index */ +#define LAC_KPT_PKE_WPK_SIZE_COLUMN (0) +/* KPT CPK size array index */ +#define LAC_KPT_PKE_CPK_SIZE_COLUMN (1) + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Build a KPT unwrap context memory buffer which will be accessed by QAT + * device, the total size is 24 bytes and the layout is: + * ------------------------------------------------ + * |KeyHandle(8B)| IV(16B) | + * ------------------------------------------------ + ***************************************************************************/ +void LacKpt_BuildUnwrapCtxMemBuffer(Cpa8U *pMemPool, + CpaCyKptUnwrapContext *pKptUnwrapContext) +{ + if (!pMemPool || !pKptUnwrapContext) + return; + + osalMemSet(pMemPool, 0, LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES); + /* The first part is kptHandle */ + *((CpaCyKptHandle *)pMemPool) = pKptUnwrapContext->kptHandle; + /* The rest part is IV */ + osalMemCopy(pMemPool + sizeof(CpaCyKptHandle), + pKptUnwrapContext->iv, + CPA_CY_KPT_MAX_IV_LENGTH); +} + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Get CPK size according to WPK size. + ***************************************************************************/ +Cpa32U LacKpt_GetCpkSize(Cpa32U sizeInBytes, + const Cpa32U pSizeTable[][LAC_KPT_PKE_NUM_COLUMNS], + Cpa32U numTableEntries) +{ + Cpa32U size = LAC_KPT_PKE_INVALID_KEY_SIZE; + Cpa32U sizeIndex = 0; + + for (sizeIndex = 0; sizeIndex < numTableEntries; sizeIndex++) + { + if (pSizeTable[sizeIndex][LAC_KPT_PKE_WPK_SIZE_COLUMN] == sizeInBytes) + { + size = pSizeTable[sizeIndex][LAC_KPT_PKE_CPK_SIZE_COLUMN]; + break; + } + } + + return size; +} + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Allocate one entry from KPT memory pool to store KPT unwrap context. + ***************************************************************************/ +CpaStatus LacKpt_MemPoolAlloc(Cpa8U **ppMemPool, lac_memory_pool_id_t poolId) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa8U *pMemPool = NULL; + + do + { + pMemPool = (Cpa8U *)Lac_MemPoolEntryAlloc(poolId); + if (NULL == pMemPool) + { + LAC_LOG_ERROR("Cannot get KPT unwrap ctx mem pool entry"); + status = CPA_STATUS_RESOURCE; + } + else if ((void *)CPA_STATUS_RETRY == pMemPool) + { + osalYield(); + } + } while ((void *)CPA_STATUS_RETRY == pMemPool); + *ppMemPool = pMemPool; + + return status; +} + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Free a KPT unwrap ctx memory pool. + ***************************************************************************/ +void LacKpt_MemPoolFree(Cpa8U *pMemPool) +{ + if (pMemPool) + { + Lac_MemPoolEntryFree(pMemPool); + } +} diff --git a/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_crypto_qat_comms.h b/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_crypto_qat_comms.h new file mode 100644 index 00000000..30b3ad53 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_crypto_qat_comms.h @@ -0,0 +1,116 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + ***************************************************************************** + * @file lac_kpt_crypto_qat_comms.h + * + * @ingroup LacKptCryptoQatComms + * + * Common definitions that are KPT service specific + * + *****************************************************************************/ +#ifndef _LAC_KPT_CRYPTO_QAT_COMMS_H_ +#define _LAC_KPT_CRYPTO_QAT_COMMS_H_ + +/* +******************************************************************************** +* Include public/global header files +******************************************************************************** +*/ +#include "cpa.h" +#include "cpa_cy_kpt.h" + +/* +******************************************************************************* +* Include private header files +******************************************************************************* +*/ +/* SAL includes */ +#include "lac_mem_pools.h" + +/* Initialization Vector (IV) size of KPT unwrap context */ +#define MAX_KPT_IV_LENGTH (16) +/* Total size of KPT unwrap context */ +#define LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES \ + (sizeof(CpaCyKptHandle) + MAX_KPT_IV_LENGTH) + +/* Invalid KPT key size */ +#define LAC_KPT_PKE_INVALID_KEY_SIZE (0) +/* Columns count of KPT key size mapping table */ +#define LAC_KPT_PKE_NUM_COLUMNS (2) + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Build a KPT crypto flat buffer which contains KPT unwrap context. + * + * @description + * This function builds a KPT crypto input flat buffer which contains + * Wrapped Private Key (WPK)'s unwrap context, QAT device will parse it + * and get the necessary information to unwrapp the WPK to Clear + * Private Key (CPK) in device internal memory. + * + * @param[in] pMempool Pointer to a pre-allocated memory pool entry. + * @param[in] pKptUnwrapContext Pointer to WPK unwrapping context. + * @retval NULL + ***************************************************************************/ +void LacKpt_BuildUnwrapCtxMemBuffer(Cpa8U *pMempool, + CpaCyKptUnwrapContext *pKptUnwrapContext); + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Get CPK size according to WPK size. + * + * @description + * Get CPK size according to WPK size. + * + * @param[in] sizeInBytes WPK size. + * @param[in] pSizeTable Key size mapping table between WPK and CPK. + * @param[in] numTableEntries Entry count of key size mapping table. + * + * @retval CPK size + ***************************************************************************/ +Cpa32U LacKpt_GetCpkSize(Cpa32U sizeInBytes, + const Cpa32U pSizeTable[][LAC_KPT_PKE_NUM_COLUMNS], + Cpa32U numTableEntries); + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Allocate a memory pool entry from a specific memory pool. + * + * @description + * This function applies to a memory pool entry from a pre-allocated + * memory pool. + * + * @param[in] poolID Memory pool id of target memory pool. + * @param[out] ppMemPool Pointer to the pointer of allocated memory entry. + * + * + * @retval CPA_STATUS_SUCCESS Function executed successfully. + * @retval CPA_STATUS_RESOURCE Does not have available memory pool entry. + ***************************************************************************/ +CpaStatus LacKpt_MemPoolAlloc(Cpa8U **ppMemPool, lac_memory_pool_id_t poolID); + +/** + *************************************************************************** + * @ingroup LacKptCryptoQatComms + * Free a memory pool entry. + * + * @description + * This function frees a allocated memory pool entry. + * + * @param[in] pMemPool Pointer to allocated memory entry. + * + * @retval NULL + ***************************************************************************/ +void LacKpt_MemPoolFree(Cpa8U *pMemPool); + +#endif /* _LAC_KPT_CRYPTO_QAT_COMMS_H_ */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_pro_qat_comms.h b/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_pro_qat_comms.h new file mode 100644 index 00000000..41a9dc74 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/common/crypto/kpt/include/lac_kpt_pro_qat_comms.h @@ -0,0 +1,199 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + *************************************************************************** + * @file lac_kpt_pro_qat_comms.h + * + * @ingroup LacKptProQatComms + * + * Common definition that are KPT provision specific + * + ******************************************************************************/ + +/******************************************************************************/ + +#ifndef _LAC_KPT_PRO_QAT_COMMS_H_ +#define _LAC_KPT_PRO_QAT_COMMS_H_ + +/* +******************************************************************************* +* Include public/global header files +******************************************************************************* +*/ + +#include "cpa.h" +#include "cpa_types.h" +#include "cpa_cy_kpt.h" + +/* QAT include */ +#include "icp_qat_fw_kpt_pro.h" + +#define LAC_QAT_KPT_PRO_REQ_SZ_LW (16) +#define LAC_KPT_PRO_SERVICE_TYPE (0xC) + +#define KPT_DEV_IPUB_N_SIZE_IN_BYTE (384) +#define KPT_DEV_IPUB_E_SIZE_IN_BYTE (8) + +#define KPT_LOAD_SWK_SIZE_IN_BYTE (384) + +#define KPT_PRO_LOAD_SWK_CMD (1) +/* Load an encrypted SWK to device */ +#define KPT_PRO_DEL_SWK_CMD (2) +/* Delete a SWK */ +#define KPT_PRO_QUERY_DEV_CREDENTIAL_CMD (3) +/* Query device credential (public key and signature) */ + +typedef void *lac_kpt_pro_req_handle_t; + +#define LAC_KPT_PRO_INVALID_HANDLE ((lac_kpt_pro_req_handle_t)0) + +/** + ******************************************************************************* + * @ingroup LacKptProvision + * This macro verifies that the KPT Instance Handle is valid. + * + * @description + * Check KPT Instance's value, type and running state. + * + ******************************************************************************/ +#define LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle) \ + do \ + { \ + LAC_CHECK_INSTANCE_HANDLE(instanceHandle); \ + /* Test if instance supports asymmetric crypto */ \ + SAL_CHECK_INSTANCE_TYPE( \ + instanceHandle, \ + (SAL_SERVICE_TYPE_CRYPTO | SAL_SERVICE_TYPE_CRYPTO_ASYM)); \ + } while (0) + +/** + ****************************************************************************** + * @ingroup LacKptProQatComms + * + * @description + * KPT provision response client callback opdata + * + *****************************************************************************/ +typedef struct lac_kpt_pro_op_cb_data_s +{ + const void *pClientCb; + void *pCallbackTag; + Cpa8U *pVirtAddr; + Cpa64U keyHandle; + Cpa16U rspStatus; + Cpa8U cmdID; +} lac_kpt_pro_op_cb_data_t; + +/** + ****************************************************************************** + * @ingroup LacKptProQatComms + * + * @description + * KPT provision response client callback function + * + *****************************************************************************/ +typedef void (*lac_kpt_pro_op_cb_func_t)(CpaStatus status, + CpaInstanceHandle instanceHandle, + lac_kpt_pro_op_cb_data_t *pCbData); +/** + ***************************************************************************** + * @ingroup LacKptProQatComms + * + * @description + * KPT provision sync mode callback function definition + * + *****************************************************************************/ +typedef void (*lac_kpt_pro_sync_cb)(void *pCallbackTag, CpaStatus status); + +/** + ***************************************************************************** + * @ingroup LacKptProQatComms + * + * @description + * Contains the data for a KPT provision operation callback + *****************************************************************************/ +typedef struct lac_kpt_pro_cb_info_s +{ + lac_kpt_pro_op_cb_func_t cbFunc; + lac_kpt_pro_op_cb_data_t *pcbData; + CpaInstanceHandle instanceHandle; +} lac_kpt_pro_cb_info_t; + +/** + ****************************************************************************** + * @ingroup LacKptProQatComms + * Request data of KPT provision for QAT messages + * + * @description + * This structure defines data format of KPT provision request which is + * issued along with a crypto instances. This structure is used to store + * data which is known when the message is sent and which we wish to + * retrieve when the response message is processed. + *****************************************************************************/ +typedef struct lac_kpt_pro_qat_req_data_s +{ + union lac_kpt_pro_qat_req_data_request_u { + icp_qat_fw_kpt_pro_request_t request; + Cpa8U padding[LAC_QAT_KPT_PRO_REQ_SZ_LW * 4]; + } u1; + /* KPT only supports asymmetric service, the size of request is 64 bytes. */ + + lac_kpt_pro_cb_info_t cbinfo; +} lac_kpt_pro_qat_req_data_t; + +/** + ******************************************************************************* + * @ingroup LacKptProQatComms + * + * @description + * This function sends a single (unchained) KPT provision request to the + * QAT. It takes the parameters for a KPT provision request, creates the + * request, fills in the KPT provision fields, and sends it to the QAT. + * This function will block, waiting for a response until the callback + * function is invoked when the response from the QAT has been processed. + * + * @param[in] instanceHandle Instance handle + * @param[in] cmdID KPT provision command ID + * @param[in] pKeyHandle A pointer referring to the SWK's identity + * @param[in] pSrc A flat buffer pointer referring to input + * data for the QAT + * @param[in] pDevCredential A pointer referring to the KPT device + * credential + * @param[out] pKptStatus The return code + * + * @retval CPA_STATUS_SUCCESS No error + * @retval CPA_STATUS_RESOURCE Resource error (e.g., failed memory + * allocation) + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter + * @retval CPA_STATUS_RETRY Ring full + * @retval CPA_STATUS_FAIL Failed to send the request + * + *****************************************************************************/ +CpaStatus LacKpt_Pro_SendRequest(CpaInstanceHandle instanceHandle, + Cpa8U cmdID, + CpaCyKptHandle *pKeyHandle, + CpaFlatBuffer *pSrc, + CpaCyKptValidationKey *pDevCredential, + CpaCyKptKeyManagementStatus *pKptStatus); + +/** + ****************************************************************************** + * @ingroup LacKptProQatComms + * + * @description + * This function will handle KPT provision response, it should be called + * in response callback function. + * + * @param[in] pRespMsg Pointer to the KPT provision response + * + * @retval NULL + * + *****************************************************************************/ +void LacKpt_Pro_RspHandler(void *pRespMsg); +#endif /* _LAC_KPT_PRO_QAT_COMMS_H_ */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c b/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c new file mode 100644 index 00000000..b2877334 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_pro_qat_comms.c @@ -0,0 +1,391 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + *************************************************************************** + * + * @file lac_kpt_pro_qat_comms.c + * + * @ingroup LacKptProQatComms + * + * This file implements the API for creating KPT key provision messages and + * sending these to the QAT device. It implements an API for creating a KPT + * provision request, and for sending a message to the QAT device. + * + ***************************************************************************/ + +/* +******************************************************************************** +* Include public/global header files +******************************************************************************** +*/ +#include "cpa.h" + +/* +**************************************************************************** +* Include private header files +**************************************************************************** +*/ +/* SAL includes */ +#include "lac_log.h" +#include "lac_common.h" +#include "lac_kpt_pro_qat_comms.h" +#include "lac_mem.h" +#include "lac_sal_types_crypto.h" +#include "sal_qat_cmn_msg.h" + +#define LAC_KPT_PRO_SYNC_CALLBACK_TIMEOUT (2000) /* 2000ms */ + +#define LAC_KPT_DEV_CREDENTIAL_SIZE_IN_BYTE (776) +/* +**************************************************************************** +* Define static function definitions +**************************************************************************** +*/ + +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT provision client callback function +***************************************************************************/ +STATIC +void LacKpt_ProcessProCb(CpaStatus status, + CpaInstanceHandle instanceHandle, + lac_kpt_pro_op_cb_data_t *pCbData) +{ + lac_kpt_pro_sync_cb pCb = NULL; + void *pCallbackTag = NULL; + + /* Extracts info from callback data structure */ + LAC_ASSERT_NOT_NULL(pCbData); + pCallbackTag = (void *)pCbData->pCallbackTag; + pCb = (lac_kpt_pro_sync_cb)LAC_CONST_PTR_CAST(pCbData->pClientCb); + LAC_ASSERT_NOT_NULL(pCb); + + /* Invokes the user callback */ + pCb(pCallbackTag, status); +} + +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT provision sync mode client callback function +***************************************************************************/ +STATIC +void LacKpt_Pro_SyncClientCb(void *pCallbackTag, CpaStatus status) +{ + LacSync_GenWakeupSyncCaller(pCallbackTag, status); +} + +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT provision sync mode client callback function +***************************************************************************/ +STATIC +CpaStatus LacKpt_Pro_CreateRequest(lac_kpt_pro_req_handle_t *pReqHandle, + CpaInstanceHandle instanceHandle, + Cpa8U cmdID, + CpaCyKptHandle *pKeyHandle, + CpaFlatBuffer *pSrc, + lac_kpt_pro_op_cb_data_t *pCbData) +{ + CpaStatus status = CPA_STATUS_FAIL; + lac_kpt_pro_qat_req_data_t *pReqData = NULL; + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + + status = LAC_OS_MALLOC(&pReqData, sizeof(lac_kpt_pro_qat_req_data_t)); + if (CPA_STATUS_SUCCESS == status) + { + LAC_OS_BZERO(pReqData, sizeof(lac_kpt_pro_qat_req_data_t)); + pReqData->cbinfo.cbFunc = LacKpt_ProcessProCb; + pReqData->cbinfo.pcbData = pCbData; + pReqData->cbinfo.instanceHandle = instanceHandle; + pReqData->u1.request.cmd_id = cmdID; + pReqData->u1.request.service_type = LAC_KPT_PRO_SERVICE_TYPE; + pReqData->u1.request.opaque_data = (LAC_ARCH_UINT)pReqData; + pReqData->u1.request.valid = ICP_QAT_FW_COMN_VALID_FLAG_MASK; + + if (cmdID == KPT_PRO_DEL_SWK_CMD) + pReqData->u1.request.key_handle = *pKeyHandle; + + if (cmdID == KPT_PRO_LOAD_SWK_CMD) + pReqData->u1.request.src_addr = LAC_OS_VIRT_TO_PHYS_EXTERNAL( + pCryptoService->generic_service_info, pSrc->pData); + + if (NULL != pCbData->pVirtAddr) + pReqData->u1.request.dst_addr = LAC_OS_VIRT_TO_PHYS_INTERNAL( + &pCryptoService->generic_service_info, pCbData->pVirtAddr); + + *pReqHandle = (lac_kpt_pro_req_handle_t)pReqData; + } + + return status; +} + +/** + *************************************************************************** + * @ingroup LacKptProQatComms + * Destroy KPT provision requests + ***************************************************************************/ +STATIC +void LacKpt_Pro_DestroyRequest(lac_kpt_pro_req_handle_t *pReqHandle) +{ + if (NULL != pReqHandle) + LAC_OS_FREE(*pReqHandle); +} + +/** + *************************************************************************** + * @ingroup LacKptProQatComms + * KPT Provision single request creation and sending function + ***************************************************************************/ +STATIC +CpaStatus LacKpt_Pro_SendSingleRequest(CpaInstanceHandle instanceHandle, + Cpa8U cmdID, + CpaCyKptHandle *pKeyHandle, + CpaFlatBuffer *pSrc, + lac_kpt_pro_op_cb_data_t *pCbData) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + lac_kpt_pro_req_handle_t reqHandle = LAC_KPT_PRO_INVALID_HANDLE; + lac_kpt_pro_qat_req_data_t *pReqData = NULL; + Cpa32U size = 0; + void *pMsg = NULL; + + status = LacKpt_Pro_CreateRequest( + &reqHandle, instanceHandle, cmdID, pKeyHandle, pSrc, pCbData); + if (CPA_STATUS_SUCCESS == status) + { + pReqData = (lac_kpt_pro_qat_req_data_t *)reqHandle; + { + pMsg = (void *)&(pReqData->u1.request); + size = LAC_QAT_KPT_PRO_REQ_SZ_LW; + } + + status = SalQatMsg_transPutMsg(pCryptoService->trans_handle_asym_tx, + pMsg, + size, + LAC_LOG_MSG_KPT_PRO, + NULL); + + if (CPA_STATUS_SUCCESS != status) + { + LacKpt_Pro_DestroyRequest(&reqHandle); + } + } + return status; +} + +#ifdef ICP_PARAM_CHECK +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT Provision packet sending function input parameters check +***************************************************************************/ +STATIC +CpaStatus LacKpt_Pro_SendRequestParamCheck( + CpaInstanceHandle instanceHandle, + Cpa8U cmdID, + CpaCyKptHandle *pKeyHandle, + CpaFlatBuffer *pSrc, + CpaCyKptValidationKey *pDevCredential, + CpaCyKptKeyManagementStatus *pKptStatus) +{ + /* Ensure the instance is not NULL */ + LAC_CHECK_NULL_PARAM(instanceHandle); + LAC_CHECK_NULL_PARAM(pKptStatus); + + switch (cmdID) + { + case KPT_PRO_QUERY_DEV_CREDENTIAL_CMD: + LAC_CHECK_NULL_PARAM(pDevCredential); + break; + case KPT_PRO_LOAD_SWK_CMD: + LAC_CHECK_NULL_PARAM(pKeyHandle); + LAC_CHECK_NULL_PARAM(pSrc); + LAC_CHECK_NULL_PARAM(pSrc->pData); + break; + case KPT_PRO_DEL_SWK_CMD: + LAC_CHECK_NULL_PARAM(pKeyHandle); + break; + default: + LAC_LOG_ERROR("Unknown KPT provision command id"); + return CPA_STATUS_INVALID_PARAM; + } + + return CPA_STATUS_SUCCESS; +} +#endif + +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT Provision sync mode packet sending function +***************************************************************************/ +CpaStatus LacKpt_Pro_SendRequest(CpaInstanceHandle instanceHandle, + Cpa8U cmdID, + CpaCyKptHandle *pKeyHandle, + CpaFlatBuffer *pSrc, + CpaCyKptValidationKey *pDevCredential, + CpaCyKptKeyManagementStatus *pKptStatus) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + lac_kpt_pro_op_cb_data_t cbData = { 0 }; + lac_sync_op_data_t *pSyncCallbackData = NULL; + Cpa8U *pVirt_addr = NULL; + +#ifdef ICP_PARAM_CHECK + status = LacKpt_Pro_SendRequestParamCheck( + instanceHandle, cmdID, pKeyHandle, pSrc, pDevCredential, pKptStatus); + LAC_CHECK_STATUS(status); +#endif + + status = LacSync_CreateSyncCookie(&pSyncCallbackData); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to create sync cookie"); + return status; + } + + cbData.cmdID = cmdID; + cbData.pCallbackTag = (void *)pSyncCallbackData; + cbData.pClientCb = (void *)LacKpt_Pro_SyncClientCb; + cbData.pVirtAddr = NULL; + if (NULL != pDevCredential) + { + sal_crypto_service_t *pCryptoService = + (sal_crypto_service_t *)instanceHandle; + + status = LAC_OS_CAMALLOC(&pVirt_addr, + LAC_KPT_DEV_CREDENTIAL_SIZE_IN_BYTE, + LAC_64BYTE_ALIGNMENT, + pCryptoService->nodeAffinity); + + if (CPA_STATUS_SUCCESS == status) + cbData.pVirtAddr = pVirt_addr; + else + { + LAC_LOG_ERROR( + "Failed to allocate memory for KPT provision response"); + LacSync_SetSyncCookieComplete(pSyncCallbackData); + } + } + + if (CPA_STATUS_SUCCESS == status) + { + status = LacKpt_Pro_SendSingleRequest( + instanceHandle, cmdID, pKeyHandle, pSrc, &cbData); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to send KPT provision request"); + LacSync_SetSyncCookieComplete(pSyncCallbackData); + } + } + + if (CPA_STATUS_SUCCESS == status) + { + status = LacSync_WaitForCallback(pSyncCallbackData, + LAC_KPT_PRO_SYNC_CALLBACK_TIMEOUT, + &status, + NULL); + if (CPA_STATUS_SUCCESS != status) + { + LacSync_SetSyncCookieComplete(pSyncCallbackData); + LAC_LOG_ERROR("Failed to wait for KPT provision response"); + } + } + + if ((CPA_STATUS_SUCCESS == status) && (cmdID != cbData.cmdID)) + { + status = CPA_STATUS_FAIL; + LacSync_SetSyncCookieComplete(pSyncCallbackData); + LAC_LOG_ERROR("Get a different command id from kpt provision response"); + } + + if (CPA_STATUS_SUCCESS == status) + { + *pKptStatus = cbData.rspStatus; + + if (NULL != pDevCredential && + NULL != pDevCredential->publicKey.modulusN.pData && + NULL != pDevCredential->publicKey.publicExponentE.pData) + { + osalMemCopy(pDevCredential->publicKey.modulusN.pData, + cbData.pVirtAddr, + KPT_DEV_IPUB_N_SIZE_IN_BYTE); + osalMemCopy(pDevCredential->publicKey.publicExponentE.pData, + cbData.pVirtAddr + KPT_DEV_IPUB_N_SIZE_IN_BYTE, + KPT_DEV_IPUB_E_SIZE_IN_BYTE); + osalMemCopy(pDevCredential->signature, + cbData.pVirtAddr + KPT_DEV_IPUB_N_SIZE_IN_BYTE + + KPT_DEV_IPUB_E_SIZE_IN_BYTE, + CPA_CY_RSA3K_SIG_SIZE_INBYTES); + } + + if (NULL != pKeyHandle) + *pKeyHandle = cbData.keyHandle; + } + + LAC_OS_CAFREE(cbData.pVirtAddr); + LacSync_DestroySyncCookie(&pSyncCallbackData); + + return status; +} + +/** +*************************************************************************** +* @ingroup LacKptProQatComms +* KPT Provision response handler +***************************************************************************/ +void LacKpt_Pro_RspHandler(void *pRespMsg) +{ + lac_kpt_pro_qat_req_data_t *pReqData = NULL; + lac_kpt_pro_op_cb_data_t *pCbData = NULL; + lac_kpt_pro_op_cb_func_t pCbFunc = NULL; + icp_qat_fw_kpt_pro_resp_data_t *pKptProRespMsg = NULL; + lac_kpt_pro_req_handle_t requestHandle = CPA_INSTANCE_HANDLE_SINGLE; + CpaInstanceHandle instanceHandle = CPA_INSTANCE_HANDLE_SINGLE; + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa8U pkeRespFlags = 0; + + /* If the response message is NULL, this function should return + * earlier and the client callback function will not be invoked. + * The calling stack is expected to detect this kind of error + * and report corresponding error code. */ + if (NULL == pRespMsg) + return; + + pKptProRespMsg = (icp_qat_fw_kpt_pro_resp_data_t *)pRespMsg; + pkeRespFlags = pKptProRespMsg->rsp_status.pke_resp_flags; + + LAC_MEM_SHARED_READ_TO_PTR(pKptProRespMsg->opaque_data, pReqData); + + requestHandle = (lac_kpt_pro_req_handle_t)pReqData; + pCbFunc = pReqData->cbinfo.cbFunc; + pCbData = pReqData->cbinfo.pcbData; + instanceHandle = pReqData->cbinfo.instanceHandle; + pCbData->cmdID = pKptProRespMsg->cmd_id; + pCbData->keyHandle = pKptProRespMsg->key_handle; + + /* Detect early FW response status */ + if (ICP_QAT_FW_COMN_STATUS_FLAG_OK == pkeRespFlags) + pCbData->rspStatus = CPA_CY_KPT_SUCCESS; + else if (ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(pkeRespFlags)) + pCbData->rspStatus = pKptProRespMsg->rsp_status.comn_err_code; + else + pCbData->rspStatus = CPA_CY_KPT_FAILED; + + LacKpt_Pro_DestroyRequest(&requestHandle); + (*pCbFunc)(status, instanceHandle, pCbData); + + return; +} diff --git a/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c b/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c index 8e1b5ccf..7be395bb 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/kpt/provision/lac_kpt_provision.c @@ -24,6 +24,194 @@ #include "cpa.h" #include "cpa_cy_kpt.h" +/* +**************************************************************************** +* Include private header files +**************************************************************************** +*/ +/* SAL includes */ +#include "lac_common.h" +#include "lac_pke_utils.h" +#include "lac_sal_types_crypto.h" +#include "sal_service_state.h" +#include "lac_kpt_pro_qat_comms.h" + +#ifndef QAT_KPT_DEBUG_KEY +/* Product issue key cert */ +static Cpa8U kpt_product_issue_key_cert[] = + "-----BEGIN CERTIFICATE-----\n" + "MIIFqjCCBBKgAwIBAgIUShQDHrdYk/549dCw5Yxa/lGj/oEwDQYJKoZIhvcNAQEM\n" + "BQAwgYsxCzAJBgNVBAYMAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEg\n" + "Q2xhcmExGjAYBgNVBAoMEUludGVsIENvcnBvcmF0aW9uMSUwIwYDVQQLDBxLUFQg\n" + "Um9vdCBDZXJ0IFNpZ25pbmcgUlNBIDNLMRYwFAYDVQQDDA13d3cuaW50ZWwuY29t\n" + "MB4XDTE4MDUwODIwMzY0MVoXDTM1MTIzMTIzNTk1OVowgYQxCzAJBgNVBAYMAlVT\n" + "MQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNVBAoMEUlu\n" + "dGVsIENvcnBvcmF0aW9uMR4wHAYDVQQLDBVLUFQgSXNzdWluZyBDQSBSU0EgM0sx\n" + "FjAUBgNVBAMMDXd3dy5pbnRlbC5jb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw\n" + "ggGKAoIBgQDJi5vrTU64iwydSGJ/oBSALae9hC1Aa/j1zEbhFqPZcXooN2jOxMBa\n" + "Py6ZITFTriUJqnHWXrxF6XQN4Wvr3rI242ASW5M41k5hKWvX3dpeyuMwL99Bn75J\n" + "b2m15IeKzbjwaYS7i5L6+n5z9tw3nBM7rT+hlB+DPlPH7u9QBoupPFU302sumVx0\n" + "qFobBrOLj5igFsTgZ7zNpRPqzFjIRAxYeXgtQdVu4tsFOZzU1nicKn2vP3/AGNN9\n" + "yz8pj4bLYNTKB6oeVsGlR7FuAZSyt0QDTDq0R2YE22Gvk/rpjkqn8JERZt/WHjhf\n" + "g2qA74FVaEx0kawt1uX0Pa51Z9M4n2ifZdpGDhTJLQbLR3AXwjNo7WrvWllRjSqs\n" + "rQ8vNjB6+lkZPqEeS1mbFAoY4WgUrgcaNTOk5Ik/h2z/CuTPnNDm7wZy11eEJS7Q\n" + "uujc9wQ67t1gC88pFSscj4Qtk8bM7ekvxTLjsI6J6psY6MrFp0u7/ZDHVolTdaZF\n" + "mPR3hNMOYw0CAwEAAaOCAQkwggEFMB8GA1UdIwQYMBaAFGb6TO43nCxUdtkwRtfx\n" + "gHsGehDYMB0GA1UdDgQWBBR5Ocgnv1EGEZAUQiBa7nmHPUBi1jAPBgNVHRMBAf8E\n" + "BTADAQH/MA4GA1UdDwEB/wQEAwIBhjBYBggrBgEFBQcBAQRMMEowSAYIKwYBBQUH\n" + "MAKGPGh0dHA6Ly90c2NpLmludGVsLmNvbS9jb250ZW50L0tQVC9jZXJ0cy9LUFRf\n" + "Um9vdENBX1JTQTNLLmNlcjBIBgNVHR8EQTA/MD2gO6A5hjdodHRwOi8vdHNjaS5p\n" + "bnRlbC5jb20vY29udGVudC9LUFQvY3Jscy9LUFRfQ0FfUlNBM0suY3JsMA0GCSqG\n" + "SIb3DQEBDAUAA4IBgQBn0KeRuZ7qVaIMDR87k4SBoDSbXKg8m6/om+W9xxeBEwQk\n" + "rY9zsfoIdrNvgd6yfu8swRkof0pIHRlZWOBY6V+R3hlrcmWowPk1NoKLRvNz2LOj\n" + "vchxHVcfLiiIYQbiksU9OacfLxvBCLXkYLuk5ITlh5E+eMsyIF09X/GVCghSzYor\n" + "TgzFWqx15I8KHVoMwbPchIVfVipr/hMo8jcdo3ZUAUhuNPebORBk86nRyBEvMbtK\n" + "IfTLVXUFVPGfahbmrihOqwZTsEQFyNnkK7fH1uUFvvOeX3Bq5f/AJbcbwacO2h8p\n" + "U3sq1tyTNepAdM7jIn9OG4dBDvTc18NTFmPOXvogdq9Q69rKlmljJVEC1mr4eK4h\n" + "YZ0LJuACGbuos3+TXrjEblcZUkD5i6HZ1EFnlhmGnovDZu7NG21/AsM+W/bFaOn9\n" + "i7xJjsXzcH7tdbsYvd3QqaX+y/V9uFGFR1MRp0ISFKREReCM7NyOb4KPsRkmoJy7\n" + "cXNwD4aT+CChYBleEY4=\n" + "-----END CERTIFICATE-----"; + +#else +/* Development issue key cert */ +static Cpa8U kpt_debug_issue_key_cert[] = + "-----BEGIN CERTIFICATE-----\n" + "MIIFqjCCBBKgAwIBAgIUQ9DKepJGJw/JT7gF/cRLPQ9AixcwDQYJKoZIhvcNAQEM\n" + "BQAwgYsxCzAJBgNVBAYMAlVTMQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEg\n" + "Q2xhcmExGjAYBgNVBAoMEUludGVsIENvcnBvcmF0aW9uMSUwIwYDVQQLDBxLUFQg\n" + "Um9vdCBDZXJ0IFNpZ25pbmcgUlNBIDNLMRYwFAYDVQQDDA13d3cuaW50ZWwuY29t\n" + "MB4XDTE4MDMyNzIyMDIzOVoXDTM1MTIzMTIzNTk1OVowgYQxCzAJBgNVBAYMAlVT\n" + "MQswCQYDVQQIDAJDQTEUMBIGA1UEBwwLU2FudGEgQ2xhcmExGjAYBgNVBAoMEUlu\n" + "dGVsIENvcnBvcmF0aW9uMR4wHAYDVQQLDBVLUFQgSXNzdWluZyBDQSBSU0EgM0sx\n" + "FjAUBgNVBAMMDXd3dy5pbnRlbC5jb20wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw\n" + "ggGKAoIBgQDDKEjvzCqxgoKtzzpXyuwo/2nRQ6hM16tamsYTBhZ3LtDDElz+BFZY\n" + "jk9lvdwjUAB+kZ5T43BXiKQ8YI8sg4uRFpw1ybZmZJXAoGBcJVvCF9Gz47ky8nqH\n" + "ObLxz1C6S4/fmfV65qPRwEe11cIXfoRzkMJ4yhm8b9CTk85yK6WstR67U/qPc9u2\n" + "1tqFKmaXUCzVnhRdob2VsEHh0pMGE4kdBpyAUBIJQprcEyDNHpqNjfdlvgdW8XBV\n" + "65lbXWsFf+1nRlLFzqjUvB8Ur7qCJgdXwWFI8rVG6SA0v4w8+SfTg9ECEhrhJZ9N\n" + "cZiBB8JD3UhzlNKhP/WbRo2H737wibSVS4CDRBUA7EygaqUGI7+SgDEkNnwbw+ql\n" + "EJB92kwAqUJbAiDkD/rYT+rjasIaOynvLsZiYb2i9bBhBjf2mwmlW3KZwHCKH4TA\n" + "xUT8Z36ZUHwCH/ZvJydM9tWcqr97gNijA+YLyfaxij8l3AX0DTUHV3j4Iq3oYAHZ\n" + "TouXivYUAyMCAwEAAaOCAQkwggEFMB8GA1UdIwQYMBaAFHbZE5uoByMmdrdZM58A\n" + "DyPgbXTlMB0GA1UdDgQWBBTGJqNtTohCujN9gOTT5kXQ7QZgXzAPBgNVHRMBAf8E\n" + "BTADAQH/MA4GA1UdDwEB/wQEAwIBhjBYBggrBgEFBQcBAQRMMEowSAYIKwYBBQUH\n" + "MAKGPGh0dHA6Ly90c2NpLmludGVsLmNvbS9jb250ZW50L0tQVC9jZXJ0cy9LUFRf\n" + "Um9vdENBX1JTQTNLLmNlcjBIBgNVHR8EQTA/MD2gO6A5hjdodHRwOi8vdHNjaS5p\n" + "bnRlbC5jb20vY29udGVudC9LUFQvY3Jscy9LUFRfQ0FfUlNBM0suY3JsMA0GCSqG\n" + "SIb3DQEBDAUAA4IBgQCMko3YW38uKBA+FmkWsjZviiz2xPtpXYzsomce8kz8oDm3\n" + "ial8ikAnzYrogpNm8ivb3tZ1QgT/KQZpta4Ru7dwJNVxPsI2bcQdYZs9moxX+KRG\n" + "6tbSCf/MlL8ezPyVBkoZ4jlv0pFR3bL1yA7dKNTLWgUq5Wg5T1WqMyXoacpCE+EB\n" + "ommAbBhj+o2rcyIgPiDpORQbsuRZVLBcEInouTz3bjvbIKx2BH0iLJ5CrK7GeKNK\n" + "9Omob3H2bm21fNmE6ep1WKCD/vPzbfo1VWUaI8Zi9bzwpPPaEuVuGjEngYp1w5ka\n" + "Uh1Ym/1BkxHHT1pptxRzH1TUweKHyOqgbs8hDUvy1r7oWcy1aphXzzNxK0BoC2F7\n" + "QWBXuD6/lOZSjA/puFXraFqabCQWfPhsmsiSY9yB6in7Xa43+gT/RgVjfnM2NX81\n" + "P75/33wVlYREn+d7QFYpY6MaXs6A7/Cdi1dS7pkENOO3gJVn21q2RdlxkJEGGlzN\n" + "7mag/PceIuYRuARjuYc=\n" + "-----END CERTIFICATE-----"; +#endif + +#ifdef ICP_PARAM_CHECK +/** + *************************************************************************** + * @ingroup LacKptProvision + * Query KPT issue key certificate parameters check + ***************************************************************************/ +STATIC +CpaStatus LacQueryKptIssueKeyCertParamCheck( + const CpaInstanceHandle instanceHandle, + CpaFlatBuffer *pCert, + CpaCyKptKeyManagementStatus *pStatus) +{ + LAC_CHECK_NULL_PARAM(pCert); + LAC_CHECK_NULL_PARAM(pStatus); + + LAC_CHECK_FLAT_BUFFER_PARAM(pCert, CHECK_NONE, 0); + + return CPA_STATUS_SUCCESS; +} + +/** + *************************************************************************** + * @ingroup LacKptProvision + * Query KPT device credential parameters check + ***************************************************************************/ +STATIC +CpaStatus LacQueryKptDeviceCredentialParamCheck( + const CpaInstanceHandle instanceHandle, + CpaCyKptValidationKey *pDevCredential, + CpaCyKptKeyManagementStatus *pStatus) +{ + LAC_CHECK_NULL_PARAM(pDevCredential); + LAC_CHECK_NULL_PARAM(pStatus); + + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pDevCredential->publicKey.modulusN), CHECK_NONE, 0); + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pDevCredential->publicKey.publicExponentE), CHECK_NONE, 0); + LAC_CHECK_FLAT_BUFFER_PARAM(&(pDevCredential->publicKey.modulusN), + CHECK_GREATER_EQUALS, + KPT_DEV_IPUB_N_SIZE_IN_BYTE); + LAC_CHECK_FLAT_BUFFER_PARAM(&(pDevCredential->publicKey.publicExponentE), + CHECK_GREATER_EQUALS, + KPT_DEV_IPUB_E_SIZE_IN_BYTE); + + return CPA_STATUS_SUCCESS; +} + +/** + *************************************************************************** + * @ingroup LacKptProvision + * Load KPT key parameters check + ***************************************************************************/ +STATIC +CpaStatus LacKptLoadKeyParamCheck(const CpaInstanceHandle instanceHandle, + CpaCyKptLoadKey *pSWK, + CpaCyKptHandle *keyHandle, + CpaCyKptKeyManagementStatus *pStatus) +{ + LAC_CHECK_NULL_PARAM(pSWK); + LAC_CHECK_NULL_PARAM(keyHandle); + LAC_CHECK_NULL_PARAM(pStatus); + + LAC_CHECK_FLAT_BUFFER_PARAM(&(pSWK->eSWK), CHECK_NONE, 0); + LAC_CHECK_FLAT_BUFFER_PARAM( + &(pSWK->eSWK), CHECK_GREATER_EQUALS, KPT_LOAD_SWK_SIZE_IN_BYTE); + + return CPA_STATUS_SUCCESS; +} +#endif + +/** + *************************************************************************** + * @ingroup LacKptProvision + * Read hard-coding X.509 KPT issue key certificate + ***************************************************************************/ +STATIC +CpaStatus LacReadKptIssueKeyCert(CpaFlatBuffer *pCert) +{ + +#ifndef QAT_KPT_DEBUG_KEY + if (pCert->dataLenInBytes < sizeof(kpt_product_issue_key_cert)) + return CPA_STATUS_INVALID_PARAM; + + osalMemCopy(pCert->pData, + kpt_product_issue_key_cert, + sizeof(kpt_product_issue_key_cert)); + pCert->dataLenInBytes = sizeof(kpt_product_issue_key_cert); +#else + if (pCert->dataLenInBytes < sizeof(kpt_debug_issue_key_cert)) + return CPA_STATUS_INVALID_PARAM; + + osalMemCopy(pCert->pData, + kpt_debug_issue_key_cert, + sizeof(kpt_debug_issue_key_cert)); + pCert->dataLenInBytes = sizeof(kpt_debug_issue_key_cert); +#endif + + return CPA_STATUS_SUCCESS; +} + /** *************************************************************************** * @ingroup LacKptProvision @@ -33,7 +221,35 @@ CpaStatus cpaCyKptQueryIssuingKeys(const CpaInstanceHandle instanceHandle, CpaFlatBuffer *pPublicX509IssueCert, CpaCyKptKeyManagementStatus *pKptStatus) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); +#endif + SAL_RUNNING_CHECK(instanceHandle); +#ifdef ICP_PARAM_CHECK + status = LacQueryKptIssueKeyCertParamCheck( + instanceHandle, pPublicX509IssueCert, pKptStatus); + LAC_CHECK_STATUS(status); +#endif + + *pKptStatus = CPA_CY_KPT_FAILED; + SAL_CHECK_INSTANCE_CRYPTO_CAPABILITY(instanceHandle, kpt); + + status = LacReadKptIssueKeyCert(pPublicX509IssueCert); + if (CPA_STATUS_SUCCESS == status) + { + *pKptStatus = CPA_CY_KPT_SUCCESS; + } + +#ifdef ICP_TRACE + LAC_LOG4("Called with params (0x%lx, 0x%lx, 0x%lx[%d])\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pPublicX509IssueCert, + (LAC_ARCH_UINT)pKptStatus, + *pKptStatus); +#endif + return status; } /** @@ -46,7 +262,49 @@ CpaStatus cpaCyKptQueryDeviceCredentials( CpaCyKptValidationKey *pDevCredential, CpaCyKptKeyManagementStatus *pKptStatus) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); +#endif + SAL_RUNNING_CHECK(instanceHandle); +#ifdef ICP_PARAM_CHECK + status = LacQueryKptDeviceCredentialParamCheck( + instanceHandle, pDevCredential, pKptStatus); + LAC_CHECK_STATUS(status); +#endif + + *pKptStatus = CPA_CY_KPT_FAILED; + SAL_CHECK_INSTANCE_CRYPTO_CAPABILITY(instanceHandle, kpt); + + status = LacKpt_Pro_SendRequest(instanceHandle, + KPT_PRO_QUERY_DEV_CREDENTIAL_CMD, + 0, + NULL, + pDevCredential, + pKptStatus); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR1("Failed to send device credential query request, " + "error code: %d\n", + status); + return status; + } + + if (CPA_STATUS_SUCCESS != *pKptStatus) + { + LAC_LOG_ERROR1("Failed to query device credential, error code: %d \n", + *pKptStatus); + } + +#ifdef ICP_TRACE + LAC_LOG4("Called with params (0x%lx, 0x%lx, 0x%lx[%d])\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pDevCredential, + (LAC_ARCH_UINT)pKptStatus, + *pKptStatus); +#endif + return CPA_STATUS_SUCCESS; } /** @@ -59,7 +317,52 @@ CpaStatus cpaCyKptLoadKey(CpaInstanceHandle instanceHandle, CpaCyKptHandle *keyHandle, CpaCyKptKeyManagementStatus *pKptStatus) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); +#endif + SAL_RUNNING_CHECK(instanceHandle); +#ifdef ICP_PARAM_CHECK + status = + LacKptLoadKeyParamCheck(instanceHandle, pSWK, keyHandle, pKptStatus); + LAC_CHECK_STATUS(status); +#endif + + *pKptStatus = CPA_CY_KPT_FAILED; + SAL_CHECK_INSTANCE_CRYPTO_CAPABILITY(instanceHandle, kpt); + + status = LacKpt_Pro_SendRequest(instanceHandle, + KPT_PRO_LOAD_SWK_CMD, + keyHandle, + &(pSWK->eSWK), + NULL, + pKptStatus); + + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR1("Failed to send key loading request, error code: %d\n", + status); + return status; + } + + if (CPA_STATUS_SUCCESS != *pKptStatus) + { + + LAC_LOG_ERROR1("Failed to load key to device, error code: %d\n", + *pKptStatus); + } + +#ifdef ICP_TRACE + LAC_LOG6("Called with params (0x%lx, 0x%lx, 0x%lx[%llu], 0x%lx[%d])\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)pSWK, + (LAC_ARCH_UINT)keyHandle, + *keyHandle, + (LAC_ARCH_UINT)pKptStatus, + *pKptStatus); +#endif + return CPA_STATUS_SUCCESS; } /** @@ -71,5 +374,44 @@ CpaStatus cpaCyKptDeleteKey(CpaInstanceHandle instanceHandle, CpaCyKptHandle keyHandle, CpaCyKptKeyManagementStatus *pKptStatus) { - return CPA_STATUS_UNSUPPORTED; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_KPT_INSTANCE_HANDLE(instanceHandle); + LAC_CHECK_NULL_PARAM(pKptStatus); +#endif + SAL_RUNNING_CHECK(instanceHandle); + + *pKptStatus = CPA_CY_KPT_FAILED; + SAL_CHECK_INSTANCE_CRYPTO_CAPABILITY(instanceHandle, kpt); + + status = LacKpt_Pro_SendRequest(instanceHandle, + KPT_PRO_DEL_SWK_CMD, + &keyHandle, + NULL, + NULL, + pKptStatus); + + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR1("Failed to send key deletion request, error code: %d\n", + status); + return status; + } + + if (CPA_STATUS_SUCCESS != *pKptStatus) + { + + LAC_LOG_ERROR1("Failed to delete key from device, error code: %d \n", + *pKptStatus); + } + +#ifdef ICP_TRACE + LAC_LOG4("Called with params (0x%lx, 0x%lx, 0x%lx[%d])\n", + (LAC_ARCH_UINT)instanceHandle, + (LAC_ARCH_UINT)&keyHandle, + (LAC_ARCH_UINT)pKptStatus, + *pKptStatus); +#endif + return CPA_STATUS_SUCCESS; } diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym.h b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym.h index 08e0f1de..1e7437d2 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym.h @@ -310,6 +310,9 @@ typedef struct icp_qat_la_auth_req_params_s uint8_t aad_sz; /**< Size in bytes of padded AAD data to prefix to the packet for CCM * or GCM processing */ + uint8_t hmac_key_sz; + /**< Size in bytes of HMAC key */ + } u2; uint8_t resrvd1; diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_cipher_defs.h b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_cipher_defs.h index fc1ae6e4..6e41eea5 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_cipher_defs.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_cipher_defs.h @@ -150,16 +150,6 @@ /* Macro to check if the algorithm is ZUC EEA3 */ #define LAC_CIPHER_IS_ZUC_EEA3(algo) (algo == CPA_CY_SYM_CIPHER_ZUC_EEA3) -/* Macro to check if the algorithm is ZUC-128 EEA3 */ -#define LAC_CIPHER_IS_ZUC_128_EEA3(algo, keySize) \ - ((algo == CPA_CY_SYM_CIPHER_ZUC_EEA3) && \ - (keySize == ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ)) - -/* Macro to check if the algorithm is ZUC-256 */ -#define LAC_CIPHER_IS_ZUC_256(algo, keySize) \ - ((algo == CPA_CY_SYM_CIPHER_ZUC_EEA3) && \ - (keySize == ICP_QAT_HW_ZUC_256_KEY_SZ)) - /* Macro to check if the algorithm is NULL */ #define LAC_CIPHER_IS_NULL(algo) (algo == CPA_CY_SYM_CIPHER_NULL) diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_hash.h b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_hash.h index d52ecb30..a43ae18b 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_hash.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_sym_hash.h @@ -414,6 +414,33 @@ CpaStatus LacHash_StatePrefixAadBufferInit( Cpa8U *pHashStateBuffer, lac_sym_qat_hash_state_buffer_info_t *pHashStateBufferInfo); +/** + ****************************************************************************** + * @ingroup LacHash + * Populates the hmac key for QAT Hash mode 2 + * + * @description + * This function populates the hmac key for qatHash mode 2. + * + * @param[in] pService Pointer to service data + * @param[in] pHashSetupData Pointer to hash setup structure + * @param[in] pReq Pointer to 128B request block. + * @param[in] qatHashMode QAT hash mode + * @param[in] pHmacKeyBuffer Pointer to hmac key buffer + * @param[in] pHmacKeyBufferInfo Pointer to hmac key buffer info + * + * @retval CPA_STATUS_SUCCESS Success + * @retval CPA_STATUS_FAIL Operation failed + * + *****************************************************************************/ +CpaStatus LacHash_PopulateHmacKey( + sal_service_t *pService, + const CpaCySymHashSetupData *pHashSetupData, + icp_qat_la_bulk_req_ftr_t *pReq, + icp_qat_hw_auth_mode_t qatHashMode, + Cpa8U *pHashStateBuffer, + lac_sym_qat_hash_state_buffer_info_t *pHashStateBufferInfo); + /** ******************************************************************************* * @ingroup LacHash diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/key/lac_sym_key.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/key/lac_sym_key.c index 7c09198f..ea2eb46a 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/key/lac_sym_key.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/key/lac_sym_key.c @@ -33,7 +33,6 @@ ******************************************************************************* */ #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "lac_sym.h" @@ -417,6 +416,10 @@ CpaStatus cpaCyKeyGenQueryStats(CpaInstanceHandle instanceHandle_in, #endif SAL_RUNNING_CHECK(instanceHandle); + if (IS_GEN6_DEV(instanceHandle)) + { + return CPA_STATUS_UNSUPPORTED; + } LAC_KEY_STATS32_GET(*pSymKeyStats, instanceHandle); return CPA_STATUS_SUCCESS; @@ -452,6 +455,10 @@ CpaStatus cpaCyKeyGenQueryStats64(CpaInstanceHandle instanceHandle_in, #endif SAL_RUNNING_CHECK(instanceHandle); + if (IS_GEN6_DEV(instanceHandle)) + { + return CPA_STATUS_UNSUPPORTED; + } LAC_KEY_STATS64_GET(*pSymKeyStats, instanceHandle); return CPA_STATUS_SUCCESS; @@ -620,6 +627,10 @@ STATIC CpaStatus LacSymKey_MgfSync(const CpaInstanceHandle instanceHandle, CpaStatus status = CPA_STATUS_SUCCESS; lac_sync_op_data_t *pSyncCallbackData = NULL; + if (IS_GEN6_DEV(instanceHandle)) + { + return CPA_STATUS_UNSUPPORTED; + } status = LacSync_CreateSyncCookie(&pSyncCallbackData); if (CPA_STATUS_SUCCESS == status) @@ -774,6 +785,10 @@ LacSymKey_MgfCommon(const CpaInstanceHandle instanceHandle, #endif SAL_RUNNING_CHECK(instanceHandle); + if (IS_GEN6_DEV(instanceHandle)) + { + return CPA_STATUS_UNSUPPORTED; + } #ifdef ICP_PARAM_CHECK LAC_CHECK_NULL_PARAM(pOpData); LAC_CHECK_NULL_PARAM(pKeyGenMgfOpData); @@ -2567,6 +2582,10 @@ LacSymKey_KeyGenSslTls(const CpaInstanceHandle instanceHandle_in, (SAL_SERVICE_TYPE_CRYPTO | SAL_SERVICE_TYPE_CRYPTO_SYM)); #endif SAL_RUNNING_CHECK(instanceHandle); + if (IS_GEN6_DEV(instanceHandle)) + { + return CPA_STATUS_UNSUPPORTED; + } if ((ICP_QAT_FW_LA_CMD_HKDF_EXTRACT <= cmdId) && (ICP_QAT_FW_LA_CMD_HKDF_EXTRACT_AND_EXPAND_LABEL >= cmdId)) { diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_alg_chain.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_alg_chain.c index 62aef0b0..6c9aeaeb 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_alg_chain.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_alg_chain.c @@ -27,7 +27,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" /* ******************************************************************************* @@ -791,6 +790,7 @@ static void buildCmdData(lac_session_desc_t *pSessionDesc, break; case CPA_CY_SYM_CIPHER_ZUC_EEA3: *proto = ICP_QAT_FW_LA_ZUC_3G_PROTO; + /* fall through */ case CPA_CY_SYM_CIPHER_AES_F8: ICP_QAT_FW_USE_WCP_SLICE_SET(*laExtCmdFlags, QAT_LA_USE_WCP_SLICE); @@ -1016,7 +1016,7 @@ static void updateLaCmdFlags(lac_session_desc_t *pSessionDesc, /* Legacy FW <=> IA interface */ else if (!extServFlagEnabled && ((CPA_CY_SYM_CIPHER_ZUC_EEA3 == pSessionDesc->cipherAlgorithm) || - (CPA_CY_SYM_HASH_ZUC_EIA3 == pSessionDesc->hashAlgorithm))) + (CPA_CY_SYM_HASH_ZUC_EIA3 == pSessionDesc->hashAlgorithm))) { /* New bit position (12) for ZUC. The FW provides a specific macro * to use to set the ZUC proto flag. With the new FW I/F this needs @@ -1668,7 +1668,11 @@ CpaStatus LacAlgChain_SessionInit( else /* CPA_CY_SYM_HASH_MODE_AUTH && anything except CPA_CY_SYM_HASH_AES_CBC_MAC */ { - if (IS_HMAC_ALG(pHashData->hashAlgorithm)) + if (IS_GEN6_DEV(instanceHandle)) + { + pSessionDesc->qatHashMode = ICP_QAT_HW_AUTH_MODE2; + } + else if (IS_HMAC_ALG(pHashData->hashAlgorithm)) { /* SHA3 HMAC do not support precompute, force MODE2 * for AUTH */ @@ -1829,6 +1833,10 @@ CpaStatus LacAlgChain_SessionInit( &hwBlockOffsetInDRAM, pOptimisedHwBlockBaseInDRAM, &optimisedHwBlockOffsetInDRAM); + if (IS_GEN6_DEV(instanceHandle)) + { + hwBlockOffsetInDRAM = 0; + } LacAlgChain_CipherCDBuild(pCipherData, pSessionDesc, ICP_QAT_FW_SLICE_DRAM_WR, @@ -1948,6 +1956,18 @@ CpaStatus LacAlgChain_SessionInit( LAC_CHECK_64_BYTE_ALIGNMENT( &(pSessionDesc->hashStatePrefixBuffer[0])); #endif + /* Populate HMAC key in case of GEN6 */ + if (IS_GEN6_DEV(instanceHandle)) + { + status = + LacHash_PopulateHmacKey(&(pService->generic_service_info), + pHashData, + &(pSessionDesc->reqCacheFtr), + pSessionDesc->qatHashMode, + pSessionDesc->hashStatePrefixBuffer, + pHashStateBufferInfo); + } + else { status = LacHash_StatePrefixAadBufferInit( &(pService->generic_service_info), @@ -2200,8 +2220,12 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, pCdInfo = &(pSessionDesc->contentDescInfo); pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData; - if (CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT == - pSessionDesc->cipherDirection) + /* For Gen6 AES-GCM and CHACHA-POLY is handled by UCS engine as + * Cipher operation. Hence configuration offset in DRAM is + * expected at initial offset even in Decryption direction */ + if ((CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT == + pSessionDesc->cipherDirection) && + !pService->generic_service_info.isGen6) { if (LAC_CIPHER_IS_GCM(cipher)) hwBlockOffsetInDRAM = LAC_QUADWORDS_TO_BYTES( @@ -2691,6 +2715,10 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, pCipher20ReqParams->spc_auth_res_sz = (Cpa8U)pSessionDesc->hashResultSize; } + /* Digest truncation is not supported on GEN6 + * so digest len will be ignored by the FW and + * should be set to 0. + */ } else { diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_api.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_api.c index 7330a984..f93ac8c4 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_api.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_api.c @@ -32,7 +32,6 @@ #include "icp_adf_transport.h" #include "icp_adf_transport_dp.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_qat_fw_la.h" /* @@ -102,6 +101,20 @@ CPA_CY_SYM_HASH_ZUC_EIA3 == hashAlgorithm)) && \ !extAlgchainSupported) +#define LAC_CHECK_COMBINATIONS(firstExpression, secondExpression) \ + ((firstExpression && !secondExpression) || \ + (!firstExpression && secondExpression)) + +#define LAC_CHECK_MANDATORY_ALGO_COMBINATION( \ + cipherExpression, hashExpression, algoName) \ + if (LAC_CHECK_COMBINATIONS(cipherExpression, hashExpression)) \ + { \ + LAC_INVALID_PARAM_LOG1("Invalid combination of Cipher/Hash " \ + "algorithms for %s", \ + algoName); \ + return CPA_STATUS_INVALID_PARAM; \ + } + #define CIPHER_INCL_MASK \ ((1U << CPA_CY_SYM_CIPHER_AES_CCM) | (1U << CPA_CY_SYM_CIPHER_AES_GCM)) @@ -202,12 +215,18 @@ LacSymSession_CapabilityCheck(const CpaInstanceHandle instanceHandle, CpaBoolean extAlgchainSupported = CPA_FALSE; CpaCyCapabilitiesInfo cyCapInfo = { 0 }; Cpa32U mask = ((sal_service_t *)instanceHandle)->capabilitiesMask; + sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle; /* initialize convenient pointers to cipher and hash contexts */ const CpaCySymCipherSetupData *const pCipherSetupData = (const CpaCySymCipherSetupData *)&pSessionSetupData->cipherSetupData; const CpaCySymHashSetupData *const pHashSetupData = &pSessionSetupData->hashSetupData; + CpaCySymCipherAlgorithm cipherAlgorithm = pCipherSetupData->cipherAlgorithm; + CpaCySymHashAlgorithm hashAlgorithm = pHashSetupData->hashAlgorithm; + Cpa32U cipherKeyLenInBytes = pCipherSetupData->cipherKeyLenInBytes; + Cpa32U authKeyLenInBytes = + pHashSetupData->authModeSetupData.authKeyLenInBytes; status = SalCtrl_CySymQueryCapabilities(instanceHandle, &symCapInfo); LAC_CHECK_STATUS(status); @@ -215,75 +234,76 @@ LacSymSession_CapabilityCheck(const CpaInstanceHandle instanceHandle, SalCtrl_CyQueryCapabilities(instanceHandle, &cyCapInfo); extAlgchainSupported = cyCapInfo.extAlgchainSupported; + if ((ICP_QAT_HW_AES_192_KEY_SZ == authKeyLenInBytes || + ICP_QAT_HW_AES_192_KEY_SZ == cipherKeyLenInBytes) && + IS_GEN6_DEV(pService)) + { + LAC_UNSUPPORTED_PARAM_LOG("AES 192-bit key size is not supported"); + return CPA_STATUS_UNSUPPORTED; + } /* Ensure cipher algorithm is correct and supported */ if ((CPA_CY_SYM_OP_ALGORITHM_CHAINING == pSessionSetupData->symOperation) || (CPA_CY_SYM_OP_CIPHER == pSessionSetupData->symOperation)) { - if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, - pCipherSetupData->cipherAlgorithm)) + if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, cipherAlgorithm)) { LAC_UNSUPPORTED_PARAM_LOG("UnSupported cipherAlgorithm"); return CPA_STATUS_UNSUPPORTED; } - if (pCipherSetupData->cipherAlgorithm == CPA_CY_SYM_CIPHER_ZUC_EEA3) - { - if (!(mask & ICP_ACCEL_CAPABILITIES_ZUC_256) && - (pCipherSetupData->cipherKeyLenInBytes == - ICP_QAT_HW_ZUC_256_KEY_SZ)) - { - LAC_UNSUPPORTED_PARAM_LOG( - "Cipher algorithm ZUC_256 is unsupported."); - return CPA_STATUS_UNSUPPORTED; - } - } } /* Ensure hash algorithm is correct and supported */ if ((CPA_CY_SYM_OP_ALGORITHM_CHAINING == pSessionSetupData->symOperation) || (CPA_CY_SYM_OP_HASH == pSessionSetupData->symOperation)) { - if (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, - pHashSetupData->hashAlgorithm)) + if (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, hashAlgorithm)) { LAC_UNSUPPORTED_PARAM_LOG("UnSupported hash Algorithm"); return CPA_STATUS_UNSUPPORTED; } - if (pHashSetupData->hashAlgorithm == CPA_CY_SYM_HASH_AES_CMAC) + if (CPA_CY_SYM_HASH_AES_CMAC == hashAlgorithm) { if (!(mask & ICP_ACCEL_CAPABILITIES_WIRELESS_CRYPTO_EXT) && - (pHashSetupData->authModeSetupData.authKeyLenInBytes == - ICP_QAT_HW_AES_192_KEY_SZ || - pHashSetupData->authModeSetupData.authKeyLenInBytes == - ICP_QAT_HW_AES_256_KEY_SZ)) + (ICP_QAT_HW_AES_192_KEY_SZ == authKeyLenInBytes || + ICP_QAT_HW_AES_256_KEY_SZ == authKeyLenInBytes)) { - LAC_INVALID_PARAM_LOG("Hash algorithm AES_CMAC with 192/256" - "bits key is unsupported."); + LAC_UNSUPPORTED_PARAM_LOG("Hash algorithm AES_CMAC with 192/256" + "bits key is unsupported."); return CPA_STATUS_UNSUPPORTED; } } - if (pHashSetupData->hashAlgorithm == CPA_CY_SYM_HASH_ZUC_EIA3) + if (CPA_CY_SYM_HASH_ZUC_EIA3 == hashAlgorithm) { if (!(mask & ICP_ACCEL_CAPABILITIES_ZUC_256) && - (pHashSetupData->authModeSetupData.authKeyLenInBytes == - ICP_QAT_HW_ZUC_256_KEY_SZ)) + (ICP_QAT_HW_ZUC_256_KEY_SZ == authKeyLenInBytes)) { LAC_UNSUPPORTED_PARAM_LOG( - "Hash algorithm ZUC_256 is unsupported."); + "Hash algorithm ZUC_EIA3 with 256-bit key is unsupported."); return CPA_STATUS_UNSUPPORTED; } } } - /* Ensure CCM, GCM, Kasumi, Snow3G and ZUC cipher and hash algorithms are - * selected together for Algorithm Chaining */ if (CPA_CY_SYM_OP_ALGORITHM_CHAINING == pSessionSetupData->symOperation) { - if (IS_EXT_ALG_CHAIN_UNSUPPORTED(pCipherSetupData->cipherAlgorithm, - pHashSetupData->hashAlgorithm, - extAlgchainSupported)) + if (IS_EXT_ALG_CHAIN_UNSUPPORTED( + cipherAlgorithm, hashAlgorithm, extAlgchainSupported)) { LAC_UNSUPPORTED_PARAM_LOG("ExtAlgChain feature not supported"); return CPA_STATUS_UNSUPPORTED; } + + if (IS_GEN6_DEV(instanceHandle)) + { + /* Cipher+hash or hash+cipher chaining combinations are not + * supported with Gen6 HW configuration. */ + if ((CPA_CY_SYM_CIPHER_AES_CTR == cipherAlgorithm) || + (CPA_CY_SYM_CIPHER_AES_XTS == cipherAlgorithm)) + { + LAC_UNSUPPORTED_PARAM_LOG( + "Chaining is unsupported on this instance"); + return CPA_STATUS_UNSUPPORTED; + } + } } return CPA_STATUS_SUCCESS; } @@ -315,6 +335,8 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, (const CpaCySymCipherSetupData *)&pSessionSetupData->cipherSetupData; const CpaCySymHashSetupData *const pHashSetupData = &pSessionSetupData->hashSetupData; + CpaCySymCipherAlgorithm cipherAlgorithm = pCipherSetupData->cipherAlgorithm; + CpaCySymHashAlgorithm hashAlgorithm = pHashSetupData->hashAlgorithm; if ((CPA_CY_SYM_OP_ALGORITHM_CHAINING == pSessionSetupData->symOperation) || (CPA_CY_SYM_OP_CIPHER == pSessionSetupData->symOperation)) @@ -322,8 +344,7 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, /* Protect against value of cipher outside the bitmap * and check if cipher algorithm is correct */ - if (pCipherSetupData->cipherAlgorithm >= - CPA_CY_SYM_CIPHER_CAP_BITMAP_SIZE) + if (cipherAlgorithm >= CPA_CY_SYM_CIPHER_CAP_BITMAP_SIZE) { LAC_INVALID_PARAM_LOG("Cipher algorithm is invalid"); return CPA_STATUS_INVALID_PARAM; @@ -336,7 +357,7 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, /* Protect against value of hash outside the bitmap * and check if hash algorithm is correct */ - if (pHashSetupData->hashAlgorithm >= CPA_CY_SYM_HASH_CAP_BITMAP_SIZE) + if (hashAlgorithm >= CPA_CY_SYM_HASH_CAP_BITMAP_SIZE) { LAC_INVALID_PARAM_LOG("Hash algorithm is invalid"); return CPA_STATUS_INVALID_PARAM; @@ -348,65 +369,31 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, switch (pSessionSetupData->symOperation) { case CPA_CY_SYM_OP_ALGORITHM_CHAINING: - /* Ensure that both hash and cipher algorithms are - * POLY and CHACHA. - */ - if (((CPA_CY_SYM_CIPHER_CHACHA == - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_HASH_POLY != pHashSetupData->hashAlgorithm)) || - ((CPA_CY_SYM_HASH_POLY == pHashSetupData->hashAlgorithm) && - (CPA_CY_SYM_CIPHER_CHACHA != - pCipherSetupData->cipherAlgorithm))) - { - LAC_INVALID_PARAM_LOG("Invalid combination of Cipher/Hash " - "algorithms for CHACHA/POLY"); - return CPA_STATUS_INVALID_PARAM; - } - - /* Ensure that both hash and cipher algorithms are CCM */ - if (((CPA_CY_SYM_CIPHER_AES_CCM == - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_HASH_AES_CCM != pHashSetupData->hashAlgorithm)) || - ((CPA_CY_SYM_HASH_AES_CCM == pHashSetupData->hashAlgorithm) && - (CPA_CY_SYM_CIPHER_AES_CCM != - pCipherSetupData->cipherAlgorithm))) - { - LAC_INVALID_PARAM_LOG( - "Invalid combination of Cipher/Hash algorithms for CCM"); - return CPA_STATUS_INVALID_PARAM; - } - - /* Ensure that both hash and cipher algorithms are GCM/GMAC */ - if ((CPA_CY_SYM_CIPHER_AES_GCM == - pCipherSetupData->cipherAlgorithm && - (CPA_CY_SYM_HASH_AES_GCM != pHashSetupData->hashAlgorithm && - CPA_CY_SYM_HASH_AES_GMAC != pHashSetupData->hashAlgorithm)) || - ((CPA_CY_SYM_HASH_AES_GCM == pHashSetupData->hashAlgorithm || - CPA_CY_SYM_HASH_AES_GMAC == pHashSetupData->hashAlgorithm) && - CPA_CY_SYM_CIPHER_AES_GCM != - pCipherSetupData->cipherAlgorithm)) - { - LAC_INVALID_PARAM_LOG( - "Invalid combination of Cipher/Hash algorithms for GCM"); - return CPA_STATUS_INVALID_PARAM; - } - /* Ensure that both hash and cipher algorithms are Kasumi */ - if (((CPA_CY_SYM_CIPHER_KASUMI_F8 == - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_HASH_KASUMI_F9 != - pHashSetupData->hashAlgorithm)) || - ((CPA_CY_SYM_HASH_KASUMI_F9 == pHashSetupData->hashAlgorithm) && - (CPA_CY_SYM_CIPHER_KASUMI_F8 != - pCipherSetupData->cipherAlgorithm))) - { - LAC_INVALID_PARAM_LOG( - "Invalid combination of Cipher/Hash algorithms for Kasumi"); - return CPA_STATUS_INVALID_PARAM; - } + LAC_CHECK_MANDATORY_ALGO_COMBINATION( + (CPA_CY_SYM_CIPHER_CHACHA == cipherAlgorithm), + (CPA_CY_SYM_HASH_POLY == hashAlgorithm), + "CHACHA/POLY"); + LAC_CHECK_MANDATORY_ALGO_COMBINATION( + (CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm), + (CPA_CY_SYM_HASH_AES_CCM == hashAlgorithm), + "CCM"); + LAC_CHECK_MANDATORY_ALGO_COMBINATION( + (CPA_CY_SYM_CIPHER_KASUMI_F8 == cipherAlgorithm), + (CPA_CY_SYM_HASH_KASUMI_F9 == hashAlgorithm), + "Kasumi"); + LAC_CHECK_MANDATORY_ALGO_COMBINATION( + (CPA_CY_SYM_CIPHER_AES_GCM == cipherAlgorithm), + ((CPA_CY_SYM_HASH_AES_GCM == hashAlgorithm) || + (CPA_CY_SYM_HASH_AES_GMAC == hashAlgorithm)), + "GCM"); + + /* Remaining checks apply only to pre-Gen6 devices */ + if (IS_GEN6_DEV(instanceHandle)) + break; /* Ensure that algorithm chaining operation is performed for - * supported wireless algorithms. + * supported wireless algorithms for Gen4 QAT devices. * * The following are supported algorithm chaining cipher + hash * combinations. Any cipher from the below list can be mixed with @@ -415,43 +402,33 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, * Ciphers: Snow3g_UEA2, ZUC_EEA3, AES_CTR, NULL_CIPHER. * Hash: Snow3g_UIA2, ZUC_EIA3, AES_CMAC. */ - if ((CPA_CY_SYM_CIPHER_SNOW3G_UEA2 == - pCipherSetupData->cipherAlgorithm) || - (CPA_CY_SYM_CIPHER_ZUC_EEA3 == - pCipherSetupData->cipherAlgorithm)) + if ((CPA_CY_SYM_CIPHER_SNOW3G_UEA2 == cipherAlgorithm) || + (CPA_CY_SYM_CIPHER_ZUC_EEA3 == cipherAlgorithm)) { - if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 != - pHashSetupData->hashAlgorithm) && - (CPA_CY_SYM_HASH_ZUC_EIA3 != - pHashSetupData->hashAlgorithm) && - (CPA_CY_SYM_HASH_AES_CMAC != pHashSetupData->hashAlgorithm)) + if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 != hashAlgorithm) && + (CPA_CY_SYM_HASH_ZUC_EIA3 != hashAlgorithm) && + (CPA_CY_SYM_HASH_AES_CMAC != hashAlgorithm)) { LAC_INVALID_PARAM_LOG2("Invalid algorithm chaining " "combination, cipher: %d, hash: %d", - pCipherSetupData->cipherAlgorithm, - pHashSetupData->hashAlgorithm); + cipherAlgorithm, + hashAlgorithm); return CPA_STATUS_INVALID_PARAM; } } - else if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 == - pHashSetupData->hashAlgorithm) || - (CPA_CY_SYM_HASH_ZUC_EIA3 == - pHashSetupData->hashAlgorithm)) + else if ((CPA_CY_SYM_HASH_SNOW3G_UIA2 == hashAlgorithm) || + (CPA_CY_SYM_HASH_ZUC_EIA3 == hashAlgorithm)) { - if ((CPA_CY_SYM_CIPHER_SNOW3G_UEA2 != - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_CIPHER_ZUC_EEA3 != - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_CIPHER_AES_CTR != - pCipherSetupData->cipherAlgorithm) && - (CPA_CY_SYM_CIPHER_NULL != - pCipherSetupData->cipherAlgorithm)) + if ((CPA_CY_SYM_CIPHER_SNOW3G_UEA2 != cipherAlgorithm) && + (CPA_CY_SYM_CIPHER_ZUC_EEA3 != cipherAlgorithm) && + (CPA_CY_SYM_CIPHER_AES_CTR != cipherAlgorithm) && + (CPA_CY_SYM_CIPHER_NULL != cipherAlgorithm)) { LAC_INVALID_PARAM_LOG2("Invalid algorithm chaining " - "combination, hash: %d, cipher: %d", - pHashSetupData->hashAlgorithm, - pCipherSetupData->cipherAlgorithm); + "combination, cipher: %d, hash: %d", + cipherAlgorithm, + hashAlgorithm); return CPA_STATUS_INVALID_PARAM; } @@ -459,11 +436,9 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, break; case CPA_CY_SYM_OP_CIPHER: /* Ensure that cipher algorithm is not CCM, CHACHA or GCM */ - if ((CPA_CY_SYM_CIPHER_AES_CCM == - pCipherSetupData->cipherAlgorithm) || - (CPA_CY_SYM_CIPHER_AES_GCM == - pCipherSetupData->cipherAlgorithm) || - (CPA_CY_SYM_CIPHER_CHACHA == pCipherSetupData->cipherAlgorithm)) + if ((CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm) || + (CPA_CY_SYM_CIPHER_AES_GCM == cipherAlgorithm) || + (CPA_CY_SYM_CIPHER_CHACHA == cipherAlgorithm)) { LAC_INVALID_PARAM_LOG("Invalid algorithm for cipher operation"); return CPA_STATUS_INVALID_PARAM; @@ -471,10 +446,10 @@ LacSymSession_ParamCheck(const CpaInstanceHandle instanceHandle, break; case CPA_CY_SYM_OP_HASH: /* Ensure that hash algorithm is not CCM, POLY or GCM/GMAC */ - if ((CPA_CY_SYM_HASH_AES_CCM == pHashSetupData->hashAlgorithm) || - (CPA_CY_SYM_HASH_AES_GCM == pHashSetupData->hashAlgorithm) || - (CPA_CY_SYM_HASH_AES_GMAC == pHashSetupData->hashAlgorithm) || - (CPA_CY_SYM_HASH_POLY == pHashSetupData->hashAlgorithm)) + if ((CPA_CY_SYM_HASH_AES_CCM == hashAlgorithm) || + (CPA_CY_SYM_HASH_AES_GCM == hashAlgorithm) || + (CPA_CY_SYM_HASH_AES_GMAC == hashAlgorithm) || + (CPA_CY_SYM_HASH_POLY == hashAlgorithm)) { LAC_INVALID_PARAM_LOG("Invalid algorithm for hash operation"); return CPA_STATUS_INVALID_PARAM; @@ -1136,6 +1111,15 @@ STATIC CpaStatus LacSym_Perform(const CpaInstanceHandle instanceHandle, LacSync_DestroySyncCookie(&pSyncCallbackData); return status; } + if (CPA_CY_SYM_PACKET_TYPE_FULL != pOpData->packetType) + { + if (((sal_service_t *)instanceHandle)->isGen6) + { + LAC_UNSUPPORTED_PARAM_LOG( + "Partial packets are not supported on Gen6"); + return CPA_STATUS_UNSUPPORTED; + } + } #ifdef ICP_PARAM_CHECK status = LacSymPerform_BufferParamCheck( diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_auth_enc.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_auth_enc.c index 9dd46cf7..a6b1f80e 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_auth_enc.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_auth_enc.c @@ -34,7 +34,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" /* ******************************************************************************* * Include private header files diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cb.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cb.c index fcf290b7..f9975027 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cb.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cb.c @@ -30,7 +30,6 @@ #include "icp_adf_init.h" #include "icp_qat_fw_la.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" #include "lac_sym.h" #include "lac_sym_cipher.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cipher.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cipher.c index 34ea79c5..a04dbf26 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cipher.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_cipher.c @@ -28,7 +28,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_qat_fw_la.h" @@ -91,11 +90,18 @@ CpaStatus LacCipher_PerformIvCheck(sal_service_t *pService, case CPA_CY_SYM_CIPHER_AES_XTS: case CPA_CY_SYM_CIPHER_SM4_CBC: case CPA_CY_SYM_CIPHER_SM4_CTR: + case CPA_CY_SYM_CIPHER_ZUC_EEA3: { #ifdef ICP_PARAM_CHECK ivLenInBytes = LacSymQat_CipherIvSizeBytesGet(algorithm); LAC_CHECK_NULL_PARAM(pOpData->pIv); - if (pOpData->ivLenInBytes != ivLenInBytes) + if (pService->isGen6 && isGcm && + pOpData->ivLenInBytes != LAC_CIPHER_IV_SIZE_GCM_12) + { + LAC_INVALID_PARAM_LOG("Invalid GCM single pass IV size"); + return CPA_STATUS_INVALID_PARAM; + } + else if (pOpData->ivLenInBytes != ivLenInBytes) { /* GCM with 12 byte IV is supported */ if (!((isGcm && @@ -221,20 +227,6 @@ CpaStatus LacCipher_PerformIvCheck(sal_service_t *pService, } } break; - case CPA_CY_SYM_CIPHER_ZUC_EEA3: - { -#ifdef ICP_PARAM_CHECK - LAC_CHECK_NULL_PARAM(pOpData->pIv); - if ((pOpData->ivLenInBytes != ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ) && - (pOpData->ivLenInBytes != ICP_QAT_HW_ZUC_256_IV_SZ)) - { - LAC_INVALID_PARAM_LOG("invalid cipher IV size"); - return CPA_STATUS_INVALID_PARAM; - } -#endif - *ppIvBuffer = pOpData->pIv; - } - break; default: *ppIvBuffer = NULL; } @@ -355,13 +347,10 @@ CpaStatus LacCipher_SessionSetupDataCheck( } break; case CPA_CY_SYM_CIPHER_ZUC_EEA3: - /* ZUC EEA3 */ - if ((pCipherSetupData->cipherKeyLenInBytes != - ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ) && - (pCipherSetupData->cipherKeyLenInBytes != - ICP_QAT_HW_ZUC_256_KEY_SZ)) + if (pCipherSetupData->cipherKeyLenInBytes != + ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ) { - LAC_INVALID_PARAM_LOG("Invalid ZUC cipher key length"); + LAC_INVALID_PARAM_LOG("Invalid ZUC-128 cipher key length"); return CPA_STATUS_INVALID_PARAM; } break; @@ -476,6 +465,11 @@ Cpa32U LacCipher_GetCipherSliceType(sal_service_t *pService, Cpa32U sliceType = ICP_QAT_FW_LA_USE_LEGACY_SLICE_TYPE; Cpa32U capabilitiesMask = pService->capabilitiesMask; + if (pService->isGen6) + { + return ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE; + } + switch (cipherAlgorithm) { case CPA_CY_SYM_CIPHER_AES_XTS: diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_compile_check.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_compile_check.c index 7dc05f45..ecd2be04 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_compile_check.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_compile_check.c @@ -24,7 +24,6 @@ #include "lac_common.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_sym.h" #include "cpa_cy_sym_dp.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_dp.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_dp.c index d0f2e797..cb90978f 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_dp.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_dp.c @@ -36,7 +36,6 @@ #include "icp_adf_init.h" #include "icp_adf_transport.h" #include "icp_adf_transport_dp.h" -#include "icp_adf_debug.h" #include "icp_sal_poll.h" #include "lac_mem.h" @@ -180,10 +179,18 @@ STATIC CpaStatus LacDp_EnqueueParamCheck(const CpaCySymDpOpData *pRequest) case CPA_CY_SYM_CIPHER_AES_F8: case CPA_CY_SYM_CIPHER_SM4_CTR: case CPA_CY_SYM_CIPHER_SM4_CBC: + case CPA_CY_SYM_CIPHER_ZUC_EEA3: { Cpa32U ivLenInBytes = LacSymQat_CipherIvSizeBytesGet( pSessionDesc->cipherAlgorithm); - if (pRequest->ivLenInBytes != ivLenInBytes) + if (IS_GEN6_DEV(pRequest->instanceHandle) && + LAC_CIPHER_IS_GCM(pSessionDesc->cipherAlgorithm) && + pRequest->ivLenInBytes != LAC_CIPHER_IV_SIZE_GCM_12) + { + LAC_INVALID_PARAM_LOG("Invalid GCM single pass IV size"); + return CPA_STATUS_INVALID_PARAM; + } + else if (pRequest->ivLenInBytes != ivLenInBytes) { if (!(/* GCM with 12 byte IV is OK */ (LAC_CIPHER_IS_GCM(pSessionDesc->cipherAlgorithm) && @@ -230,28 +237,6 @@ STATIC CpaStatus LacDp_EnqueueParamCheck(const CpaCySymDpOpData *pRequest) } } break; - case CPA_CY_SYM_CIPHER_ZUC_EEA3: - { - if ((ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ != pRequest->ivLenInBytes) && - (ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ == - pSessionDesc->cipherKeyLenInBytes)) - { - LAC_INVALID_PARAM_LOG("invalid cipher IV size"); - return CPA_STATUS_INVALID_PARAM; - } - if ((ICP_QAT_HW_ZUC_256_IV_SZ != pRequest->ivLenInBytes) && - (ICP_QAT_HW_ZUC_256_KEY_SZ == pSessionDesc->cipherKeyLenInBytes)) - { - LAC_INVALID_PARAM_LOG("invalid cipher IV size"); - return CPA_STATUS_INVALID_PARAM; - } - if (0 == pRequest->iv) - { - LAC_INVALID_PARAM_LOG("invalid iv of 0"); - return CPA_STATUS_INVALID_PARAM; - } - } - break; case CPA_CY_SYM_CIPHER_AES_CCM: { if (CPA_STATUS_SUCCESS != @@ -560,6 +545,16 @@ void LacDp_WriteRingMsgOpt(CpaCySymDpOpData *pRequest, LAC_QUADWORDS_TO_BYTES( pHashStateBufferInfo->stateStorageSzQuadWords); } + /* For Gen6, pRequest->additionalAuthData is reused for Hmac key, since + * the offset of Hmac key and additionalAuthData are the same in request + * descriptor. + */ + if (IS_GEN6_DEV(pSessionDesc->pInstance) && + pSessionDesc->qatHashMode == ICP_QAT_HW_AUTH_MODE2) + { + pRequest->additionalAuthData = + (pSessionDesc->hashStateBufferInfo.pDataPhys); + } /* The first 24 bytes in icp_qat_fw_la_auth_req_params_t can be * copied directly from the op request data because they share a * corresponding layout. The remaining 4 bytes are taken @@ -624,6 +619,8 @@ void LacDp_WriteRingMsgFull(CpaCySymDpOpData *pRequest, ->generic_service_info.capabilitiesMask; CpaBoolean isGen4 = ((sal_crypto_service_t *)pRequest->instanceHandle) ->generic_service_info.isGen4; + CpaBoolean isGen6 = ((sal_crypto_service_t *)pRequest->instanceHandle) + ->generic_service_info.isGen6; CpaBoolean isSpGcm = LAC_CIPHER_IS_SPC_GCM(cipher, hash, capabilitiesMask); CpaBoolean isSpCcp = LAC_CIPHER_IS_SPC_CCP(cipher, hash, capabilitiesMask); @@ -668,7 +665,8 @@ void LacDp_WriteRingMsgFull(CpaCySymDpOpData *pRequest, pCdInfo = &(pSessionDesc->contentDescInfo); pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData; if (CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT == - pSessionDesc->cipherDirection) + pSessionDesc->cipherDirection && + !isGen6) { if (LAC_CIPHER_IS_GCM(cipher)) hwBlockOffsetInDRAM = LAC_QUADWORDS_TO_BYTES( @@ -873,6 +871,10 @@ void LacDp_WriteRingMsgFull(CpaCySymDpOpData *pRequest, pCipher20ReqParams->spc_auth_res_sz = (Cpa8U)pSessionDesc->hashResultSize; } + /* Digest truncation is not supported on GEN6 + * so digest len will be ignored by the FW and + * should be set to 0. + */ /* Pad the AAD buffer to a blocklen multiple. * For ChaChaPoly and AES-GCM there is an AAD buffer if * aadLenInBytes is nonzero. For CCM there is always an AAD diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash.c index 9134db59..a71e6347 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash.c @@ -27,7 +27,6 @@ #include "cpa_cy_sym.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" /* ******************************************************************************* @@ -86,6 +85,49 @@ STATIC void LacHash_SyncPrecomputeDoneCb(void *pCallbackTag) LacSync_GenWakeupSyncCaller(pCallbackTag, CPA_STATUS_SUCCESS); } +/** @ingroup LacHash */ +CpaStatus LacHash_PopulateHmacKey( + sal_service_t *pService, + const CpaCySymHashSetupData *pHashSetupData, + icp_qat_la_bulk_req_ftr_t *pReq, + icp_qat_hw_auth_mode_t qatHashMode, + Cpa8U *pHashStateBuffer, + lac_sym_qat_hash_state_buffer_info_t *pHashStateBufferInfo) +{ + icp_qat_la_auth_req_params_t *pHashReqParams = + (icp_qat_la_auth_req_params_t *)(&(pReq->serv_specif_rqpars)); + Cpa8U padding = 0; + /* Populate HMAC key address for mode 2 auth, + * HMAC key should be 4 byte aligned for Gen6. + */ + if (IS_HASH_MODE_2_AUTH(qatHashMode, pHashSetupData->hashMode)) + { + pHashStateBufferInfo->pData = pHashStateBuffer; + pHashStateBufferInfo->pDataPhys = LAC_MEM_CAST_PTR_TO_UINT64( + LAC_OS_VIRT_TO_PHYS_EXTERNAL((*pService), pHashStateBuffer)); + if (pHashStateBufferInfo->pDataPhys == 0) + { + LAC_LOG_ERROR("Unable to get the physical address of " + "the HMAC key \n"); + return CPA_STATUS_FAIL; + } + osalMemCopy(pHashStateBufferInfo->pData, + pHashSetupData->authModeSetupData.authKey, + (Cpa8U)pHashSetupData->authModeSetupData.authKeyLenInBytes); + padding = pHashReqParams->u2.hmac_key_sz - + (Cpa8U)pHashSetupData->authModeSetupData.authKeyLenInBytes; + /* Reset with zeroes any area reserved for padding in this block */ + if (0 < padding) + { + LAC_OS_BZERO( + pHashStateBufferInfo->pData + + (Cpa8U)pHashSetupData->authModeSetupData.authKeyLenInBytes, + padding); + } + } + return CPA_STATUS_SUCCESS; +} + /** @ingroup LacHash */ CpaStatus LacHash_StatePrefixAadBufferInit( sal_service_t *pService, @@ -236,9 +278,9 @@ CpaStatus LacHash_PrecomputeDataCreate(const CpaInstanceHandle instanceHandle, case CPA_CY_SYM_HASH_AES_CMAC: /* First, copy the original key to pState2 */ osalMemCopy(pState2, pAuthKey, authKeyLenInBytes); - /* Then precompute */ if (authKeyLenInBytes == ICP_QAT_HW_AES_128_KEY_SZ) { + /* Then precompute */ status = LacSymHash_AesECBPreCompute(instanceHandle, hashAlgorithm, authKeyLenInBytes, @@ -345,7 +387,6 @@ CpaStatus LacHash_PrecomputeDataCreate(const CpaInstanceHandle instanceHandle, case CPA_CY_SYM_HASH_SNOW3G_UIA2: /* The Inner Hash Initial State2 should be all zeros. */ LAC_OS_BZERO(pState2, ICP_QAT_HW_SNOW_3G_UIA2_STATE2_SZ); - /* There is no request sent to the QAT for this operation, * so just invoke the user's callback directly to signal * completion of the precompute. @@ -360,10 +401,6 @@ CpaStatus LacHash_PrecomputeDataCreate(const CpaInstanceHandle instanceHandle, { LAC_OS_BZERO(pState2, ICP_QAT_HW_ZUC_3G_EIA3_STATE2_SZ); } - else - { - LAC_OS_BZERO(pState2, ICP_QAT_HW_ZUC_256_STATE2_SZ); - } osalMemCopy(pState2, pAuthKey, authKeyLenInBytes); /* There is no request sent to the QAT for this operation, * so just invoke the user's callback directly to signal @@ -428,6 +465,12 @@ CpaStatus LacHash_HashContextCheck(CpaInstanceHandle instanceHandle, case CPA_CY_SYM_HASH_MODE_AUTH: break; case CPA_CY_SYM_HASH_MODE_NESTED: + if (IS_GEN6_DEV(instanceHandle)) + { + LAC_UNSUPPORTED_PARAM_LOG( + "Unsupported hash mode for Gen6 device"); + return CPA_STATUS_UNSUPPORTED; + } break; default: @@ -458,7 +501,10 @@ CpaStatus LacHash_HashContextCheck(CpaInstanceHandle instanceHandle, /* Check Digest Length is permitted by the algorithm */ if ((0 == pHashSetupData->digestResultLenInBytes) || (pHashSetupData->digestResultLenInBytes > - pHashAlgInfo->digestLength)) + pHashAlgInfo->digestLength) || + ((pHashSetupData->digestResultLenInBytes != + pHashAlgInfo->digestLength) && + IS_GEN6_DEV(instanceHandle))) { LAC_INVALID_PARAM_LOG("digestResultLenInBytes"); return CPA_STATUS_INVALID_PARAM; @@ -606,11 +652,9 @@ CpaStatus LacHash_HashContextCheck(CpaInstanceHandle instanceHandle, else if (CPA_CY_SYM_HASH_ZUC_EIA3 == pHashSetupData->hashAlgorithm) { - /* QAT-FW only supports 128/256 bits Integrity Key size for ZUC */ - if ((pHashSetupData->authModeSetupData.authKeyLenInBytes != - ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ) && - (pHashSetupData->authModeSetupData.authKeyLenInBytes != - ICP_QAT_HW_ZUC_256_KEY_SZ)) + /* ZUC EIA3 only supports 128 bits Integrity Key size */ + if (pHashSetupData->authModeSetupData.authKeyLenInBytes != + ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ) { LAC_INVALID_PARAM_LOG("authKeyLenInBytes"); return CPA_STATUS_INVALID_PARAM; @@ -618,10 +662,8 @@ CpaStatus LacHash_HashContextCheck(CpaInstanceHandle instanceHandle, /* For ZUC EIA3 hash aad field contains IV - it needs to be 16 * bytes long */ - if ((pHashSetupData->authModeSetupData.aadLenInBytes != - ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ) && - (pHashSetupData->authModeSetupData.aadLenInBytes != - ICP_QAT_HW_ZUC_256_IV_SZ)) + if (pHashSetupData->authModeSetupData.aadLenInBytes != + ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ) { LAC_INVALID_PARAM_LOG("aadLenInBytes"); return CPA_STATUS_INVALID_PARAM; diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_hw_precomputes.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_hw_precomputes.c index 89a8c94b..44fb563f 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_hw_precomputes.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_hw_precomputes.c @@ -31,7 +31,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" #include "icp_qat_fw_la.h" /* diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_sw_precomputes.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_sw_precomputes.c index da1ae370..6031ccce 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_sw_precomputes.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_hash_sw_precomputes.c @@ -30,7 +30,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" /* ******************************************************************************* diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_partial.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_partial.c index ef583aae..6c42fcfb 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_partial.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_partial.c @@ -24,7 +24,6 @@ #include "cpa.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_sym.h" #include "cpa_cy_sym.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_queue.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_queue.c index ddd46b52..74b2847e 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_queue.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_queue.c @@ -31,7 +31,6 @@ */ #include "icp_accel_devices.h" #include "icp_adf_init.h" -#include "icp_adf_debug.h" #include "icp_adf_transport.h" #include "lac_sym_queue.h" #include "lac_sym_qat.h" diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_stats.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_stats.c index d43b4f1f..fff65f40 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_stats.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/lac_sym_stats.c @@ -32,7 +32,6 @@ #include "lac_mem_pools.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_qat_fw_la.h" #include "lac_sym_qat.h" #include "lac_sal_types_crypto.h" @@ -124,7 +123,7 @@ void LacSym_StatsShow(CpaInstanceHandle instanceHandle) osalLog(OSAL_LOG_LVL_USER, OSAL_LOG_DEV_STDOUT, SEPARATOR BORDER - " Symmetric Stats " BORDER + " Symmetric Stats " BORDER "\n" SEPARATOR); /* Session Info */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_cipher.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_cipher.c index cde179ba..39e638bc 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_cipher.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_cipher.c @@ -27,7 +27,6 @@ #include "cpa.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_sym_qat.h" #include "lac_sym_qat_cipher.h" #include "lac_mem.h" @@ -224,42 +223,7 @@ static const uint8_t key_size_f8[] = { 0, ICP_QAT_HW_CIPHER_ALGO_AES256 /* ICP_QAT_HW_AES_256_F8_KEY_SZ */ }; -/* LAC_CIPHER_IS_ZUC_EEA3 */ -static const uint8_t key_size_zuc_eea3[] = { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3, /* ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ICP_QAT_HW_CIPHER_ALGO_ZUC_256 /* ICP_QAT_HW_ZUC_256_KEY_SZ */ -}; + /* This array must be kept aligned with CpaCySymCipherAlgorithm enum but * offset by -1 as that enum starts at 1. LacSymQat_CipherGetCfgData() * below relies on that alignment and uses that enum -1 to index into this @@ -465,8 +429,8 @@ static const icp_qat_hw_cipher_info icp_qat_alg_info[] = { ICP_QAT_HW_CIPHER_ECB_MODE, { ICP_QAT_HW_CIPHER_KEY_CONVERT, ICP_QAT_HW_CIPHER_KEY_CONVERT }, { ICP_QAT_HW_CIPHER_ENCRYPT, ICP_QAT_HW_CIPHER_DECRYPT }, - IS_KEY_DEP_YES, - key_size_zuc_eea3, + IS_KEY_DEP_NO, + NULL, }, /* CPA_CY_SYM_CIPHER_CHACHA */ { @@ -556,9 +520,9 @@ void LacSymQat_CipherCtrlBlockWrite(lac_session_desc_t *pSessionDesc, LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_KASUMI_F8_KEY_SZ); cd_ctrl->cipher_padding_sz = ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR; break; - /* For Snow3G UEA2 content descriptor key size is - key size plus iv size */ case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: + /* For Snow3G UEA2 content descriptor key size is + key size plus iv size */ cd_ctrl->cipher_key_sz = LAC_BYTES_TO_QUADWORDS( ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ + ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); break; @@ -568,22 +532,25 @@ void LacSymQat_CipherCtrlBlockWrite(lac_session_desc_t *pSessionDesc, cd_ctrl->cipher_padding_sz = (2 * ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR); break; - /* For ZUC EEA3 content descriptor key size is - key size plus iv size */ case CPA_CY_SYM_CIPHER_ZUC_EEA3: - /* For ZUC-128 EEA3 and ZUC-256, the content descriptor - key size is key size plus iv size */ - if (ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ == targetKeyLenInBytes) { + /* For ZUC-128 EEA3 the content descriptor key size is key size + plus iv size */ cd_ctrl->cipher_key_sz = LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ + ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); } - /* ICP_QAT_HW_ZUC_256_KEY_SZ assumed */ + break; + case CPA_CY_SYM_CIPHER_AES_XTS: + if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE == sliceType) + { + cd_ctrl->cipher_key_sz = + LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes >> 1); + } else { - cd_ctrl->cipher_key_sz = LAC_BYTES_TO_QUADWORDS( - ICP_QAT_HW_ZUC_256_KEY_SZ + ICP_QAT_HW_ZUC_256_IV_SZ); + cd_ctrl->cipher_key_sz = + LAC_BYTES_TO_QUADWORDS(targetKeyLenInBytes); } break; default: @@ -596,13 +563,6 @@ void LacSymQat_CipherCtrlBlockWrite(lac_session_desc_t *pSessionDesc, cd_ctrl->cipher_cfg_offset = cipherCfgOffsetInQuadWord; - /* Amend obtained IV size for ZUC-256 */ - if (LAC_CIPHER_IS_ZUC_256(cipherAlgorithm, targetKeyLenInBytes)) - { - cd_ctrl->cipher_state_sz = - LAC_BYTES_TO_QUADWORDS(ICP_QAT_HW_ZUC_256_IV_SZ); - } - if (ICP_QAT_FW_LA_USE_UCS_SLICE_TYPE != sliceType) { ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, nextSlice); @@ -695,7 +655,8 @@ void LacSymQat_CipherHwBlockPopulateCfgData(lac_session_desc_t *pSession, LacSymQat_CipherGetCfgData(pSession, &algorithm, &mode, &dir, &key_convert); /* Build the cipher config into the hardware setup block */ - if (SPC_YES == pSession->singlePassState) + if (SPC_YES == pSession->singlePassState && + !IS_GEN6_DEV(pSession->pInstance)) { aed_hash_cmp_length = pSession->hashResultSize; reserved = @@ -843,34 +804,23 @@ void LacSymQat_CipherHwBlockPopulateKeySetup( } break; case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: - { - /* For Snow3G zero area after the key for FW */ - LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, - ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); - - *pSizeInBytes += ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; - } - break; - case CPA_CY_SYM_CIPHER_ZUC_EEA3: - { - if (targetKeyLenInBytes == ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ) { - /* For ZUC zero area after the key for FW */ + /* For Snow3G zero area after the key for FW */ LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, - ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); + ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ); - *pSizeInBytes += ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; + *pSizeInBytes += ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; } - else if (targetKeyLenInBytes == ICP_QAT_HW_ZUC_256_KEY_SZ) + break; + case CPA_CY_SYM_CIPHER_ZUC_EEA3: { /* For ZUC zero area after the key for FW */ LAC_OS_BZERO(pCipherKey + targetKeyLenInBytes, - ICP_QAT_HW_ZUC_256_IV_SZ); + ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ); - *pSizeInBytes += ICP_QAT_HW_ZUC_256_IV_SZ; + *pSizeInBytes += ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ; } - } - break; + break; case CPA_CY_SYM_CIPHER_AES_XTS: { /* For AES in XTS mode Cipher Key is concatenated with @@ -907,6 +857,9 @@ void LacSymQat_CipherHwBlockPopulateKeySetup( key_len); } } + if (IS_GEN6_DEV(pSessionDesc->pInstance)) + *pSizeInBytes += (targetKeyLenInBytes >> 1); + else *pSizeInBytes += targetKeyLenInBytes; } break; diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash.c index f559bbe4..26f5ef22 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash.c @@ -26,7 +26,6 @@ #include "cpa.h" #include "cpa_cy_sym.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_mem.h" #include "lac_sym.h" #include "lac_common.h" @@ -197,6 +196,32 @@ void LacSymQat_HashContentDescInit( /* setup the offset in QuadWords into the HW block */ cd_ctrl->hash_cfg_offset = (Cpa8U)hwBlockOffsetInQuadWords; + if (IS_GEN6_DEV(instanceHandle)) + { + /* Hmac in mode 2. Rest all hash flags are reserved for Gen6 */ + if (IS_HASH_MODE_2(qatHashMode)) + { + ICP_QAT_FW_HASH_FLAG_MODE2_SET(cd_ctrl->hash_flags, + QAT_FW_LA_MODE2); + } + /* Content Descriptor size for hash only request has been + * strictly restricted to 1 QW by FW + */ + *pHashBlkSizeInBytes = sizeof(icp_qat_hw_auth_config_t); + + if (!useSymConstantsTable) + { + LacSymQat_HashSetupBlockInit(pHashSetupData, + cd_ctrl, + pHwBlockBase, + qatHashMode, + pPrecompute, + pHashDefs, + pOuterHashDefs, + instanceHandle); + } + return; + } ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl, nextSlice); ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl, ICP_QAT_FW_SLICE_AUTH); @@ -311,13 +336,18 @@ void LacSymQat_HashContentDescInit( cd_ctrl->outer_res_sz = 0; } - if (CPA_CY_SYM_HASH_SNOW3G_UIA2 == pHashSetupData->hashAlgorithm) + switch (pHashSetupData->hashAlgorithm) { - /* add the size for the cipher config word, the key and the IV*/ - hashSetupBlkSize += - sizeof(icp_qat_hw_cipher_config_t) + - pHashSetupData->authModeSetupData.authKeyLenInBytes + - ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; + case CPA_CY_SYM_HASH_SNOW3G_UIA2: + /* Add the size for the cipher config word, the key and the IV */ + hashSetupBlkSize += + sizeof(icp_qat_hw_cipher_config_t) + + pHashSetupData->authModeSetupData.authKeyLenInBytes + + ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ; + break; + + default: + break; } *pHashBlkSizeInBytes = hashSetupBlkSize; @@ -387,6 +417,16 @@ void LacSymQat_HashSetupReqParamsMetaData( digestResultLenInBytes); LAC_ENSURE_NOT_NULL(pHashDefs); + if (IS_GEN6_DEV(instanceHandle)) + { + /* Hmac in mode 2 */ + if (IS_HASH_MODE_2(qatHashMode)) + { + pHashReqParams->u2.hmac_key_sz = + (Cpa8U)pHashDefs->algInfo->blockLength; + } + return; + } /* Hmac in mode 2 TLS */ if (IS_HASH_MODE_2(qatHashMode)) { @@ -527,6 +567,21 @@ STATIC void LacSymQat_HashSetupBlockInit( lac_hash_blk_ptrs_t hashBlkPtrs = {0}; Cpa32U aedHashCmpLength = 0; Cpa32U innerConfig = 0; + if (IS_GEN6_DEV(instanceHandle)) + { + hashBlkPtrs.pInHashSetup = + (icp_qat_hw_auth_setup_t *)((Cpa8U *)pHwBlockBase); + /* Hash compare length is reserved for Gen6 device */ + innerConfig = ICP_QAT_HW_AUTH_CONFIG_BUILD( + qatHashMode, pHashDefs->qatInfo->algoEnc, 0); + hashBlkPtrs.pInHashSetup->auth_config.config = innerConfig; + hashBlkPtrs.pInHashSetup->auth_config.reserved = 0; + /* Gen6 supports HMAC only in auth mode 2. Hence set + * zero for auth_counter. */ + hashBlkPtrs.pInHashSetup->auth_counter.counter = 0; + hashBlkPtrs.pInHashSetup->auth_counter.reserved = 0; + return; + } LacSymQat_HashHwBlockPtrsInit( pHashControlBlock, pHwBlockBase, &hashBlkPtrs); @@ -923,6 +978,17 @@ inline CpaStatus LacSymQat_HashRequestParamsPopulate( return CPA_STATUS_FAIL; } } + if (IS_GEN6_DEV(pService)) + { + pHashReqParams->auth_off = authOffsetInBytes; + pHashReqParams->auth_len = authLenInBytes; + /* For a full packet we need to set the auth result field */ + pHashReqParams->auth_res_addr = authResultPhys; + /* Populate the hmac key address */ + pHashReqParams->u1.hmac_key_addr = (pHashStateBuf->pDataPhys); + /* Remaining authentication request parameters are reserved for Gen6 */ + return CPA_STATUS_SUCCESS; + } pHashReqParams->auth_off = authOffsetInBytes; pHashReqParams->auth_len = authLenInBytes; @@ -944,15 +1010,10 @@ inline CpaStatus LacSymQat_HashRequestParamsPopulate( * field */ pHashReqParams->auth_res_addr = authResultPhys; - if (CPA_TRUE == digestVerify) - { - /* auth result size in bytes to be read in for a verify - * operation */ - pHashReqParams->auth_res_sz = (Cpa8U)hashResultSize; - } - else { - pHashReqParams->auth_res_sz = 0; + /* For non-Gen6 FW, auth_res_sz is only used for verify operations + */ + pHashReqParams->auth_res_sz = digestVerify ? (Cpa8U)hashResultSize : 0; } /* If there is a hash state prefix buffer */ diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash_defs_lookup.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash_defs_lookup.c index 72360bd5..1fc1a222 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash_defs_lookup.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_hash_defs_lookup.c @@ -31,7 +31,6 @@ #include "lac_common.h" #include "lac_log.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_adf_transport.h" #include "lac_sym.h" #include "icp_qat_fw_la.h" @@ -299,27 +298,6 @@ STATIC lac_sym_qat_hash_alg_info_t zucEia3Info = { 0 /* state size */ }; -STATIC lac_sym_qat_hash_alg_info_t zuc256mac32Info = { - LAC_HASH_ZUC_256_MAC_32_DIGEST_SIZE, - LAC_HASH_ZUC_256_MAC_32_BLOCK_SIZE, - NULL, /* initial state */ - 0 /* state size */ -}; - -STATIC lac_sym_qat_hash_alg_info_t zuc256mac64Info = { - LAC_HASH_ZUC_256_MAC_64_DIGEST_SIZE, - LAC_HASH_ZUC_256_MAC_64_BLOCK_SIZE, - NULL, /* initial state */ - 0 /* state size */ -}; - -STATIC lac_sym_qat_hash_alg_info_t zuc256mac128Info = { - LAC_HASH_ZUC_256_MAC_128_DIGEST_SIZE, - LAC_HASH_ZUC_256_MAC_128_BLOCK_SIZE, - NULL, /* initial state */ - 0 /* state size */ -}; - STATIC lac_sym_qat_hash_alg_info_t aesCmacWatInfo = { LAC_HASH_CMAC_BLOCK_SIZE, LAC_HASH_CMAC_DIGEST_SIZE, @@ -451,34 +429,6 @@ STATIC lac_sym_qat_hash_qat_info_t zucEia3Config = { ICP_QAT_HW_ZUC_3G_EIA3_STATE2_SZ }; -STATIC lac_sym_qat_hash_qat_info_t zuc256mac32Config = { - ICP_QAT_HW_AUTH_ALGO_ZUC_256_MAC_32, - 0, - ICP_QAT_HW_ZUC_256_MAC_32_STATE1_SZ, - ICP_QAT_HW_ZUC_256_STATE2_SZ -}; - -STATIC lac_sym_qat_hash_qat_info_t zuc256mac64Config = { - ICP_QAT_HW_AUTH_ALGO_ZUC_256_MAC_64, - 0, - ICP_QAT_HW_ZUC_256_MAC_64_STATE1_SZ, - ICP_QAT_HW_ZUC_256_STATE2_SZ -}; - -STATIC lac_sym_qat_hash_qat_info_t zuc256mac128Config = { - ICP_QAT_HW_AUTH_ALGO_ZUC_256_MAC_128, - 0, - ICP_QAT_HW_ZUC_256_MAC_128_STATE1_SZ, - ICP_QAT_HW_ZUC_256_STATE2_SZ -}; - -STATIC lac_sym_qat_hash_defs_t zuc256Mac32HashDefs = { &zuc256mac32Info, - &zuc256mac32Config }; -STATIC lac_sym_qat_hash_defs_t zuc256Mac64HashDefs = { &zuc256mac64Info, - &zuc256mac64Config }; -STATIC lac_sym_qat_hash_defs_t zuc256Mac128HashDefs = { &zuc256mac128Info, - &zuc256mac128Config }; - STATIC lac_sym_qat_hash_qat_info_t aes192CmacConfig = { ICP_QAT_HW_AUTH_ALGO_AES_192_CMAC, 0, @@ -604,24 +554,8 @@ void LacSymQat_HashAlgLookupGet(CpaInstanceHandle instanceHandle, "hash alg Info should not be NULL\n"); *ppHashAlgInfo = pLacHashLookupDefs[hashAlgorithm]->algInfo; - if ((hashAlgorithm == CPA_CY_SYM_HASH_ZUC_EIA3) && - (authKeyLenInBytes == ICP_QAT_HW_ZUC_256_KEY_SZ)) - { - if (digestResultLenInBytes == LAC_HASH_ZUC_256_MAC_32_DIGEST_SIZE) - { - *ppHashAlgInfo = &zuc256mac32Info; - } - else if (digestResultLenInBytes == LAC_HASH_ZUC_256_MAC_64_DIGEST_SIZE) - { - *ppHashAlgInfo = &zuc256mac64Info; - } - else - { - *ppHashAlgInfo = &zuc256mac128Info; - } - } - else if ((hashAlgorithm == CPA_CY_SYM_HASH_AES_CMAC) && - (authKeyLenInBytes != ICP_QAT_HW_AES_128_KEY_SZ)) + if ((CPA_CY_SYM_HASH_AES_CMAC == hashAlgorithm) && + (ICP_QAT_HW_AES_128_KEY_SZ != authKeyLenInBytes)) { *ppHashAlgInfo = &aesCmacWatInfo; } @@ -658,23 +592,8 @@ void LacSymQat_HashDefsLookupGet(CpaInstanceHandle instanceHandle, LAC_ENSURE(pLacHashLookupDefs[hashAlgorithm]->qatInfo != NULL, "hash qatInfo should not be NULL\n"); *ppHashDefsInfo = pLacHashLookupDefs[hashAlgorithm]; - if ((hashAlgorithm == CPA_CY_SYM_HASH_ZUC_EIA3) && - (authKeyLenInBytes == ICP_QAT_HW_ZUC_256_KEY_SZ)) - { - if (digestResultLenInBytes == LAC_HASH_ZUC_256_MAC_32_DIGEST_SIZE) - { - *ppHashDefsInfo = &zuc256Mac32HashDefs; - } - else if (digestResultLenInBytes == LAC_HASH_ZUC_256_MAC_64_DIGEST_SIZE) - { - *ppHashDefsInfo = &zuc256Mac64HashDefs; - } - else - { - *ppHashDefsInfo = &zuc256Mac128HashDefs; - } - } - else if (hashAlgorithm == CPA_CY_SYM_HASH_AES_CMAC) + + if (hashAlgorithm == CPA_CY_SYM_HASH_AES_CMAC) { if (authKeyLenInBytes == ICP_QAT_HW_AES_192_KEY_SZ) { diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_key.c b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_key.c index a16580b3..62ded286 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_key.c +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/qat/lac_sym_qat_key.c @@ -21,7 +21,6 @@ #include "lac_mem.h" #include "icp_qat_fw_la.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_list.h" #include "lac_sal_types.h" #include "lac_sym_qat_key.h" diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c index b632c096..a711557b 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c @@ -33,7 +33,6 @@ #include "icp_adf_cfg.h" #include "icp_adf_accel_mgr.h" #include "icp_adf_poll.h" -#include "icp_adf_debug.h" #include "icp_qat_hw.h" /* SAL includes */ @@ -67,65 +66,6 @@ #define MAX_BANK_NUM 1024 -/* - * Prints statistics for a compression instance - */ -STATIC int SalCtrl_CompresionDebug(void *private_data, - char *data, - int size, - int offset) -{ - sal_compression_service_t *pCompressionService = - (sal_compression_service_t *)private_data; - CpaStatus status = CPA_STATUS_SUCCESS; - CpaDcStats dcStats = {0}; - Cpa32S len = 0; - - status = cpaDcGetStats(pCompressionService, &dcStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaDcGetStats returned error\n"); - return (-1); - } - - /* Engine Info */ - if (NULL != pCompressionService->debug_file) - { - len += snprintf(data + len, - size - len, - SEPARATOR BORDER - " Statistics for Instance %24s | \n" SEPARATOR, - pCompressionService->debug_file->name); - } - - /* Perform Info */ - len += snprintf( - data + len, - size - len, - BORDER " DC comp Requests: %16llu " BORDER "\n" BORDER - " DC comp Request Errors: %16llu " BORDER "\n" BORDER - " DC comp Completed: %16llu " BORDER "\n" BORDER - " DC comp Completed Errors: %16llu " BORDER "\n" SEPARATOR, - (long long unsigned int)dcStats.numCompRequests, - (long long unsigned int)dcStats.numCompRequestsErrors, - (long long unsigned int)dcStats.numCompCompleted, - (long long unsigned int)dcStats.numCompCompletedErrors); - - /* Perform Info */ - snprintf(data + len, - size - len, - BORDER - " DC decomp Requests: %16llu " BORDER "\n" BORDER - " DC decomp Request Errors: %16llu " BORDER "\n" BORDER - " DC decomp Completed: %16llu " BORDER "\n" BORDER - " DC decomp Completed Errors: %16llu " BORDER "\n" SEPARATOR, - (long long unsigned int)dcStats.numDecompRequests, - (long long unsigned int)dcStats.numDecompRequestsErrors, - (long long unsigned int)dcStats.numDecompCompleted, - (long long unsigned int)dcStats.numDecompCompletedErrors); - return 0; -} - /* Disabling memory pool when the device is in error state */ STATIC void SalCtrl_DcMemPoolDisable(sal_service_t *service) { @@ -326,102 +266,22 @@ STATIC CpaStatus SalCtr_DcInstInit(icp_accel_dev_t *device, return status; } -STATIC void SalCtrl_DcDebugCleanup(icp_accel_dev_t *device, - sal_service_t *service) -{ - sal_compression_service_t *pCompressionService = - (sal_compression_service_t *)service; - sal_statistics_collection_t *pStatsCollection = - (sal_statistics_collection_t *)device->pQatStats; - - if (CPA_TRUE == pStatsCollection->bStatsEnabled) - { - /* Clean stats */ - if (NULL != pCompressionService->debug_file) - { - LAC_OS_FREE(pCompressionService->debug_file->name); - LAC_OS_FREE(pCompressionService->debug_file); - pCompressionService->debug_file = NULL; - } - } -} - -STATIC void SalCtrl_DcDebugShutdown(icp_accel_dev_t *device, +STATIC void SalCtrl_DcStatsShutdown(icp_accel_dev_t *device, sal_service_t *service) { sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; - SalCtrl_DcDebugCleanup(device, service); pCompressionService->generic_service_info.stats = NULL; } -STATIC void SalCtrl_DcDebugRestarting(icp_accel_dev_t *device, - sal_service_t *service) +STATIC void SalCtrl_DcStatsInit(icp_accel_dev_t *device, sal_service_t *service) { - SalCtrl_DcDebugCleanup(device, service); -} - -STATIC CpaStatus SalCtrl_DcDebugInit(icp_accel_dev_t *device, - sal_service_t *service, - char *serviceName) -{ - char adfGetParam[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char temp_string[SAL_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char *instance_name = NULL; sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; sal_statistics_collection_t *pStatsCollection = (sal_statistics_collection_t *)device->pQatStats; - CpaStatus status = CPA_STATUS_SUCCESS; - char *section = icpGetProcessName(); - - if (CPA_TRUE == pStatsCollection->bStatsEnabled) - { - /* Get instance name for stats */ - status = LAC_OS_MALLOC(&instance_name, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - LAC_CHECK_STATUS(status); - - status = Sal_StringParsing( - serviceName, - pCompressionService->generic_service_info.instance, - SAL_CFG_NAME, - temp_string); - if (CPA_STATUS_SUCCESS != status) - { - LAC_OS_FREE(instance_name); - return status; - } - - status = - icp_adf_cfgGetParamValue(device, section, temp_string, adfGetParam); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_STRING_ERROR1("Failed to get %s from configuration file", - temp_string); - LAC_OS_FREE(instance_name); - return status; - } - snprintf( - instance_name, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "%s", adfGetParam); - status = LAC_OS_MALLOC(&pCompressionService->debug_file, - sizeof(debug_file_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - LAC_OS_FREE(instance_name); - return status; - } - osalMemSet( - pCompressionService->debug_file, 0, sizeof(debug_file_info_t)); - pCompressionService->debug_file->name = instance_name; - pCompressionService->debug_file->seq_read = SalCtrl_CompresionDebug; - pCompressionService->debug_file->private_data = pCompressionService; - pCompressionService->debug_file->parent = - pCompressionService->generic_service_info.debug_parent_dir; - } pCompressionService->generic_service_info.stats = pStatsCollection; - - return status; } STATIC CpaStatus @@ -511,7 +371,6 @@ CpaStatus SalCtrl_CompressionInit(icp_accel_dev_t *device, pCompressionService->trans_handle_compression_rx = NULL; pCompressionService->trans_handle_decompression_tx = NULL; pCompressionService->trans_handle_decompression_rx = NULL; - pCompressionService->debug_file = NULL; /* Initialise device specific compression data */ status = SalCtrl_SetDCCaps(&pCompressionService->dc_capabilities, @@ -672,12 +531,7 @@ CpaStatus SalCtrl_CompressionInit(icp_accel_dev_t *device, /* Initialize Data Compression/Decompression Cookies */ Lac_MemPoolInitDcCookies(*poolID); - status = SalCtrl_DcDebugInit(device, service, serviceName); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR1("Failed to initialize %s debugfs\n", serviceName); - goto cleanup; - } + SalCtrl_DcStatsInit(device, service); pCompressionService->pDcChainService = NULL; @@ -725,7 +579,7 @@ CpaStatus SalCtrl_CompressionInit(icp_accel_dev_t *device, dcStatsFree(pCompressionService); - SalCtrl_DcDebugShutdown(device, service); + SalCtrl_DcStatsShutdown(device, service); #ifndef ICP_DC_ONLY if (NULL != pChainService) @@ -785,8 +639,6 @@ CpaStatus SalCtrl_CompressionShutdown(icp_accel_dev_t *device, sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; - sal_statistics_collection_t *pStatsCollection = - (sal_statistics_collection_t *)device->pQatStats; if ((SAL_SERVICE_STATE_INITIALIZED != pCompressionService->generic_service_info.state) && @@ -828,16 +680,6 @@ CpaStatus SalCtrl_CompressionShutdown(icp_accel_dev_t *device, LAC_CHECK_STATUS(status); } - if (CPA_TRUE == pStatsCollection->bDcStatsEnabled) - { - if (NULL != pCompressionService->debug_file) - { - /* Clean stats */ - LAC_OS_FREE(pCompressionService->debug_file->name); - LAC_OS_FREE(pCompressionService->debug_file); - pCompressionService->debug_file = NULL; - } - } pCompressionService->generic_service_info.stats = NULL; dcStatsFree(pCompressionService); #ifndef ICP_DC_ONLY @@ -848,7 +690,7 @@ CpaStatus SalCtrl_CompressionShutdown(icp_accel_dev_t *device, LAC_OS_FREE(pCompressionService->pDcChainService); } #endif - SalCtrl_DcDebugShutdown(device, service); + SalCtrl_DcStatsShutdown(device, service); pCompressionService->generic_service_info.state = SAL_SERVICE_STATE_SHUTDOWN; @@ -861,8 +703,6 @@ CpaStatus SalCtrl_CompressionRestarting(icp_accel_dev_t *device, sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; CpaStatus status = CPA_STATUS_SUCCESS; - sal_statistics_collection_t *pStatsCollection = - (sal_statistics_collection_t *)device->pQatStats; if ((SAL_SERVICE_STATE_RUNNING != pCompressionService->generic_service_info.state) && @@ -894,13 +734,6 @@ CpaStatus SalCtrl_CompressionRestarting(icp_accel_dev_t *device, LAC_CHECK_STATUS(status); } - if (CPA_TRUE == pStatsCollection->bDcStatsEnabled) - { - /* Free debug file */ - LAC_OS_FREE(pCompressionService->debug_file->name); - LAC_OS_FREE(pCompressionService->debug_file); - pCompressionService->debug_file = NULL; - } #ifndef ICP_DC_ONLY if (NULL != pCompressionService->pDcChainService) { @@ -909,7 +742,6 @@ CpaStatus SalCtrl_CompressionRestarting(icp_accel_dev_t *device, LAC_OS_FREE(pCompressionService->pDcChainService); } #endif - SalCtrl_DcDebugRestarting(device, service); pCompressionService->generic_service_info.state = SAL_SERVICE_STATE_RESTARTING; @@ -949,7 +781,6 @@ CpaStatus SalCtrl_CompressionRestarted(icp_accel_dev_t *device, coreAffinity, nodeAffinity and response mode */ pCompressionService->acceleratorNum = 0; - pCompressionService->debug_file = NULL; /* Initialise device specific compression data */ status = SalCtrl_SetDCCaps(&pCompressionService->dc_capabilities, @@ -1071,12 +902,7 @@ CpaStatus SalCtrl_CompressionRestarted(icp_accel_dev_t *device, /* Enabling memory pool for generating dummy response */ Lac_MemPoolEnable(poolID); - status = SalCtrl_DcDebugInit(device, service, serviceName); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR1("Failed to initialize %s debugfs\n", serviceName); - goto cleanup; - } + SalCtrl_DcStatsInit(device, service); pCompressionService->pDcChainService = NULL; @@ -1236,6 +1062,9 @@ CpaStatus cpaDcGetNumIntermediateBuffers(CpaInstanceHandle dcInstance, #ifdef ICP_PARAM_CHECK LAC_CHECK_NULL_PARAM(insHandle); + SAL_CHECK_INSTANCE_TYPE( + insHandle, + (SAL_SERVICE_TYPE_COMPRESSION | SAL_SERVICE_TYPE_DECOMPRESSION)); LAC_CHECK_NULL_PARAM(pNumBuffers); #endif @@ -1535,7 +1364,12 @@ CpaStatus cpaDcStopInstance(CpaInstanceHandle instanceHandle) insHandle = instanceHandle; } +#ifdef ICP_PARAM_CHECK LAC_CHECK_NULL_PARAM(insHandle); + SAL_CHECK_INSTANCE_TYPE( + insHandle, + (SAL_SERVICE_TYPE_COMPRESSION | SAL_SERVICE_TYPE_DECOMPRESSION)); +#endif pService = (sal_compression_service_t *)insHandle; dev = icp_adf_getAccelDevByAccelId(pService->acceleratorNum); diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression_capabilities.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression_capabilities.c index 6be6f82c..7acf43b1 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression_capabilities.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression_capabilities.c @@ -30,6 +30,7 @@ #include "icp_qat_fw_comp.h" #include "icp_qat_hw_20_comp_defs.h" +#include "icp_qat_hw_51_comp_defs.h" /* ******************************************************************************* @@ -80,7 +81,8 @@ STATIC void SalCtrl_Set4xxxDcExtendedCapabilities( STATIC void SalCtrl_Set4xxxDcCapabilities(dc_capabilities_t *pDcCapabilities, Cpa32U dcExtendedFeatures, - fw_caps_t *fw_caps) + fw_caps_t *fw_caps, + device_type_t device_type) { dc_extd_ftrs_t *pExtendedFtrs = (dc_extd_ftrs_t *)&(dcExtendedFeatures); memset(pDcCapabilities, 0, sizeof(dc_capabilities_t)); @@ -100,7 +102,14 @@ STATIC void SalCtrl_Set4xxxDcCapabilities(dc_capabilities_t *pDcCapabilities, pDcCapabilities->deviceData.uncompressedDataSupported = CPA_TRUE; pDcCapabilities->deviceData.hw_gen = DC_CAPS_GEN4_HW; pDcCapabilities->deviceData.compressionServiceSupported = CPA_TRUE; - pDcCapabilities->dcDeflateBound = dcDeflateBoundGen4; + if (device_type == DEVICE_420XX || device_type == DEVICE_420XXVF) + { + pDcCapabilities->dcDeflateBound = dcDeflateBoundGen4_2; + } + else + { + pDcCapabilities->dcDeflateBound = dcDeflateBoundGen4; + } pDcCapabilities->dcLZ4Bound = dcLZ4BoundGen4; pDcCapabilities->dcLZ4SBound = dcLZ4SBoundGen4; pDcCapabilities->dcCompHwBlockPopulate = dcCompHwBlockPopulateGen4; @@ -191,6 +200,208 @@ STATIC void SalCtrl_Set4xxxDcCapabilities(dc_capabilities_t *pDcCapabilities, } } +STATIC void SalCtrl_Set6xxxDcExtendedCapabilities( + dc_capabilities_t *pDcCapabilities, + fw_caps_t *fw_caps) +{ + pDcCapabilities->checksum = + ((fw_caps->cksum_algos & DC_CAPS_CRC32) | + (fw_caps->cksum_algos & DC_CAPS_ADLER32) | + ((fw_caps->cksum_algos & DC_CAPS_ADLER32) << DC_CAPS_XXHASH32_OFFSET) | + ((fw_caps->cksum_algos & DC_CAPS_ADLER32) << DC_CAPS_XXHASH64_OFFSET)); + pDcCapabilities->deflate.supported = + (fw_caps->comp_algos & DC_CAPS_DEFLATE_SUPPORTED); + pDcCapabilities->deflate.dynamicHuffmanBufferReq = + LAC_SHIFT_RIGHT((fw_caps->deflate_caps & DC_CAPS_DYNAMIC_HUFF_BUFF_REQ), + DC_CAPS_DYNAMIC_HUFF_OFFSET); + pDcCapabilities->deflate.programmableCrc64 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_PCRC), DC_CAPS_PCRC_OFFSET); + pDcCapabilities->lz4.supported = LAC_SHIFT_RIGHT( + (fw_caps->comp_algos & DC_CAPS_LZ4_SUPPORTED), DC_CAPS_LZ4_OFFSET); + pDcCapabilities->lz4.checksumXXHash32 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_ADLER32), DC_CAPS_ADLER32_OFFSET); + pDcCapabilities->lz4.programmableCrc64 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_PCRC), DC_CAPS_PCRC_OFFSET); + pDcCapabilities->lz4s.supported = LAC_SHIFT_RIGHT( + (fw_caps->comp_algos & DC_CAPS_LZ4S_SUPPORTED), DC_CAPS_LZ4S_OFFSET); + pDcCapabilities->lz4s.checksumXXHash32 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_ADLER32), DC_CAPS_ADLER32_OFFSET); + pDcCapabilities->lz4s.programmableCrc64 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_PCRC), DC_CAPS_PCRC_OFFSET); + pDcCapabilities->zstd.supported = LAC_SHIFT_RIGHT( + (fw_caps->comp_algos & DC_CAPS_ZSTD_SUPPORTED), DC_CAPS_ZSTD_OFFSET); + pDcCapabilities->zstd.checksumXXHash64 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_ADLER32), DC_CAPS_ADLER32_OFFSET); + pDcCapabilities->zstd.programmableCrc64 = LAC_SHIFT_RIGHT( + (fw_caps->cksum_algos & DC_CAPS_PCRC), DC_CAPS_PCRC_OFFSET); + pDcCapabilities->zstd.dictId = LAC_SHIFT_RIGHT( + (fw_caps->zstd_caps & DC_CAPS_DICT_ID), DC_CAPS_DICT_ID_OFFSET); +} + +STATIC void SalCtrl_Set6xxxDcCapabilities(dc_capabilities_t *pDcCapabilities, + Cpa32U dcExtendedFeatures, + fw_caps_t *fw_caps) +{ + LAC_OS_BZERO(pDcCapabilities, sizeof(dc_capabilities_t)); + + dc_extd_ftrs_t *pExtendedFtrs = (dc_extd_ftrs_t *)&(dcExtendedFeatures); + + /* Set compression HW capabilitities */ + pDcCapabilities->deviceData.oddByteDecompNobFinal = CPA_TRUE; + pDcCapabilities->deviceData.oddByteDecompInterim = CPA_TRUE; + pDcCapabilities->deviceData.enableDmm = CPA_TRUE; + pDcCapabilities->deviceData.minOutputBuffSize = + DC_DEST_BUFFER_MIN_SIZE_GEN6; + pDcCapabilities->deviceData.minOutputBuffSizeDynamic = + DC_DEST_BUFFER_DYN_MIN_SIZE_GEN6; + pDcCapabilities->deviceData.useDevRam = + ICP_QAT_FW_COMP_ENABLE_SECURE_RAM_USED_AS_INTMD_BUF; + pDcCapabilities->deviceData.highestHwCompressionDepth = + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_9; + pDcCapabilities->deviceData.uncompressedDataSupported = CPA_TRUE; + pDcCapabilities->deviceData.hw_gen = DC_CAPS_GEN6_HW; + pDcCapabilities->deviceData.decompressionServiceSupported = CPA_TRUE; + pDcCapabilities->deviceData.compressionServiceSupported = CPA_TRUE; + pDcCapabilities->dcDeflateBound = dcDeflateBoundGen6; + pDcCapabilities->dcLZ4Bound = dcLZ4BoundGen6; + pDcCapabilities->dcLZ4SBound = dcLZ4SBoundGen6; + pDcCapabilities->dcZstdBound = dcZstdBoundGen6; + pDcCapabilities->dcCompHwBlockPopulate = dcCompHwBlockPopulateGen6; + pDcCapabilities->dcNsCompHwBlockPopulate = dcCompHwBlockPopulateGen6; + pDcCapabilities->dcGetMetaSizeForSrcBuffWithDict = + dcGetMetaSizeForSrcBuffWithDictGen6; + + /* Set generic capabilities */ + pDcCapabilities->sessState = DC_CAPS_STATELESS; + pDcCapabilities->checksum = + (DC_CAPS_CRC32 | DC_CAPS_ADLER32 | DC_CAPS_XXHASH32 | DC_CAPS_XXHASH64); + pDcCapabilities->numInterBuffs = 0; + pDcCapabilities->endOfLastBlock = CPA_TRUE; + pDcCapabilities->storedBlockGeneration = CPA_TRUE; + pDcCapabilities->determinism = CPA_TRUE; + pDcCapabilities->reportParityError = CPA_TRUE; + pDcCapabilities->overflowResubmitUnsupported = CPA_TRUE; + pDcCapabilities->statefulLiteUnsupported = CPA_TRUE; + + /* Set asb capabilities */ + pDcCapabilities->asb.supported = CPA_TRUE; + pDcCapabilities->asb.asbTshSupported = CPA_TRUE; + pDcCapabilities->asb.asbRatioSupported = CPA_TRUE; + + /* Set data integrity capabilities */ + pDcCapabilities->crcIntegrity.supported = CPA_TRUE; + pDcCapabilities->crcIntegrity.checkCRC64 = CPA_TRUE; + + /* Set CNV capabilities */ + pDcCapabilities->cnv.supported = + (dcExtendedFeatures & DC_CNV_EXTENDED_CAPABILITY); + pDcCapabilities->cnv.recovery = + LAC_SHIFT_RIGHT((dcExtendedFeatures & DC_CNVNR_EXTENDED_CAPABILITY), + DC_CAPS_CNVNR_EXTENDED_OFFSET); + + pDcCapabilities->cnv.errorInjection = CPA_TRUE; + pDcCapabilities->cnv.strict = CPA_TRUE; + + /* Set deflate capabilities */ + DC_CAPS_DEFLATE_TYPE_SUPPORT_SET(pDcCapabilities->deflate.typeSupport, + DC_CAPS_DEFLATE_TYPE_DYNAMIC, + DC_CAPS_DEFLATE_TYPE_SUPPORTED); + + pDcCapabilities->deflate.supported = CPA_TRUE; + pDcCapabilities->deflate.dirMask = + (DC_CAPS_COMPRESSION | DC_CAPS_DECOMPRESSION); + pDcCapabilities->deflate.dynamicHuffmanBufferReq = CPA_FALSE; + pDcCapabilities->deflate.precompiledHuffman = CPA_FALSE; + pDcCapabilities->deflate.internalHuffmanMem = CPA_TRUE; + pDcCapabilities->deflate.bypassIncompleteFileErr = CPA_TRUE; + pDcCapabilities->deflate.historyBufferSize = CPA_DC_WINSIZE_32K; + pDcCapabilities->deflate.zerolengthRequests = CPA_TRUE; + pDcCapabilities->deflate.validWindowSizeMaskCompression = + DC_32K_WINDOW_MASK; + pDcCapabilities->deflate.validWindowSizeMaskDecompression = + DC_4K_WINDOW_MASK | DC_8K_WINDOW_MASK | DC_16K_WINDOW_MASK | + DC_32K_WINDOW_MASK; + pDcCapabilities->deflate.asbSupported = CPA_TRUE; + pDcCapabilities->deflate.dictCompSupported = CPA_TRUE; + pDcCapabilities->deflate.dictCap = DC_CAPS_UNCOMPRESSED_DICT; + pDcCapabilities->deflate.programmableCrc64 = CPA_TRUE; + pDcCapabilities->deflate.hashThenCompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_hash_then_compress; + pDcCapabilities->deflate.compressThenAeadSupported = + (Cpa8U)pExtendedFtrs->is_chain_compress_then_aead; + pDcCapabilities->deflate.aeadThenDecompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_aead_then_decompress; + + /* Set lz4 capabilities */ + pDcCapabilities->lz4.supported = CPA_TRUE; + pDcCapabilities->lz4.dirMask = + (DC_CAPS_COMPRESSION | DC_CAPS_DECOMPRESSION); + pDcCapabilities->lz4.checksumXXHash32 = CPA_TRUE; + pDcCapabilities->lz4.accumulateXXHash = CPA_FALSE; + pDcCapabilities->lz4.blockIndependence = CPA_TRUE; + pDcCapabilities->lz4.maxBlockSize = DC_CAPS_LZ4_64K; + pDcCapabilities->lz4.historyBufferSize = CPA_DC_WINSIZE_64K; + pDcCapabilities->lz4.zerolengthRequests = CPA_TRUE; + pDcCapabilities->lz4.validWindowSizeMaskCompression = DC_64K_WINDOW_MASK; + pDcCapabilities->lz4.validWindowSizeMaskDecompression = + DC_4K_WINDOW_MASK | DC_8K_WINDOW_MASK | DC_16K_WINDOW_MASK | + DC_32K_WINDOW_MASK | DC_64K_WINDOW_MASK; + pDcCapabilities->lz4.asbSupported = CPA_TRUE; + pDcCapabilities->lz4.programmableCrc64 = CPA_TRUE; + pDcCapabilities->lz4.hashThenCompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_hash_then_compress; + pDcCapabilities->lz4.compressThenAeadSupported = + (Cpa8U)pExtendedFtrs->is_chain_compress_then_aead; + pDcCapabilities->lz4.aeadThenDecompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_aead_then_decompress; + pDcCapabilities->lz4.asbEnablePref = CPA_TRUE; + + /* Set lz4s capabilities */ + pDcCapabilities->lz4s.supported = CPA_TRUE; + pDcCapabilities->lz4s.dirMask = DC_CAPS_COMPRESSION; + pDcCapabilities->lz4s.checksumXXHash32 = CPA_TRUE; + pDcCapabilities->lz4s.minMatch = (DC_CAPS_LZ4S_3B | DC_CAPS_LZ4S_4B); + pDcCapabilities->lz4s.historyBufferSize = CPA_DC_WINSIZE_64K; + pDcCapabilities->lz4s.zerolengthRequests = CPA_TRUE; + pDcCapabilities->lz4s.validWindowSizeMaskCompression = DC_64K_WINDOW_MASK; + pDcCapabilities->lz4s.asbSupported = CPA_FALSE; + pDcCapabilities->lz4s.dictCompSupported = CPA_TRUE; + pDcCapabilities->lz4s.dictCap = DC_CAPS_UNCOMPRESSED_DICT; + pDcCapabilities->lz4s.programmableCrc64 = CPA_TRUE; + + /* Set zstd capabilities */ + pDcCapabilities->zstd.supported = CPA_TRUE; + pDcCapabilities->zstd.dirMask = + (DC_CAPS_COMPRESSION | DC_CAPS_DECOMPRESSION); + pDcCapabilities->zstd.checksumXXHash64 = CPA_TRUE; + pDcCapabilities->zstd.historyBufferSize = CPA_DC_WINSIZE_64K; + pDcCapabilities->zstd.zerolengthRequests = CPA_TRUE; + pDcCapabilities->zstd.validWindowSizeMaskCompression = DC_64K_WINDOW_MASK; + pDcCapabilities->zstd.validWindowSizeMaskDecompression = + DC_4K_WINDOW_MASK | DC_8K_WINDOW_MASK | DC_16K_WINDOW_MASK | + DC_32K_WINDOW_MASK | DC_64K_WINDOW_MASK; + + pDcCapabilities->zstd.asbSupported = CPA_TRUE; + pDcCapabilities->zstd.asbEnablePref = CPA_TRUE; + pDcCapabilities->zstd.dictCompSupported = CPA_TRUE; + pDcCapabilities->zstd.dictCap = DC_CAPS_UNCOMPRESSED_DICT; + pDcCapabilities->zstd.dictId = CPA_TRUE; + pDcCapabilities->zstd.programmableCrc64 = CPA_TRUE; + pDcCapabilities->zstd.hashThenCompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_hash_then_compress; + pDcCapabilities->zstd.compressThenAeadSupported = + (Cpa8U)pExtendedFtrs->is_chain_compress_then_aead; + pDcCapabilities->zstd.aeadThenDecompressSupported = + (Cpa8U)pExtendedFtrs->is_chain_aead_then_decompress; + + /* Overwrite default capabilities with capabilities returned + * from firmware if available. */ + if (fw_caps->is_fw_caps) + { + SalCtrl_Set6xxxDcExtendedCapabilities(pDcCapabilities, fw_caps); + } +} + /* Sets device specific information needed by compression service */ CpaStatus SalCtrl_SetDCCaps(dc_capabilities_t *pDcCapabilities, int device_type, @@ -209,6 +420,11 @@ CpaStatus SalCtrl_SetDCCaps(dc_capabilities_t *pDcCapabilities, case DEVICE_420XX: case DEVICE_420XXVF: SalCtrl_Set4xxxDcCapabilities( + pDcCapabilities, dcExtendedFeatures, fw_caps, device_type); + break; + case DEVICE_6XXX: + case DEVICE_6XXXVF: + SalCtrl_Set6xxxDcCapabilities( pDcCapabilities, dcExtendedFeatures, fw_caps); break; default: diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_create_services.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_create_services.c index a7db2a17..299e648f 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_create_services.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_create_services.c @@ -29,7 +29,6 @@ #include "lac_list.h" #include "icp_adf_transport.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_qat_fw_la.h" #include "lac_sym_qat.h" diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c index 4a9f6c66..0faf098b 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c @@ -49,7 +49,6 @@ #include "icp_adf_cfg.h" #include "icp_adf_accel_mgr.h" #include "icp_adf_poll.h" -#include "icp_adf_debug.h" /* SAL includes */ #include "lac_log.h" @@ -72,6 +71,7 @@ #include "lac_sal_types_crypto.h" #include "lac_sal.h" #include "lac_sal_ctrl.h" +#include "lac_kpt_crypto_qat_comms.h" #include "sal_string_parse.h" #include "sal_service_state.h" #include "icp_sal_poll.h" @@ -501,6 +501,11 @@ STATIC CpaStatus SalCtrl_AsymFreeResources(sal_crypto_service_t *pCryptoService) Lac_MemPoolDestroy(pCryptoService->lac_pke_req_pool); Lac_MemPoolDestroy(pCryptoService->lac_ec_pool); Lac_MemPoolDestroy(pCryptoService->lac_prime_pool); + SAL_GET_INSTANCE_CRYPTO_CAPABILITY_STATUS(status, pCryptoService, kpt); + if (CPA_STATUS_SUCCESS == status) + { + Lac_MemPoolDestroy(pCryptoService->lac_pke_kpt_pool); + } /* Free the statistics */ LacDh_StatsFree(pCryptoService); @@ -667,7 +672,9 @@ STATIC CpaStatus SalCtrl_AsymCreateTransHandle(icp_accel_dev_t *device, /* Need to free resources in case not _SUCCESS from here */ LAC_CHECK_STATUS_ASYM_INIT(status); - msgSize = LAC_QAT_ASYM_REQ_SZ_LW * LAC_LONG_WORD_IN_BYTES; + { + msgSize = LAC_QAT_ASYM_REQ_SZ_IN_BYTES; + } status = icp_adf_transCreateHandle( device, ICP_TRANS_TYPE_ETR, @@ -733,7 +740,10 @@ STATIC CpaStatus SalCtrl_AsymReinitTransHandle(icp_accel_dev_t *device, /* Need to free resources in case not _SUCCESS from here */ LAC_CHECK_STATUS_ASYM_INIT(status); - msgSize = LAC_QAT_ASYM_REQ_SZ_LW * LAC_LONG_WORD_IN_BYTES; + { + msgSize = LAC_QAT_ASYM_REQ_SZ_IN_BYTES; + } + status = icp_adf_transReinitHandle( device, ICP_TRANS_TYPE_ETR, @@ -910,681 +920,6 @@ STATIC CpaStatus SalCtrl_SymReinitTransHandle(icp_accel_dev_t *device, return status; } -STATIC int SalCtrl_CryptoDebug(void *private_data, - char *data, - int size, - int offset) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - Cpa32U len = 0; - sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)private_data; - - switch (offset) - { - case SAL_STATS_SYM: - { - CpaCySymStats64 symStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bSymStatsEnabled) - { - break; - } - status = cpaCySymQueryStats64(pCryptoService, &symStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCySymQueryStats64 returned error\n"); - return 0; - } - - /* Engine Info */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " Statistics for Instance %24s |\n" BORDER - " Symmetric Stats " BORDER - "\n" SEPARATOR, - pCryptoService->debug_file->name); - - /* Session Info */ - len += snprintf( - data + len, - size - len, - BORDER - " Sessions Initialized: %16llu " BORDER "\n" BORDER - " Sessions Removed: %16llu " BORDER "\n" BORDER - " Session Errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)symStats.numSessionsInitialized, - (long long unsigned int)symStats.numSessionsRemoved, - (long long unsigned int)symStats.numSessionErrors); - - /* Session info */ - snprintf( - data + len, - size - len, - BORDER - " Symmetric Requests: %16llu " BORDER "\n" BORDER - " Symmetric Request Errors: %16llu " BORDER "\n" BORDER - " Symmetric Completed: %16llu " BORDER "\n" BORDER - " Symmetric Completed Errors: %16llu " BORDER "\n" BORDER - " Symmetric Verify Failures: %16llu " BORDER "\n", - (long long unsigned int)symStats.numSymOpRequests, - (long long unsigned int)symStats.numSymOpRequestErrors, - (long long unsigned int)symStats.numSymOpCompleted, - (long long unsigned int)symStats.numSymOpCompletedErrors, - (long long unsigned int)symStats.numSymOpVerifyFailures); - break; - } - case SAL_STATS_DSA: - { - CpaCyDsaStats64 dsaStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bDsaStatsEnabled) - { - ++offset; - break; - } - - status = cpaCyDsaQueryStats64(pCryptoService, &dsaStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyDsaQueryStats4 returned error\n"); - return 0; - } - /* engine info */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " DSA Stats " BORDER - "\n" SEPARATOR); - - /* p parameter generation requests */ - len += snprintf( - data + len, - size - len, - BORDER - " DSA P Param Gen Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA P Param Gen Requests-Err: %16llu " BORDER "\n" BORDER - " DSA P Param Gen Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA P Param Gen Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaPParamGenRequests, - (long long unsigned int)dsaStats.numDsaPParamGenRequestErrors, - (long long unsigned int)dsaStats.numDsaPParamGenCompleted, - (long long unsigned int) - dsaStats.numDsaPParamGenCompletedErrors); - - /* g parameter generation requests */ - len += snprintf( - data + len, - size - len, - BORDER - " DSA G Param Gen Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA G Param Gen Requests-Err: %16llu " BORDER "\n" BORDER - " DSA G Param Gen Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA G Param Gen Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaGParamGenRequests, - (long long unsigned int)dsaStats.numDsaGParamGenRequestErrors, - (long long unsigned int)dsaStats.numDsaGParamGenCompleted, - (long long unsigned int) - dsaStats.numDsaGParamGenCompletedErrors); - - /* y parameter generation requests */ - snprintf( - data + len, - size - len, - BORDER - " DSA Y Param Gen Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA Y Param Gen Requests-Err: %16llu " BORDER "\n" BORDER - " DSA Y Param Gen Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA Y Param Gen Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaYParamGenRequests, - (long long unsigned int)dsaStats.numDsaYParamGenRequestErrors, - (long long unsigned int)dsaStats.numDsaYParamGenCompleted, - (long long unsigned int) - dsaStats.numDsaYParamGenCompletedErrors); - break; - } - case SAL_STATS_DSA2: - { - CpaCyDsaStats64 dsaStats = {0}; - status = cpaCyDsaQueryStats64(pCryptoService, &dsaStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyDsaQueryStats4 returned error\n"); - return 0; - } - /* r sign requests */ - len += snprintf( - data + len, - size - len, - BORDER - " DSA R Sign Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA R Sign Request-Err: %16llu " BORDER "\n" BORDER - " DSA R Sign Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA R Sign Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaRSignRequests, - (long long unsigned int)dsaStats.numDsaRSignRequestErrors, - (long long unsigned int)dsaStats.numDsaRSignCompleted, - (long long unsigned int)dsaStats.numDsaRSignCompletedErrors); - - /* s sign requests */ - len += snprintf( - data + len, - size - len, - BORDER - " DSA S Sign Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA S Sign Request-Err: %16llu " BORDER "\n" BORDER - " DSA S Sign Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA S Sign Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaSSignRequests, - (long long unsigned int)dsaStats.numDsaSSignRequestErrors, - (long long unsigned int)dsaStats.numDsaSSignCompleted, - (long long unsigned int)dsaStats.numDsaSSignCompletedErrors); - - /* rs sign requests */ - len += snprintf( - data + len, - size - len, - BORDER - " DSA RS Sign Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA RS Sign Request-Err: %16llu " BORDER "\n" BORDER - " DSA RS Sign Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA RS Sign Completed-Err: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dsaStats.numDsaRSSignRequests, - (long long unsigned int)dsaStats.numDsaRSSignRequestErrors, - (long long unsigned int)dsaStats.numDsaRSSignCompleted, - (long long unsigned int)dsaStats.numDsaRSSignCompletedErrors); - - /* verify requests */ - snprintf( - data + len, - size - len, - BORDER - " DSA Verify Requests-Succ: %16llu " BORDER "\n" BORDER - " DSA Verify Request-Err: %16llu " BORDER "\n" BORDER - " DSA Verify Completed-Succ: %16llu " BORDER "\n" BORDER - " DSA Verify Completed-Err: %16llu " BORDER "\n" BORDER - " DSA Verify Completed-Failure: %16llu " BORDER "\n", - (long long unsigned int)dsaStats.numDsaVerifyRequests, - (long long unsigned int)dsaStats.numDsaVerifyRequestErrors, - (long long unsigned int)dsaStats.numDsaVerifyCompleted, - (long long unsigned int)dsaStats.numDsaVerifyCompletedErrors, - (long long unsigned int)dsaStats.numDsaVerifyFailures); - break; - } - case SAL_STATS_RSA: - { - CpaCyRsaStats64 rsaStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bRsaStatsEnabled) - { - break; - } - - status = cpaCyRsaQueryStats64(pCryptoService, &rsaStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyRsaQueryStats64 returned error\n"); - return 0; - } - - /* Engine Info */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " RSA Stats " BORDER - "\n" SEPARATOR); - - /* rsa keygen Info */ - len += snprintf( - data + len, - size - len, - BORDER - " RSA Key Gen Requests: %16llu " BORDER "\n" BORDER - " RSA Key Gen Request Errors %16llu " BORDER "\n" BORDER - " RSA Key Gen Completed: %16llu " BORDER "\n" BORDER - " RSA Key Gen Completed Errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)rsaStats.numRsaKeyGenRequests, - (long long unsigned int)rsaStats.numRsaKeyGenRequestErrors, - (long long unsigned int)rsaStats.numRsaKeyGenCompleted, - (long long unsigned int)rsaStats.numRsaKeyGenCompletedErrors); - - /* rsa enc Info */ - len += snprintf( - data + len, - size - len, - BORDER - " RSA Encrypt Requests: %16llu " BORDER "\n" BORDER - " RSA Encrypt Request Errors: %16llu " BORDER "\n" BORDER - " RSA Encrypt Completed: %16llu " BORDER "\n" BORDER - " RSA Encrypt Completed Errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)rsaStats.numRsaEncryptRequests, - (long long unsigned int)rsaStats.numRsaEncryptRequestErrors, - (long long unsigned int)rsaStats.numRsaEncryptCompleted, - (long long unsigned int)rsaStats.numRsaEncryptCompletedErrors); - - /* rsa dec Info */ - snprintf( - data + len, - size - len, - BORDER - " RSA Decrypt Requests: %16llu " BORDER "\n" BORDER - " RSA Decrypt Request Errors: %16llu " BORDER "\n" BORDER - " RSA Decrypt Completed: %16llu " BORDER "\n" BORDER - " RSA Decrypt Completed Errors: %16llu " BORDER "\n", - (long long unsigned int)rsaStats.numRsaDecryptRequests, - (long long unsigned int)rsaStats.numRsaDecryptRequestErrors, - (long long unsigned int)rsaStats.numRsaDecryptCompleted, - (long long unsigned int)rsaStats.numRsaDecryptCompletedErrors); - break; - } - case SAL_STATS_DH: - { - CpaCyDhStats64 dhStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bDhStatsEnabled) - { - break; - } - status = cpaCyDhQueryStats64(pCryptoService, &dhStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyDhQueryStats returned error\n"); - return 0; - } - - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " Diffie Hellman Stats " BORDER - "\n" SEPARATOR); - - /* perform Info */ - len += snprintf( - data + len, - size - len, - BORDER - " DH Phase1 Key Gen Requests: %16llu " BORDER "\n" BORDER - " DH Phase1 Key Gen Request Err: %16llu " BORDER "\n" BORDER - " DH Phase1 Key Gen Completed: %16llu " BORDER "\n" BORDER - " DH Phase1 Key Gen Completed Err:%16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)dhStats.numDhPhase1KeyGenRequests, - (long long unsigned int)dhStats.numDhPhase1KeyGenRequestErrors, - (long long unsigned int)dhStats.numDhPhase1KeyGenCompleted, - (long long unsigned int) - dhStats.numDhPhase1KeyGenCompletedErrors); - - snprintf( - data + len, - size - len, - BORDER - " DH Phase2 Key Gen Requests: %16llu " BORDER "\n" BORDER - " DH Phase2 Key Gen Request Err: %16llu " BORDER "\n" BORDER - " DH Phase2 Key Gen Completed: %16llu " BORDER "\n" BORDER - " DH Phase2 Key Gen Completed Err:%16llu " BORDER "\n", - (long long unsigned int)dhStats.numDhPhase2KeyGenRequests, - (long long unsigned int)dhStats.numDhPhase2KeyGenRequestErrors, - (long long unsigned int)dhStats.numDhPhase2KeyGenCompleted, - (long long unsigned int) - dhStats.numDhPhase2KeyGenCompletedErrors); - break; - } - case SAL_STATS_KEYGEN: - { - CpaCyKeyGenStats64 keyStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bKeyGenStatsEnabled) - { - break; - } - status = cpaCyKeyGenQueryStats64(pCryptoService, &keyStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyKeyGenQueryStats64 returned error\n"); - return 0; - } - - /* Key Gen stats */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " Key Stats " BORDER - "\n" SEPARATOR); - - len += snprintf( - data + len, - size - len, - BORDER - " SSL Key Requests: %16llu " BORDER "\n" BORDER - " SSL Key Request Errors: %16llu " BORDER "\n" BORDER - " SSL Key Completed %16llu " BORDER "\n" BORDER - " SSL Key Complete Errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)keyStats.numSslKeyGenRequests, - (long long unsigned int)keyStats.numSslKeyGenRequestErrors, - (long long unsigned int)keyStats.numSslKeyGenCompleted, - (long long unsigned int)keyStats.numSslKeyGenCompletedErrors); - - len += snprintf( - data + len, - size - len, - BORDER - " TLS Key Requests: %16llu " BORDER "\n" BORDER - " TLS Key Request Errors: %16llu " BORDER "\n" BORDER - " TLS Key Completed %16llu " BORDER "\n" BORDER - " TLS Key Complete Errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)keyStats.numTlsKeyGenRequests, - (long long unsigned int)keyStats.numTlsKeyGenRequestErrors, - (long long unsigned int)keyStats.numTlsKeyGenCompleted, - (long long unsigned int)keyStats.numTlsKeyGenCompletedErrors); - - snprintf( - data + len, - size - len, - BORDER - " MGF Key Requests: %16llu " BORDER "\n" BORDER - " MGF Key Request Errors: %16llu " BORDER "\n" BORDER - " MGF Key Completed %16llu " BORDER "\n" BORDER - " MGF Key Complete Errors: %16llu " BORDER "\n", - (long long unsigned int)keyStats.numMgfKeyGenRequests, - (long long unsigned int)keyStats.numMgfKeyGenRequestErrors, - (long long unsigned int)keyStats.numMgfKeyGenCompleted, - (long long unsigned int)keyStats.numMgfKeyGenCompletedErrors); - break; - } - case SAL_STATS_LN: - { - CpaCyLnStats64 lnStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bLnStatsEnabled) - { - break; - } - status = cpaCyLnStatsQuery64(pCryptoService, &lnStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyLnStatsQuery64 returned error\n"); - return 0; - } - - /* Engine Info */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " LN ModExp/ModInv Stats " BORDER - "\n" SEPARATOR); - - /* Large Number Modular Exponentationstats operations stats */ - len += snprintf( - data + len, - size - len, - BORDER - " LN ModEXP successful requests: %16llu " BORDER "\n" BORDER - " LN ModEXP requests with error: %16llu " BORDER "\n" BORDER - " LN ModEXP completed operations: %16llu " BORDER "\n" BORDER - " LN ModEXP not completed-errors: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)lnStats.numLnModExpRequests, - (long long unsigned int)lnStats.numLnModExpRequestErrors, - (long long unsigned int)lnStats.numLnModExpCompleted, - (long long unsigned int)lnStats.numLnModExpCompletedErrors); - - /* Large Number Modular Inversion operations stats */ - snprintf( - data + len, - size - len, - BORDER - " LN ModINV successful requests: %16llu " BORDER "\n" BORDER - " LN ModINV requests with error: %16llu " BORDER "\n" BORDER - " LN ModINV completed operations: %16llu " BORDER "\n" BORDER - " LN ModINV not completed-errors: %16llu " BORDER "\n", - (long long unsigned int)lnStats.numLnModInvRequests, - (long long unsigned int)lnStats.numLnModInvRequestErrors, - (long long unsigned int)lnStats.numLnModInvCompleted, - (long long unsigned int)lnStats.numLnModInvCompletedErrors); - - break; - } - case SAL_STATS_PRIME: - { - CpaCyPrimeStats64 primeStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bPrimeStatsEnabled) - { - break; - } - status = cpaCyPrimeQueryStats64(pCryptoService, &primeStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyPrimeQueryStats64 returned error\n"); - return 0; - } - - /* Engine Info */ - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " PRIME Stats " BORDER - "\n" SEPARATOR); - - /* Parameter generation requests - PRIME stats */ - snprintf( - data + len, - size - len, - BORDER - " PRIME successful requests: %16llu " BORDER "\n" BORDER - " PRIME failed requests: %16llu " BORDER "\n" BORDER - " PRIME successfully completed: %16llu " BORDER "\n" BORDER - " PRIME failed completion: %16llu " BORDER "\n" BORDER - " PRIME completed - not a prime: %16llu " BORDER "\n", - (long long unsigned int)primeStats.numPrimeTestRequests, - (long long unsigned int)primeStats.numPrimeTestRequestErrors, - (long long unsigned int)primeStats.numPrimeTestCompleted, - (long long unsigned int)primeStats.numPrimeTestCompletedErrors, - (long long unsigned int)primeStats.numPrimeTestFailures); - break; - } - case SAL_STATS_ECC: - { - CpaCyEcStats64 ecStats = {0}; - if (CPA_TRUE != - pCryptoService->generic_service_info.stats->bEccStatsEnabled) - { - offset += DOUBLE_INCR; - break; - } - status = cpaCyEcQueryStats64(pCryptoService, &ecStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyEcQueryStats64 returned error\n"); - return 0; - } - - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " EC Stats " BORDER - "\n" SEPARATOR); - - len += snprintf( - data + len, - size - len, - BORDER - " EC Pt Multiply Requests-Succ: %16llu " BORDER "\n" BORDER - " EC Pt Multiply Request-Err: %16llu " BORDER "\n" BORDER - " EC Pt Multiply Completed-Succ: %16llu " BORDER "\n" BORDER - " EC Pt Multiply Completed-Err: %16llu " BORDER "\n" BORDER - " EC Pt Multiply Output Invalid: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)ecStats.numEcPointMultiplyRequests, - (long long unsigned int)ecStats.numEcPointMultiplyRequestErrors, - (long long unsigned int)ecStats.numEcPointMultiplyCompleted, - (long long unsigned int) - ecStats.numEcPointMultiplyCompletedError, - (long long unsigned int) - ecStats.numEcPointMultiplyCompletedOutputInvalid); - snprintf( - data + len, - size - len, - BORDER - " EC Pt Verify Requests-Succ: %16llu " BORDER "\n" BORDER - " EC Pt Verify Request-Err: %16llu " BORDER "\n" BORDER - " EC Pt Verify Completed-Succ: %16llu " BORDER "\n" BORDER - " EC Pt Verify Completed-Err: %16llu " BORDER "\n" BORDER - " EC Pt Verify Output Invalid: %16llu " BORDER "\n", - (long long unsigned int)ecStats.numEcPointVerifyRequests, - (long long unsigned int)ecStats.numEcPointVerifyRequestErrors, - (long long unsigned int)ecStats.numEcPointVerifyCompleted, - (long long unsigned int)ecStats.numEcPointVerifyCompletedErrors, - (long long unsigned int) - ecStats.numEcPointVerifyCompletedOutputInvalid); - break; - } - case SAL_STATS_ECDH: - { - CpaCyEcdhStats64 ecdhStats = {0}; - status = cpaCyEcdhQueryStats64(pCryptoService, &ecdhStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyEcdhQueryStats64 returned error\n"); - return 0; - } - - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " ECDH Stats " BORDER - "\n" SEPARATOR); - snprintf( - data + len, - size - len, - BORDER - " ECDH Pt Multiply Requests-Succ: %16llu " BORDER "\n" BORDER - " ECDH Pt Multiply Request-Err: %16llu " BORDER "\n" BORDER - " ECDH Pt Multiply Completed-Succ:%16llu " BORDER "\n" BORDER - " ECDH Pt Multiply Completed-Err: %16llu " BORDER "\n" BORDER - " ECDH Output Invalid: %16llu " BORDER "\n", - (long long unsigned int)ecdhStats.numEcdhPointMultiplyRequests, - (long long unsigned int) - ecdhStats.numEcdhPointMultiplyRequestErrors, - (long long unsigned int)ecdhStats.numEcdhPointMultiplyCompleted, - (long long unsigned int) - ecdhStats.numEcdhPointMultiplyCompletedError, - (long long unsigned int) - ecdhStats.numEcdhRequestCompletedOutputInvalid); - break; - } - case SAL_STATS_ECDSA: - { - CpaCyEcdsaStats64 ecdsaStats = {0}; - status = cpaCyEcdsaQueryStats64(pCryptoService, &ecdsaStats); - if (status != CPA_STATUS_SUCCESS) - { - LAC_LOG_ERROR("cpaCyEcdsaQueryStats64 returned error\n"); - return 0; - } - - len += snprintf( - data + len, - size - len, - SEPARATOR BORDER - " ECDSA Stats " BORDER - "\n" SEPARATOR); - len += snprintf( - data + len, - size - len, - BORDER - " ECDSA Sign R Requests-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign R Request-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign R Completed-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign R Completed-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign R Output Invalid: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)ecdsaStats.numEcdsaSignRRequests, - (long long unsigned int)ecdsaStats.numEcdsaSignRRequestErrors, - (long long unsigned int)ecdsaStats.numEcdsaSignRCompleted, - (long long unsigned int)ecdsaStats.numEcdsaSignRCompletedErrors, - (long long unsigned int) - ecdsaStats.numEcdsaSignRCompletedOutputInvalid); - len += snprintf( - data + len, - size - len, - BORDER - " ECDSA Sign S Requests-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign S Request-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign S Completed-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign S Completed-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign S Output Invalid: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)ecdsaStats.numEcdsaSignSRequests, - (long long unsigned int)ecdsaStats.numEcdsaSignSRequestErrors, - (long long unsigned int)ecdsaStats.numEcdsaSignSCompleted, - (long long unsigned int)ecdsaStats.numEcdsaSignSCompletedErrors, - (long long unsigned int) - ecdsaStats.numEcdsaSignSCompletedOutputInvalid); - len += snprintf( - data + len, - size - len, - BORDER - " ECDSA Sign RS Requests-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign RS Request-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign RS Completed-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Sign RS Completed-Err: %16llu " BORDER "\n" BORDER - " ECDSA Sign RS Output Invalid: %16llu " BORDER - "\n" SEPARATOR, - (long long unsigned int)ecdsaStats.numEcdsaSignRSRequests, - (long long unsigned int)ecdsaStats.numEcdsaSignRSRequestErrors, - (long long unsigned int)ecdsaStats.numEcdsaSignRSCompleted, - (long long unsigned int) - ecdsaStats.numEcdsaSignRSCompletedErrors, - (long long unsigned int) - ecdsaStats.numEcdsaSignRSCompletedOutputInvalid); - snprintf( - data + len, - size - len, - BORDER - " ECDSA Verify Requests-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Verify Request-Err: %16llu " BORDER "\n" BORDER - " ECDSA Verify Completed-Succ: %16llu " BORDER "\n" BORDER - " ECDSA Verify Completed-Err: %16llu " BORDER "\n" BORDER - " ECDSA Verify Output Invalid: %16llu " BORDER "\n", - (long long unsigned int)ecdsaStats.numEcdsaVerifyRequests, - (long long unsigned int)ecdsaStats.numEcdsaVerifyRequestErrors, - (long long unsigned int)ecdsaStats.numEcdsaVerifyCompleted, - (long long unsigned int) - ecdsaStats.numEcdsaVerifyCompletedErrors, - (long long unsigned int) - ecdsaStats.numEcdsaVerifyCompletedOutputInvalid); - break; - } - default: - { - snprintf(data + len, size - len, SEPARATOR); - return 0; - } - } - return ++offset; -} - STATIC CpaStatus SalCtrl_GetCyConcurrentReqNum(char *string1, char *section, @@ -1723,6 +1058,28 @@ STATIC CpaStatus SalCtrl_AsymInit(icp_accel_dev_t *device, pCryptoService->nodeAffinity); LAC_CHECK_STATUS_ASYM_INIT(status); + SAL_GET_INSTANCE_CRYPTO_CAPABILITY_STATUS(status, service, kpt); + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate KPT asymmetric service memory pool */ + pCryptoService->lac_pke_kpt_pool = LAC_MEM_POOL_INIT_POOL_ID; + status = + Sal_StringParsing(SAL_CFG_CY, + pCryptoService->generic_service_info.instance, + SAL_CFG_ASYM_KPT_UNWRAP_CTX_MEM_POOL, + temp_string); + LAC_CHECK_STATUS_ASYM_INIT(status); + status = Lac_MemPoolCreate( + &pCryptoService->lac_pke_kpt_pool, + temp_string, + numAsymConcurrentReq + 1, + (LAC_KPT_UNWRAP_CTX_SIZE_IN_BYTES + sizeof(CpaFlatBuffer)), + LAC_64BYTE_ALIGNMENT, + CPA_FALSE, + pCryptoService->nodeAffinity); + LAC_CHECK_STATUS_ASYM_INIT(status); + } + /* Clear Key stats and allocate memory of SSL and TLS labels These labels are initialised to standard values */ @@ -1819,8 +1176,11 @@ STATIC CpaStatus SalCtrl_SymInit(icp_accel_dev_t *device, sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; char *section = icpGetProcessName(); - /* Set default value of HMAC mode */ - pCryptoService->qatHmacMode = ICP_QAT_HW_AUTH_MODE1; + /* Gen6 supports only AUTH_MODE2 for HMAC */ + if (pCryptoService->generic_service_info.isGen6) + pCryptoService->qatHmacMode = ICP_QAT_HW_AUTH_MODE2; + else + pCryptoService->qatHmacMode = ICP_QAT_HW_AUTH_MODE1; /* Register callbacks for the symmetric services * (Hash, Cipher, Algorithm-Chaining) (returns void)*/ @@ -1942,96 +1302,20 @@ STATIC CpaStatus SalCtrl_SymReinit(icp_accel_dev_t *device, return status; } -STATIC void SalCtrl_DebugCleanup(icp_accel_dev_t *device, - sal_service_t *service) -{ - sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - sal_statistics_collection_t *pStatsCollection = - (sal_statistics_collection_t *)device->pQatStats; - - if (CPA_TRUE == pStatsCollection->bStatsEnabled) - { - /* Clean stats */ - if (NULL != pCryptoService->debug_file) - { - LAC_OS_FREE(pCryptoService->debug_file->name); - LAC_OS_FREE(pCryptoService->debug_file); - pCryptoService->debug_file = NULL; - } - } -} - -STATIC void SalCtrl_DebugShutdown(icp_accel_dev_t *device, +STATIC void SalCtrl_StatsShutdown(icp_accel_dev_t *device, sal_service_t *service) { sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - SalCtrl_DebugCleanup(device, service); pCryptoService->generic_service_info.stats = NULL; } -STATIC void SalCtrl_DebugRestarting(icp_accel_dev_t *device, - sal_service_t *service) -{ - SalCtrl_DebugCleanup(device, service); -} - -STATIC CpaStatus SalCtrl_DebugInit(icp_accel_dev_t *device, - sal_service_t *service) +STATIC void SalCtrl_StatsInit(icp_accel_dev_t *device, sal_service_t *service) { - char adfGetParam[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char temp_string[SAL_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char *instance_name = NULL; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; sal_statistics_collection_t *pStatsCollection = (sal_statistics_collection_t *)device->pQatStats; - CpaStatus status = CPA_STATUS_SUCCESS; - char *section = icpGetProcessName(); - - if (CPA_TRUE == pStatsCollection->bStatsEnabled) - { - /* Get instance name for stats */ - status = LAC_OS_MALLOC(&instance_name, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - LAC_CHECK_STATUS(status); - - status = - Sal_StringParsing(SAL_CFG_CY, - pCryptoService->generic_service_info.instance, - SAL_CFG_NAME, - temp_string); - if (CPA_STATUS_SUCCESS != status) - { - LAC_OS_FREE(instance_name); - return status; - } - status = - icp_adf_cfgGetParamValue(device, section, temp_string, adfGetParam); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_STRING_ERROR1("Failed to get %s from configuration file", - temp_string); - LAC_OS_FREE(instance_name); - return status; - } - snprintf( - instance_name, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "%s", adfGetParam); - status = LAC_OS_MALLOC(&pCryptoService->debug_file, - sizeof(debug_file_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - LAC_OS_FREE(instance_name); - return status; - } - osalMemSet(pCryptoService->debug_file, 0, sizeof(debug_file_info_t)); - pCryptoService->debug_file->name = instance_name; - pCryptoService->debug_file->seq_read = SalCtrl_CryptoDebug; - pCryptoService->debug_file->private_data = pCryptoService; - pCryptoService->debug_file->parent = - pCryptoService->generic_service_info.debug_parent_dir; - } pCryptoService->generic_service_info.stats = pStatsCollection; - - return status; } STATIC CpaStatus SalCtrl_GetBankNum(icp_accel_dev_t *device, @@ -2219,9 +1503,7 @@ CpaStatus SalCtrl_CryptoInit(icp_accel_dev_t *device, sal_service_t *service) SalCtrl_CyQueryCapabilities(service, &pCryptoService->capInfo); - /* Create debug directory for service */ - status = SalCtrl_DebugInit(device, service); - LAC_CHECK_STATUS(status); + SalCtrl_StatsInit(device, service); switch (svc_type) { @@ -2230,7 +1512,7 @@ CpaStatus SalCtrl_CryptoInit(icp_accel_dev_t *device, sal_service_t *service) status = SalCtrl_AsymInit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } break; @@ -2239,7 +1521,7 @@ CpaStatus SalCtrl_CryptoInit(icp_accel_dev_t *device, sal_service_t *service) status = SalCtrl_SymInit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } break; @@ -2248,14 +1530,14 @@ CpaStatus SalCtrl_CryptoInit(icp_accel_dev_t *device, sal_service_t *service) status = SalCtrl_AsymInit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } #endif status = SalCtrl_SymInit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); #ifndef ASYM_NOT_SUPPORTED SalCtrl_AsymFreeResources(pCryptoService); #endif @@ -2361,7 +1643,7 @@ CpaStatus SalCtrl_CryptoShutdown(icp_accel_dev_t *device, break; } - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); pCryptoService->generic_service_info.state = SAL_SERVICE_STATE_SHUTDOWN; @@ -2452,8 +1734,6 @@ CpaStatus SalCtrl_CryptoRestarting(icp_accel_dev_t *device, break; } - SalCtrl_DebugRestarting(device, service); - pCryptoService->generic_service_info.state = SAL_SERVICE_STATE_RESTARTING; return status; @@ -2477,9 +1757,7 @@ CpaStatus SalCtrl_CryptoRestarted(icp_accel_dev_t *device, SalCtrl_CyQueryCapabilities(service, &pCryptoService->capInfo); - /* Create debug directory for service */ - status = SalCtrl_DebugInit(device, service); - LAC_CHECK_STATUS(status); + SalCtrl_StatsInit(device, service); switch (svc_type) { @@ -2488,7 +1766,7 @@ CpaStatus SalCtrl_CryptoRestarted(icp_accel_dev_t *device, status = SalCtrl_AsymReinit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } break; @@ -2497,7 +1775,7 @@ CpaStatus SalCtrl_CryptoRestarted(icp_accel_dev_t *device, status = SalCtrl_SymReinit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } break; @@ -2506,14 +1784,14 @@ CpaStatus SalCtrl_CryptoRestarted(icp_accel_dev_t *device, status = SalCtrl_AsymReinit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); return status; } #endif status = SalCtrl_SymReinit(device, service); if (CPA_STATUS_SUCCESS != status) { - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); #ifndef ASYM_NOT_SUPPORTED SalCtrl_AsymFreeResources(pCryptoService); #endif @@ -2521,7 +1799,7 @@ CpaStatus SalCtrl_CryptoRestarted(icp_accel_dev_t *device, } break; default: - SalCtrl_DebugShutdown(device, service); + SalCtrl_StatsShutdown(device, service); LAC_LOG_ERROR("Invalid service type\n"); status = CPA_STATUS_FAIL; break; @@ -2730,6 +2008,33 @@ CpaStatus SalCtrl_CySymQueryCapabilities(sal_service_t *pGenericService, CPA_BITMAP_BIT_SET(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_SNOW3G_UEA2); CPA_BITMAP_BIT_SET(pCapInfo->hashes, CPA_CY_SYM_HASH_SNOW3G_UIA2); } + + /* Enable only supported algorithm list for Cipher and Hash for Gen6 device + */ + if (pGenericService->isGen6) + { + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_AES_CBC); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_AES_CCM); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_AES_ECB); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_AES_GMAC); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_AES_CCM); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_AES_XCBC); + if (!(pGenericService->capabilitiesMask & + ICP_ACCEL_CAPABILITIES_WIRELESS_CRYPTO_EXT)) + { + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_AES_CMAC); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_SNOW3G_UIA2); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_NULL); + } + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_AES_CBC_MAC); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_KASUMI_F9); + CPA_BITMAP_BIT_CLEAR(pCapInfo->hashes, CPA_CY_SYM_HASH_SM3); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_SM4_ECB); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_SM4_CBC); + CPA_BITMAP_BIT_CLEAR(pCapInfo->ciphers, CPA_CY_SYM_CIPHER_SM4_CTR); + pCapInfo->partialPacketSupported = CPA_FALSE; + } + return CPA_STATUS_SUCCESS; } @@ -3633,7 +2938,7 @@ CpaInstanceHandle Lac_GetFirstHandle(sal_service_type_t svc_type) cyInst = Lac_GetFirstCyHandle(adfInsts, num_cy_dev); break; default: - LAC_LOG_ERROR("Invalid service type!\n"); + /* All other types are rejected by the first switch above */ break; } if (NULL == cyInst) diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_ctrl_services.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_ctrl_services.c index 1a7b081b..9dec2ddf 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_ctrl_services.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_ctrl_services.c @@ -41,7 +41,6 @@ #include "icp_adf_cfg.h" #include "icp_adf_init.h" #include "icp_adf_accel_mgr.h" -#include "icp_adf_debug.h" /* SAL includes */ #include "lac_log.h" @@ -73,40 +72,9 @@ #define INLINE_SERVICE "inline" static char *subsystem_name = "SAL"; -/**< Name used by ADF to identify this component. */ -#ifndef ICP_DC_ONLY -static char *cy_dir_name = CY_SERVICE; -static char *asym_dir_name = ASYM_SERVICE; -static char *sym_dir_name = SYM_SERVICE; -#endif -static char *dc_dir_name = DC_SERVICE; -static char *decomp_dir_name = DECOMP_SERVICE; -/**< Stats dir names. */ -static char *ver_file_name = "version"; static subservice_registation_handle_t sal_service_reg_handle; -static inline const char *get_sku_info(enum dev_sku_info info) -{ - switch (info) - { - case DEV_SKU_1: - return "SKU1"; - case DEV_SKU_2: - return "SKU2"; - case DEV_SKU_3: - return "SKU3"; - case DEV_SKU_4: - return "SKU4"; - case DEV_SKU_VF: - return "SKUVF"; - case DEV_SKU_UNKNOWN: - default: - break; - } - return "Unknown SKU"; -} - /**< Data structure used by ADF to keep a reference to this component. */ /* @@ -509,13 +477,11 @@ static void SalCtrl_ServiceFreeResource(sal_list_t *services) * * @param[in] device An icp_accel_dev_t* type * @param[in] services A pointer to the container of services - * @param[in] dbg_dir A pointer to the debug directory * @param[in] svc_type The type of the service instance * ****************************************************************************/ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, sal_list_t **services, - debug_dir_info_t **debug_dir, sal_service_type_t svc_type) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -524,12 +490,6 @@ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, /* Call Shutdown function for each service instance */ SAL_FOR_EACH(*services, sal_service_t, device, shutdown, status); - if (*debug_dir) - { - LAC_OS_FREE(*debug_dir); - *debug_dir = NULL; - } - /* Free Sal services controller memory */ SalCtrl_ServiceFreeResource(*services); SalList_free(services); @@ -557,8 +517,6 @@ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, * * @param[in] device An icp_accel_dev_t* type * @param[in] services A pointer to the container of services - * @param[in] dbg_dir A pointer to the debug directory - * @param[in] dbg_dir_name Name of the debug directory * @param[in] tail_list SAL's list of services * @param[in] instance_count Number of instances * @param[in] svc_type The type of the service instance @@ -566,8 +524,6 @@ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, *************************************************************************/ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, sal_list_t **services, - debug_dir_info_t **dbg_dir, - char *dbg_dir_name, sal_list_t *tail_list, Cpa32U instance_count, sal_service_type_t svc_type) @@ -575,19 +531,9 @@ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, CpaStatus status = CPA_STATUS_SUCCESS; sal_service_t *pInst = NULL; Cpa32U i = 0; - debug_dir_info_t *debug_dir = NULL; sal_statistics_collection_t *pStats = (sal_statistics_collection_t *)device->pQatStats; - status = LAC_OS_MALLOC(&debug_dir, sizeof(debug_dir_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR("Failed to allocate memory for debug dir"); - return status; - } - debug_dir->name = dbg_dir_name; - debug_dir->parent = NULL; - for (i = 0; i < instance_count; i++) { status = SalCtrl_ServiceCreate(svc_type, i, &pInst); @@ -595,12 +541,14 @@ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, { break; } - pInst->debug_parent_dir = debug_dir; pInst->capabilitiesMask = device->accelCapabilitiesMask; pInst->isGen4 = IS_QAT_GEN4(device->deviceType); - pInst->isGen4_2 = IS_QAT_GEN4_2(device->deviceType); + pInst->isGen6 = IS_QAT_6XXX(device->deviceType); + if (pInst->isGen6) + pInst->dpaSupport = CPA_TRUE; + pInst->ns_isCnvErrorInjection = ICP_QAT_FW_COMP_NO_CNV_DFX; - if (pInst->isGen4) + if (pInst->isGen4 || pInst->isGen6) { pInst->optimisedCurveSupport = CPA_TRUE; } @@ -617,8 +565,6 @@ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, if (CPA_STATUS_SUCCESS != status) { LAC_LOG_ERROR("Failed to allocate all instances"); - LAC_OS_FREE(debug_dir); - debug_dir = NULL; SalCtrl_ServiceFreeResource(*services); SalList_free(services); return status; @@ -627,7 +573,6 @@ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, if (CPA_STATUS_SUCCESS != status) { LAC_LOG_ERROR("Failed to Initialize Misc Error Stats"); - LAC_OS_FREE(debug_dir); SalCtrl_ServiceFreeResource(*services); SalList_free(services); return status; @@ -643,16 +588,12 @@ STATIC CpaStatus SalCtrl_ServiceInit(icp_accel_dev_t *device, device, shutdown, SAL_SERVICE_STATE_INITIALIZED); - LAC_OS_FREE(debug_dir); - debug_dir = NULL; Sal_CleanMiscErrStats(pInst); SalCtrl_ServiceFreeResource(*services); SalList_free(services); return status; } - /* initialize the debug directory for relevant service */ - *dbg_dir = debug_dir; return status; } @@ -798,23 +739,15 @@ STATIC CpaStatus SalCtrl_ServiceError(icp_accel_dev_t *device, * * @param[in] device An icp_accel_dev_t* type * @param[in] services A pointer to the container of services - * @param[in] dbg_dir A pointer to the debug directory * *************************************************************************/ STATIC CpaStatus SalCtrl_ServiceRestarting(icp_accel_dev_t *device, - sal_list_t *services, - debug_dir_info_t **debug_dir) + sal_list_t *services) { CpaStatus status = CPA_STATUS_SUCCESS; sal_list_t *curr_element = services; sal_service_t *service = NULL; - if (*debug_dir) - { - LAC_OS_FREE(*debug_dir); - *debug_dir = NULL; - } - while (NULL != curr_element) { service = (sal_service_t *)SalList_getObject(curr_element); @@ -852,36 +785,22 @@ STATIC CpaStatus SalCtrl_ServiceRestarting(icp_accel_dev_t *device, * * @param[in] device An icp_accel_dev_t* type * @param[in] services A pointer to the container of services - * @param[in] dbg_dir A pointer to the debug directory * *************************************************************************/ STATIC CpaStatus SalCtrl_ServiceRestarted(icp_accel_dev_t *device, sal_list_t **services, - debug_dir_info_t **dbg_dir, - char *dbg_dir_name, sal_list_t *tail_list, Cpa32U instance_count, sal_service_type_t svc_type) { CpaStatus status = CPA_STATUS_SUCCESS; - debug_dir_info_t *debug_dir = NULL; sal_list_t *curr_element = *services; sal_service_t *service = NULL; - status = LAC_OS_MALLOC(&debug_dir, sizeof(debug_dir_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR("Failed to allocate memory for debug dir"); - return status; - } - debug_dir->name = dbg_dir_name; - debug_dir->parent = NULL; - while (NULL != curr_element) { service = (sal_service_t *)SalList_getObject(curr_element); - service->debug_parent_dir = debug_dir; if (CPA_TRUE == service->isInstanceStarted) { @@ -910,118 +829,8 @@ STATIC CpaStatus SalCtrl_ServiceRestarted(icp_accel_dev_t *device, } curr_element = SalList_next(curr_element); } - /* initialize the debug directory for relevant service */ - *dbg_dir = debug_dir; - return status; -} - -/* - * @ingroup SalCtrl - * @description - * This function is used to print hardware and software versions in proc - * filesystem entry via ADF Debug interface - * - * @context - * This functions is called from proc filesystem interface - * - * @assumptions - * None - * @sideEffects - * None - * @reentrant - * No - * @threadSafe - * Yes - * - * @param[in] private_data A pointer to a private data passed to the - * function while adding a debug file. - * @param[out] data Pointer to a buffer where version information - * needs to be printed to. - * @param[in] size Size of a buffer pointed by data. - * @param[in] offset Offset in a debug file - * - * @retval 0 This function always returns 0 - */ -STATIC int SalCtrl_VersionDebug(void *private_data, - char *data, - int size, - int offset) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - Cpa32U len = 0; - icp_accel_dev_t *device = (icp_accel_dev_t *)private_data; - char param_value[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - - len += snprintf(data + len, - size - len, - SEPARATOR BORDER - " Hardware and Software versions for device %d " BORDER - "\n" SEPARATOR, - device->accelId); - - osalMemSet(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - status = icp_adf_cfgGetParamValue( - device, LAC_CFG_SECTION_GENERAL, ADF_HW_REV_ID_KEY, param_value); - LAC_CHECK_STATUS(status); - len += snprintf(data + len, - size - len, - " Hardware Version: %s %s \n", - param_value, - get_sku_info(device->sku)); - - osalMemSet(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - status = icp_adf_cfgGetParamValue( - device, LAC_CFG_SECTION_GENERAL, ADF_UOF_VER_KEY, param_value); - LAC_CHECK_STATUS(status); - - len += snprintf(data + len, - size - len, - " Firmware Version: %s \n", - param_value); -#ifndef ICP_DC_ONLY - osalMemSet(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - status = icp_adf_cfgGetParamValue( - device, LAC_CFG_SECTION_GENERAL, ADF_MMP_VER_KEY, param_value); - LAC_CHECK_STATUS(status); - - len += snprintf(data + len, - size - len, - " MMP Version: %s \n", - param_value); -#endif - len += snprintf(data + len, - size - len, - " Driver Version: %d.%d.%d \n", - QAT_LIBRARY_VERSION_MAJOR, - QAT_LIBRARY_VERSION_MINOR, - QAT_LIBRARY_VERSION_PATCH); - - osalMemSet(param_value, 0, ADF_CFG_MAX_VAL_LEN_IN_BYTES); - status = icp_adf_cfgGetParamValue(device, - LAC_CFG_SECTION_GENERAL, - ICP_CFG_LO_COMPATIBLE_DRV_KEY, - param_value); - LAC_CHECK_STATUS(status); - - len += snprintf(data + len, - size - len, - " Lowest Compatible Driver: %s \n", - param_value); - - len += snprintf(data + len, - size - len, - " QuickAssist API CY Version: %d.%d \n", - CPA_CY_API_VERSION_NUM_MAJOR, - CPA_CY_API_VERSION_NUM_MINOR); - len += snprintf(data + len, - size - len, - " QuickAssist API DC Version: %d.%d \n", - CPA_DC_API_VERSION_NUM_MAJOR, - CPA_DC_API_VERSION_NUM_MINOR); - - snprintf(data + len, size - len, SEPARATOR); - return 0; + return status; } /************************************************************************** @@ -1064,7 +873,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, { status = SalCtrl_ServiceShutdown(device, &service_container->crypto_services, - &service_container->cy_dir, SAL_SERVICE_TYPE_CRYPTO); if (CPA_STATUS_SUCCESS != status) { @@ -1077,7 +885,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, { status = SalCtrl_ServiceShutdown(device, &service_container->asym_services, - &service_container->asym_dir, SAL_SERVICE_TYPE_CRYPTO_ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1089,7 +896,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, { status = SalCtrl_ServiceShutdown(device, &service_container->sym_services, - &service_container->sym_dir, SAL_SERVICE_TYPE_CRYPTO_SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1103,7 +909,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, status = SalCtrl_ServiceShutdown(device, &service_container->compression_services, - &service_container->dc_dir, SAL_SERVICE_TYPE_COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1117,7 +922,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, status = SalCtrl_ServiceShutdown(device, &service_container->decompression_services, - &service_container->decomp_dir, SAL_SERVICE_TYPE_DECOMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1139,12 +943,6 @@ STATIC CpaStatus SalCtrl_ServiceEventShutdown(icp_accel_dev_t *device, SalList_free(&service_container->crypto_services); } - if (service_container->ver_file) - { - LAC_OS_FREE(service_container->ver_file); - service_container->ver_file = NULL; - } - /* Free container also */ osalMemFree(service_container); device->pSalHandle = NULL; @@ -1192,6 +990,8 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, return status; } + LacLogMsg_SetConfig(device); + service_container = osalMemAlloc(sizeof(sal_t)); if (NULL == service_container) { @@ -1205,27 +1005,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, service_container->compression_services = NULL; service_container->decompression_services = NULL; - service_container->asym_dir = NULL; - service_container->sym_dir = NULL; - service_container->cy_dir = NULL; - service_container->dc_dir = NULL; - service_container->decomp_dir = NULL; - service_container->ver_file = NULL; - - status = - LAC_OS_MALLOC(&service_container->ver_file, sizeof(debug_file_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - osalMemFree(service_container); - return status; - } - - osalMemSet(service_container->ver_file, 0, sizeof(debug_file_info_t)); - service_container->ver_file->name = ver_file_name; - service_container->ver_file->seq_read = SalCtrl_VersionDebug; - service_container->ver_file->private_data = device; - service_container->ver_file->parent = NULL; - #ifndef ICP_DC_ONLY if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_CRYPTO_ASYM)) @@ -1238,8 +1017,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, } status = SalCtrl_ServiceInit(device, &service_container->asym_services, - &service_container->asym_dir, - asym_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO_ASYM); @@ -1259,8 +1036,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, } status = SalCtrl_ServiceInit(device, &service_container->sym_services, - &service_container->sym_dir, - sym_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO_SYM); @@ -1280,8 +1055,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, } status = SalCtrl_ServiceInit(device, &service_container->crypto_services, - &service_container->cy_dir, - cy_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO); @@ -1302,8 +1075,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, } status = SalCtrl_ServiceInit(device, &service_container->compression_services, - &service_container->dc_dir, - dc_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_COMPRESSION); @@ -1323,8 +1094,6 @@ STATIC CpaStatus SalCtrl_ServiceEventInit(icp_accel_dev_t *device, } status = SalCtrl_ServiceInit(device, &service_container->decompression_services, - &service_container->decomp_dir, - decomp_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_DECOMPRESSION); @@ -1649,9 +1418,8 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarting(icp_accel_dev_t *device, if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_CRYPTO_ASYM)) { - status = SalCtrl_ServiceRestarting(device, - service_container->asym_services, - &service_container->asym_dir); + status = + SalCtrl_ServiceRestarting(device, service_container->asym_services); if (CPA_STATUS_SUCCESS != status) { return status; @@ -1660,9 +1428,8 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarting(icp_accel_dev_t *device, if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_CRYPTO_SYM)) { - status = SalCtrl_ServiceRestarting(device, - service_container->sym_services, - &service_container->sym_dir); + status = + SalCtrl_ServiceRestarting(device, service_container->sym_services); if (CPA_STATUS_SUCCESS != status) { return status; @@ -1672,8 +1439,7 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarting(icp_accel_dev_t *device, if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_CRYPTO)) { status = SalCtrl_ServiceRestarting(device, - service_container->crypto_services, - &service_container->cy_dir); + service_container->crypto_services); if (CPA_STATUS_SUCCESS != status) { return status; @@ -1683,10 +1449,8 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarting(icp_accel_dev_t *device, if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_COMPRESSION)) { - status = - SalCtrl_ServiceRestarting(device, - service_container->compression_services, - &service_container->dc_dir); + status = SalCtrl_ServiceRestarting( + device, service_container->compression_services); if (CPA_STATUS_SUCCESS != status) { return status; @@ -1696,22 +1460,14 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarting(icp_accel_dev_t *device, if (SalCtrl_IsServiceEnabled(enabled_services, SAL_SERVICE_TYPE_DECOMPRESSION)) { - status = - SalCtrl_ServiceRestarting(device, - service_container->decompression_services, - &service_container->decomp_dir); + status = SalCtrl_ServiceRestarting( + device, service_container->decompression_services); if (CPA_STATUS_SUCCESS != status) { return status; } } - if (service_container->ver_file) - { - LAC_OS_FREE(service_container->ver_file); - service_container->ver_file = NULL; - } - return status; } @@ -1758,25 +1514,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, LAC_LOG_ERROR("Private data is NULL"); return CPA_STATUS_FATAL; } - service_container->asym_dir = NULL; - service_container->sym_dir = NULL; - service_container->cy_dir = NULL; - service_container->dc_dir = NULL; - service_container->decomp_dir = NULL; - service_container->ver_file = NULL; - - status = - LAC_OS_MALLOC(&service_container->ver_file, sizeof(debug_file_info_t)); - if (CPA_STATUS_SUCCESS != status) - { - goto err_restarted; - } - - osalMemSet(service_container->ver_file, 0, sizeof(debug_file_info_t)); - service_container->ver_file->name = ver_file_name; - service_container->ver_file->seq_read = SalCtrl_VersionDebug; - service_container->ver_file->private_data = device; - service_container->ver_file->parent = NULL; #ifndef ICP_DC_ONLY if (SalCtrl_IsServiceEnabled(enabled_services, @@ -1790,8 +1527,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, } status = SalCtrl_ServiceRestarted(device, &service_container->asym_services, - &service_container->asym_dir, - asym_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO_ASYM); @@ -1811,8 +1546,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, } status = SalCtrl_ServiceRestarted(device, &service_container->sym_services, - &service_container->sym_dir, - sym_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO_SYM); @@ -1832,8 +1565,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, } status = SalCtrl_ServiceRestarted(device, &service_container->crypto_services, - &service_container->cy_dir, - cy_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_CRYPTO); @@ -1855,8 +1586,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, status = SalCtrl_ServiceRestarted(device, &service_container->compression_services, - &service_container->dc_dir, - dc_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_COMPRESSION); @@ -1878,8 +1607,6 @@ STATIC CpaStatus SalCtrl_ServiceEventRestarted(icp_accel_dev_t *device, status = SalCtrl_ServiceRestarted(device, &service_container->decompression_services, - &service_container->decomp_dir, - decomp_dir_name, tail_list, instance_count, SAL_SERVICE_TYPE_DECOMPRESSION); diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c deleted file mode 100644 index 14ae4728..00000000 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_resp_type.c +++ /dev/null @@ -1,182 +0,0 @@ -/*************************************************************************** - * - * SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2007-2026 Intel Corporation - * - * These contents may have been developed with support from one or more - * Intel-operated generative artificial intelligence solutions. - * - ***************************************************************************/ - -/** - *************************************************************************** - * @file sal_resp_type.c - * - * @description - * This file contains implementation of ResponseMode APIs - * allowing to configure an instance for POLL / EPOLL modes. - * - ***************************************************************************/ - -#include "adf_dev_ring_ctl.h" -#include "cpa.h" - -#include "lac_sal_types.h" -#include "lac_common.h" -#include "sal_types_compression.h" -#include "lac_log.h" -#include "lac_sal_types_crypto.h" - -CpaStatus cpaInstanceSetResponseMode( - const CpaInstanceHandle instanceHandle, - const CpaAccelerationServiceType accelerationServiceType, - const CpaInstanceResponseMode responseMode) -{ - icp_comms_trans_handle trans_handle_rx[2] = {NULL, NULL}; - sal_compression_service_t *pCompressionService = NULL; - sal_compression_service_t *pDecompressionService = NULL; - sal_crypto_service_t *pCyService = NULL; - CpaBoolean irq_enable = CPA_FALSE; - Cpa8U *pIsPolled = NULL; - int i, num_handles = 1; - -#ifdef ICP_PARAM_CHECK - LAC_CHECK_NULL_PARAM(instanceHandle); -#endif - - switch (responseMode) - { - case CPA_INST_RX_NOTIFY_NONE: - irq_enable = CPA_FALSE; - break; - case CPA_INST_RX_NOTIFY_BY_EVENT: - irq_enable = CPA_TRUE; - break; - default: - LAC_LOG_ERROR("Invalid Response Mode"); - return CPA_STATUS_UNSUPPORTED; - } - - switch (accelerationServiceType) - { - case CPA_ACC_SVC_TYPE_CRYPTO_SYM: - pCyService = (sal_crypto_service_t *)instanceHandle; - if (pCyService->generic_service_info.type != - SAL_SERVICE_TYPE_CRYPTO_SYM) - { - LAC_LOG_ERROR("Invalid Service Type"); - return CPA_STATUS_INVALID_PARAM; - } - trans_handle_rx[0] = pCyService->trans_handle_sym_rx; - pIsPolled = &pCyService->isPolled; - break; - case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: - pCyService = (sal_crypto_service_t *)instanceHandle; - if (pCyService->generic_service_info.type != - SAL_SERVICE_TYPE_CRYPTO_ASYM) - { - LAC_LOG_ERROR("Invalid Service Type"); - return CPA_STATUS_INVALID_PARAM; - } - trans_handle_rx[0] = pCyService->trans_handle_asym_rx; - pIsPolled = &pCyService->isPolled; - break; - case CPA_ACC_SVC_TYPE_CRYPTO: - pCyService = (sal_crypto_service_t *)instanceHandle; - if (pCyService->generic_service_info.type != - SAL_SERVICE_TYPE_CRYPTO) - { - LAC_LOG_ERROR("Invalid Service Type"); - return CPA_STATUS_INVALID_PARAM; - } - trans_handle_rx[0] = pCyService->trans_handle_sym_rx; - trans_handle_rx[1] = pCyService->trans_handle_asym_rx; - num_handles = 2; /* Only crypto has 2 handles */ - pIsPolled = &pCyService->isPolled; - break; - case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: - pCompressionService = (sal_compression_service_t *)instanceHandle; - trans_handle_rx[0] = pCompressionService->trans_handle_compression_rx; - pIsPolled = (Cpa8U *)&pCompressionService->isPolled; - break; - case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: - pDecompressionService = (sal_compression_service_t *)instanceHandle; - trans_handle_rx[0] = pDecompressionService->trans_handle_decompression_rx; - pIsPolled = (Cpa8U *)&pDecompressionService->isPolled; - break; - default: - LAC_LOG_ERROR("Invalid Acceleration Service Type"); - return CPA_STATUS_INVALID_PARAM; - } - - for (i = 0; i < num_handles; i++) - { - if (!trans_handle_rx[i]) - { - LAC_LOG_ERROR("trans_handle_rx is NULL"); - return CPA_STATUS_FAIL; - } - if (CPA_STATUS_SUCCESS != - icp_adf_transSetRespMode(trans_handle_rx[i], irq_enable)) - { - LAC_LOG_ERROR("icp_adf_transSetRespMode() failed"); - return CPA_STATUS_FAIL; - } - } - *pIsPolled = irq_enable ? SAL_RESP_EPOLL_CFG_FILE : SAL_RESP_POLL_CFG_FILE; - - return CPA_STATUS_SUCCESS; -} - -CpaStatus cpaInstanceGetResponseMode( - const CpaInstanceHandle instanceHandle, - const CpaAccelerationServiceType accelerationServiceType, - CpaInstanceResponseMode *responseMode) -{ - sal_compression_service_t *pCompressionService = NULL; - sal_compression_service_t *pDecompressionService = NULL; - sal_crypto_service_t *pCyService = NULL; - Cpa8U isPolled = SAL_RESP_POLL_CFG_FILE; - -#ifdef ICP_PARAM_CHECK - LAC_CHECK_NULL_PARAM(instanceHandle); - LAC_CHECK_NULL_PARAM(responseMode); -#endif - *responseMode = CPA_INST_RX_NOTIFY_NONE; - - switch (accelerationServiceType) - { - case CPA_ACC_SVC_TYPE_CRYPTO_SYM: - case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: - pCyService = (sal_crypto_service_t *)instanceHandle; - isPolled = pCyService->isPolled; - break; - case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: - pCompressionService = (sal_compression_service_t *)instanceHandle; - isPolled = pCompressionService->isPolled; - break; - case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: - pDecompressionService = (sal_compression_service_t *)instanceHandle; - isPolled = pDecompressionService->isPolled; - break; - default: - LAC_LOG_ERROR("Invalid Acceleration Service Type"); - return CPA_STATUS_INVALID_PARAM; - } - - if (isPolled == SAL_RESP_EPOLL_CFG_FILE) - { - *responseMode = CPA_INST_RX_NOTIFY_BY_EVENT; - } - else if (isPolled == SAL_RESP_POLL_CFG_FILE) - { - *responseMode = CPA_INST_RX_NOTIFY_NONE; - } - else - { - LAC_LOG_ERROR("Invalid Poll Mode"); - return CPA_STATUS_FAIL; - } - - return CPA_STATUS_SUCCESS; -} diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c new file mode 100644 index 00000000..52014acc --- /dev/null +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_transport_cfg.c @@ -0,0 +1,364 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ + +/** + *************************************************************************** + * @file sal_transport_cfg.c + * + * @description + * This file contains implementation of ResponseMode APIs + * allowing to configure an instance for POLL / EPOLL modes. + * + ***************************************************************************/ + +#include "adf_dev_ring_ctl.h" +#include "cpa.h" + +#include "lac_sal_types.h" +#include "lac_common.h" +#include "sal_types_compression.h" +#include "lac_log.h" +#include "lac_sal_types_crypto.h" + +STATIC CpaStatus SalCtrl_GetTransHandleRx( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + icp_comms_trans_handle *pTrans_handle_rx) +{ + sal_compression_service_t *pCompressionService = NULL; + sal_crypto_service_t *pCyService = NULL; + + switch (accelerationServiceType) + { + case CPA_ACC_SVC_TYPE_CRYPTO_SYM: + pCyService = (sal_crypto_service_t *)instanceHandle; + if (pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO_SYM && + pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO) + { + LAC_LOG_ERROR("Invalid Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + *pTrans_handle_rx = pCyService->trans_handle_sym_rx; + break; + case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: + pCyService = (sal_crypto_service_t *)instanceHandle; + if (pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO_ASYM && + pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO) + { + LAC_LOG_ERROR("Invalid Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + *pTrans_handle_rx = pCyService->trans_handle_asym_rx; + break; + case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: + pCompressionService = (sal_compression_service_t *)instanceHandle; + *pTrans_handle_rx = + pCompressionService->trans_handle_compression_rx; + break; + case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: + pCompressionService = (sal_compression_service_t *)instanceHandle; + *pTrans_handle_rx = + pCompressionService->trans_handle_decompression_rx; + break; + default: + LAC_LOG_ERROR("Invalid Acceleration Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + + if (!*pTrans_handle_rx) + { + LAC_LOG_ERROR("pTrans_handle_rx is NULL"); + return CPA_STATUS_FAIL; + } + + return CPA_STATUS_SUCCESS; +} + +CpaStatus cpaInstanceSetResponseMode( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + const CpaInstanceResponseMode responseMode) +{ + icp_comms_trans_handle trans_handle_rx[2] = { NULL, NULL }; + sal_compression_service_t *pCompressionService = NULL; + sal_compression_service_t *pDecompressionService = NULL; + sal_crypto_service_t *pCyService = NULL; + CpaBoolean irq_enable = CPA_FALSE; + Cpa8U *pIsPolled = NULL; + int i, num_handles = 1; + +#ifdef ICP_TRACE + LAC_LOG3("Called with params (0x%lx, %d, %d)\n", + (LAC_ARCH_UINT)instanceHandle, + accelerationServiceType, + responseMode); +#endif + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(instanceHandle); +#endif + + switch (responseMode) + { + case CPA_INST_RX_NOTIFY_NONE: + irq_enable = CPA_FALSE; + break; + case CPA_INST_RX_NOTIFY_BY_EVENT: + irq_enable = CPA_TRUE; + break; + default: + LAC_LOG_ERROR("Invalid Response Mode"); + return CPA_STATUS_UNSUPPORTED; + } + + switch (accelerationServiceType) + { + case CPA_ACC_SVC_TYPE_CRYPTO_SYM: + pCyService = (sal_crypto_service_t *)instanceHandle; + if (pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO_SYM) + { + LAC_LOG_ERROR("Invalid Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + trans_handle_rx[0] = pCyService->trans_handle_sym_rx; + pIsPolled = &pCyService->isPolled; + break; + case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: + pCyService = (sal_crypto_service_t *)instanceHandle; + if (pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO_ASYM) + { + LAC_LOG_ERROR("Invalid Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + trans_handle_rx[0] = pCyService->trans_handle_asym_rx; + pIsPolled = &pCyService->isPolled; + break; + case CPA_ACC_SVC_TYPE_CRYPTO: + pCyService = (sal_crypto_service_t *)instanceHandle; + if (pCyService->generic_service_info.type != + SAL_SERVICE_TYPE_CRYPTO) + { + LAC_LOG_ERROR("Invalid Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + trans_handle_rx[0] = pCyService->trans_handle_sym_rx; + trans_handle_rx[1] = pCyService->trans_handle_asym_rx; + num_handles = 2; /* Only crypto has 2 handles */ + pIsPolled = &pCyService->isPolled; + break; + case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: + pCompressionService = (sal_compression_service_t *)instanceHandle; + trans_handle_rx[0] = + pCompressionService->trans_handle_compression_rx; + pIsPolled = (Cpa8U *)&pCompressionService->isPolled; + break; + case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: + pDecompressionService = (sal_compression_service_t *)instanceHandle; + trans_handle_rx[0] = + pDecompressionService->trans_handle_decompression_rx; + pIsPolled = (Cpa8U *)&pDecompressionService->isPolled; + break; + default: + LAC_LOG_ERROR("Invalid Acceleration Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + + for (i = 0; i < num_handles; i++) + { + CpaStatus inflight_status = CPA_STATUS_SUCCESS; + Cpa32U maxInflightRequests = 0; + Cpa32U numInflightRequests = 0; + + if (!trans_handle_rx[i]) + { + LAC_LOG_ERROR("trans_handle_rx is NULL"); + return CPA_STATUS_FAIL; + } + + /* Check for inflight requests before switching mode */ + inflight_status = icp_adf_getInflightRequests( + trans_handle_rx[i], &maxInflightRequests, &numInflightRequests); + if (CPA_STATUS_SUCCESS != inflight_status) + { + LAC_LOG_ERROR1("Failed to get inflight requests (status=%d)", + inflight_status); + return CPA_STATUS_FAIL; + } + + if (numInflightRequests > 0) + { + LAC_LOG_ERROR1( + "Cannot switch response mode with %u inflight requests", + numInflightRequests); + return CPA_STATUS_RETRY; + } + (void)maxInflightRequests; + + if (CPA_STATUS_SUCCESS != + icp_adf_transSetRespMode(trans_handle_rx[i], irq_enable)) + { + LAC_LOG_ERROR("icp_adf_transSetRespMode() failed"); + return CPA_STATUS_FAIL; + } + } + *pIsPolled = irq_enable ? SAL_RESP_EPOLL_CFG_FILE : SAL_RESP_POLL_CFG_FILE; + + return CPA_STATUS_SUCCESS; +} + +CpaStatus cpaInstanceGetResponseMode( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + CpaInstanceResponseMode *responseMode) +{ + sal_compression_service_t *pCompressionService = NULL; + sal_compression_service_t *pDecompressionService = NULL; + sal_crypto_service_t *pCyService = NULL; + Cpa8U isPolled = SAL_RESP_POLL_CFG_FILE; + +#ifdef ICP_TRACE + LAC_LOG3("Called with params (0x%lx, %d, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle, + accelerationServiceType, + (LAC_ARCH_UINT)responseMode); +#endif + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(instanceHandle); + LAC_CHECK_NULL_PARAM(responseMode); +#endif + *responseMode = CPA_INST_RX_NOTIFY_NONE; + + switch (accelerationServiceType) + { + case CPA_ACC_SVC_TYPE_CRYPTO_SYM: + case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: + pCyService = (sal_crypto_service_t *)instanceHandle; + isPolled = pCyService->isPolled; + break; + case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: + pCompressionService = (sal_compression_service_t *)instanceHandle; + isPolled = pCompressionService->isPolled; + break; + case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: + pDecompressionService = (sal_compression_service_t *)instanceHandle; + isPolled = pDecompressionService->isPolled; + break; + default: + LAC_LOG_ERROR("Invalid Acceleration Service Type"); + return CPA_STATUS_INVALID_PARAM; + } + + if (isPolled == SAL_RESP_EPOLL_CFG_FILE) + { + *responseMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else if (isPolled == SAL_RESP_POLL_CFG_FILE) + { + *responseMode = CPA_INST_RX_NOTIFY_NONE; + } + else + { + LAC_LOG_ERROR("Invalid Poll Mode"); + return CPA_STATUS_FAIL; + } + + return CPA_STATUS_SUCCESS; +} + +CpaStatus cpaInstanceSetIntCoalescingTimer( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + const Cpa32U coalescingTimerInNs) +{ + /* + * CPA_ACC_SVC_TYPE_CRYPTO is not valid here; callers must use + * CPA_ACC_SVC_TYPE_CRYPTO_SYM or CPA_ACC_SVC_TYPE_CRYPTO_ASYM. + * SalCtrl_GetTransHandleRx returns CPA_STATUS_INVALID_PARAM for it. + */ + icp_comms_trans_handle trans_handle_rx = NULL; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_TRACE + LAC_LOG3("Called with params (0x%lx, %d, %u)\n", + (LAC_ARCH_UINT)instanceHandle, + accelerationServiceType, + coalescingTimerInNs); +#endif + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(instanceHandle); +#endif + + status = SalCtrl_GetTransHandleRx( + instanceHandle, accelerationServiceType, &trans_handle_rx); + if (CPA_STATUS_SUCCESS == status) + { + status = + icp_adf_transSetIntCoalTimer(trans_handle_rx, coalescingTimerInNs); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to set interrupt coalescing " + "information for the instance"); + } + } + + return status; +} + +CpaStatus cpaInstanceGetRxInterruptMetaData( + const CpaInstanceHandle instanceHandle, + const CpaAccelerationServiceType accelerationServiceType, + CpaRxInterruptMetaData *pInterruptData) +{ + icp_comms_trans_handle trans_handle_rx = NULL; + CpaStatus status = CPA_STATUS_SUCCESS; + +#ifdef ICP_TRACE + LAC_LOG3("Called with params (0x%lx, %d, 0x%lx)\n", + (LAC_ARCH_UINT)instanceHandle, + accelerationServiceType, + (LAC_ARCH_UINT)pInterruptData); +#endif + +#ifdef ICP_PARAM_CHECK + LAC_CHECK_NULL_PARAM(instanceHandle); + LAC_CHECK_NULL_PARAM(pInterruptData); +#endif + + status = SalCtrl_GetTransHandleRx( + instanceHandle, accelerationServiceType, &trans_handle_rx); + if (CPA_STATUS_SUCCESS == status) + { + status = icp_adf_transGetIntCoalTimerData( + trans_handle_rx, + &pInterruptData->coalescingTimerInNs, + &pInterruptData->coalescingTimerMaxInNs, + &pInterruptData->coalescingTimerGranularityInNs); + if (CPA_STATUS_SUCCESS != status) + { + LAC_LOG_ERROR("Failed to get interrupt coalescing " + "information for the instance"); + } + else + { + pInterruptData->reserved1 = 0; + pInterruptData->reserved2 = 0; + } + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/common/include/lac_common.h b/quickassist/lookaside/access_layer/src/common/include/lac_common.h index 1418a806..af65297e 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_common.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_common.h @@ -579,6 +579,33 @@ typedef enum } \ } while (0) +/** + ******************************************************************************* + * @ingroup LacCommon + * Checks capability for a crypto service instance and cache the status. + * + * @description + * This macro checks feature capability for a symmetric/asymmetric service + * instance and caches the status. + * + * @param[out] status Status of the capability check. + * @param[in] instanceHandle Instance handler of the target service + * instance. + * @param[in] capa Capability to be checked. + * + ******************************************************************************/ +#define SAL_GET_INSTANCE_CRYPTO_CAPABILITY_STATUS( \ + status, instanceHandle, capa) \ + do \ + { \ + CpaCyCapabilitiesInfo *pCyCapInfo; \ + pCyCapInfo = &((sal_crypto_service_t *)instanceHandle)->capInfo; \ + if (!pCyCapInfo->capa##Supported) \ + status = CPA_STATUS_UNSUPPORTED; \ + else \ + status = CPA_STATUS_SUCCESS; \ + } while (0) + /** ******************************************************************************* * @ingroup LacCommon @@ -1220,4 +1247,32 @@ static inline int lac_getServiceType(icp_adf_ringInfoService_t type) return SAL_RING_TYPE_NONE; } +/** + ******************************************************************************* + * @ingroup LacCommon + * This macro checks if the device is Gen6 + * + * @param[in] instanceHandle Instance Handle + * + * @return CPA_TRUE If device is Gen6 + * @return CPA_FALSE If device is not Gen6 + * + ******************************************************************************/ +#define IS_GEN6_DEV(instanceHandle) \ + ((((sal_service_t *)instanceHandle)->isGen6) ? CPA_TRUE : CPA_FALSE) + +/** + ******************************************************************************* + * @ingroup LacCommon + * This macro checks if the address is 4-byte aligned + * + * @param[in] address address + * + * @return CPA_TRUE If address is not 4-byte aligned + * @return CPA_FALSE If address is 4-byte aligned + * + ******************************************************************************/ +#define IS_4BYTE_ALIGNED(address) \ + ((((uintptr_t)address) % 4) ? CPA_FALSE : CPA_TRUE) + #endif /* LAC_COMMON_H */ diff --git a/quickassist/lookaside/access_layer/src/common/include/lac_log.h b/quickassist/lookaside/access_layer/src/common/include/lac_log.h index 43672ab9..1b96e0da 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_log.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_log.h @@ -179,6 +179,35 @@ /**< @ingroup LacLog * Internal macro that accepts 9 parameters in the string to be logged */ +#define _LAC_LOG_PARAM10_(level, \ + log, \ + param1, \ + param2, \ + param3, \ + param4, \ + param5, \ + param6, \ + param7, \ + param8, \ + param9, \ + param10) \ + (void)LAC_OSAL_LOG(level, \ + OSAL_LOG_DEV_STDERR, \ + "%s() - : " log "\n", \ + __func__, \ + param1, \ + param2, \ + param3, \ + param4, \ + param5, \ + param6, \ + param7, \ + param8, \ + param9, \ + param10) +/**< @ingroup LacLog + * Internal macro that accepts 10 parameters in the string to be logged */ + #define _LAC_LOG_STRING_PARAM1_(level, log, param1) \ (void)LAC_OSAL_LOG_STRING( \ level, OSAL_LOG_DEV_STDERR, "%s() - : " log "\n", __func__, param1) @@ -322,6 +351,33 @@ * Log a string with no prefix * (9 parameters in the string to be logged). */ +#define LAC_LOG10(log, \ + param1, \ + param2, \ + param3, \ + param4, \ + param5, \ + param6, \ + param7, \ + param8, \ + param9, \ + param10) \ + _LAC_LOG_PARAM10_(OSAL_LOG_LVL_USER, \ + log, \ + param1, \ + param2, \ + param3, \ + param4, \ + param5, \ + param6, \ + param7, \ + param8, \ + param9, \ + param10) +/**< @ingroup LacLog + * Log a string with no prefix + * (10 parameters in the string to be logged). */ + /************************** Lac Error Log Macros **************************/ #define LAC_LOG_ERROR(log) _LAC_LOG_PARAM0_(OSAL_LOG_LVL_ERROR, log) @@ -390,6 +446,7 @@ #define LAC_LOG_MSG_SYMCYKEY 3 #define LAC_LOG_MSG_PKE 4 #define LAC_LOG_MSG_DC 5 +#define LAC_LOG_MSG_KPT_PRO 6 void LacLogMsg_SetConfig(icp_accel_dev_t *device); void set_osal_log_debug_level(void); diff --git a/quickassist/lookaside/access_layer/src/common/include/lac_sal_types.h b/quickassist/lookaside/access_layer/src/common/include/lac_sal_types.h index fc4463f6..49b95cb2 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_sal_types.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_sal_types.h @@ -25,7 +25,6 @@ #include "lac_list.h" #include "icp_accel_devices.h" #include "sal_statistics.h" -#include "icp_adf_debug.h" #define SAL_CFG_BASE_DEC 10 #define SAL_CFG_BASE_HEX 16 @@ -132,9 +131,6 @@ typedef struct sal_service_s sal_statistics_collection_t *stats; /**< Pointer to device statistics configuration */ - void *debug_parent_dir; - /**< Pointer to parent proc dir entry */ - Cpa32U capabilitiesMask; /**< Capabilities mask of the device */ @@ -145,10 +141,13 @@ typedef struct sal_service_s /**< True if user called StartInstance on this instance */ CpaBoolean isGen4; - /* True if the device is qat_4xxx or qat_4xxxvf */ + /* True if the device is a Gen4 device (qat_4xxx/qat_4xxxvf or + * qat_420xx/qat_420xxvf) */ - CpaBoolean isGen4_2; - /* True if the device is qat_420xx or qat_420xxvf */ + CpaBoolean isGen6; + /* True if the device is qat_6xxxvf or qat_6xxx */ + CpaBoolean dpaSupport; + /* True if the device has DPA support */ CpaBoolean optimisedCurveSupport; /* True if optimised curves are supported */ @@ -180,35 +179,8 @@ typedef struct sal_s /**< Container of sal_compression_service_t */ sal_list_t *decompression_services; /**< Container of sal_compression_service_t for decomp only service */ - debug_dir_info_t *cy_dir; - /**< Container for crypto proc debug */ - debug_dir_info_t *asym_dir; - /**< Container for asym proc debug */ - debug_dir_info_t *sym_dir; - /**< Container for sym proc debug */ - debug_dir_info_t *dc_dir; - /**< Container for data compression proc debug */ - debug_dir_info_t *decomp_dir; - /**< Container for decompression only proc debug */ - debug_file_info_t *ver_file; - /**< Container for version debug file */ } sal_t; -/** - ***************************************************************************** - * @ingroup SalCtrl - * SAL debug structure - * - * @description - * Service debug handler - * - *****************************************************************************/ -typedef struct sal_service_debug_s -{ - icp_accel_dev_t *accel_dev; - debug_file_info_t debug_file; -} sal_service_debug_t; - /** ******************************************************************************* * @ingroup SalCtrl diff --git a/quickassist/lookaside/access_layer/src/common/include/lac_sal_types_crypto.h b/quickassist/lookaside/access_layer/src/common/include/lac_sal_types_crypto.h index f442f27b..69fbe63b 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_sal_types_crypto.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_sal_types_crypto.h @@ -27,7 +27,6 @@ #include "cpa_cy_sym_dp.h" #include "cpa_cy_im.h" -#include "icp_adf_debug.h" #include "lac_sal_types.h" #include "icp_adf_transport.h" #include "lac_mem_pools.h" @@ -60,6 +59,8 @@ typedef struct sal_crypto_service_s /**< Memory pool ID used for asymmetric operations */ lac_memory_pool_id_t lac_pke_align_pool; /**< Memory pool ID used for asymmetric operations */ + lac_memory_pool_id_t lac_pke_kpt_pool; + /**< Memory pool ID used for asymmetric KPT operations */ OsalAtomic *pLacSymStatsArr; /**< pointer to an array of atomic stats for symmetric */ @@ -146,9 +147,6 @@ typedef struct sal_crypto_service_s lac_sym_key_tls_hkdf_sub_labels_t *pTlsHKDFSubLabel; /**< pointer to memory holding the 4 HKDFLabels sublabels */ - debug_file_info_t *debug_file; - /**< Statistics handler */ - CpaCyCapabilitiesInfo capInfo; /* Cryptographic Capabilities Info */ diff --git a/quickassist/lookaside/access_layer/src/common/include/sal_qat_cmn_msg.h b/quickassist/lookaside/access_layer/src/common/include/sal_qat_cmn_msg.h index 82a69f94..95198d9d 100644 --- a/quickassist/lookaside/access_layer/src/common/include/sal_qat_cmn_msg.h +++ b/quickassist/lookaside/access_layer/src/common/include/sal_qat_cmn_msg.h @@ -167,6 +167,24 @@ void SalQatMsg_ContentDescHdrWrite( icp_qat_fw_comn_req_t *pMsg, const sal_qat_content_desc_info_t *pContentDescInfo); +/******************************************************************** + * @ingroup SalQatMsg_KptFlagHdrWrite + * + * @description + * This function fills in all fields related with KPT service in + * service extension field. + * + * + * @param[in] pExtSrvSpReqHdr Pointer to extended_serv_specif_flags + * field of request header. + * + * @return + * none + * + ********************************************************************/ +void SalQatMsg_KptFlagHdrWrite( + icp_qat_fw_ext_serv_specif_flags *pExtSrvSpReqHdr); + /******************************************************************** * @ingroup SalQatMsg_CtrlBlkSetToReserved * diff --git a/quickassist/lookaside/access_layer/src/common/include/sal_types_compression.h b/quickassist/lookaside/access_layer/src/common/include/sal_types_compression.h index 28ecf245..04abb1c3 100644 --- a/quickassist/lookaside/access_layer/src/common/include/sal_types_compression.h +++ b/quickassist/lookaside/access_layer/src/common/include/sal_types_compression.h @@ -123,9 +123,6 @@ typedef struct sal_compression_service_s Cpa32U coreAffinity; Cpa32U nodeAffinity; - /* Statistics handler */ - debug_file_info_t *debug_file; - /* Chaining service */ sal_dc_chain_service_t *pDcChainService; diff --git a/quickassist/lookaside/access_layer/src/common/qat_comms/sal_qat_cmn_msg.c b/quickassist/lookaside/access_layer/src/common/qat_comms/sal_qat_cmn_msg.c index 7ebd98b4..d2cde7c9 100644 --- a/quickassist/lookaside/access_layer/src/common/qat_comms/sal_qat_cmn_msg.c +++ b/quickassist/lookaside/access_layer/src/common/qat_comms/sal_qat_cmn_msg.c @@ -183,6 +183,27 @@ void SalQatMsg_ContentDescHdrWrite( } +/******************************************************************** + * @ingroup SalQatMsg_KptFlagHdrWrite + * + * @description + * This function fills the flags related with KPT service in + * field extended_serv_specif_flags of common PKE request header. + * + * @param[in] pCmnReqHdr Pointer to field extended_serv_specif_flags + * of common PKE request header. + * + * @return + * none + * + *******************************************************************/ +void SalQatMsg_KptFlagHdrWrite( + icp_qat_fw_ext_serv_specif_flags *pExtSrvSpReqHdr) +{ + ICP_QAT_FW_COMN_KPT_SERVICES_SET(*pExtSrvSpReqHdr, + QAT_COMN_KPT_SERVICE_FLAG); +} + /******************************************************************** * @ingroup SalQatMsg_CtrlBlkSetToReserved * diff --git a/quickassist/lookaside/access_layer/src/common/utils/lac_buffer_desc.c b/quickassist/lookaside/access_layer/src/common/utils/lac_buffer_desc.c index db4065ab..d2ed932a 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/lac_buffer_desc.c +++ b/quickassist/lookaside/access_layer/src/common/utils/lac_buffer_desc.c @@ -22,7 +22,6 @@ ******************************************************************************* */ #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "icp_adf_init.h" #include "lac_list.h" #include "lac_sal_types.h" diff --git a/quickassist/lookaside/access_layer/src/common/utils/lac_log_message.c b/quickassist/lookaside/access_layer/src/common/utils/lac_log_message.c index 234c73e3..5335dac8 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/lac_log_message.c +++ b/quickassist/lookaside/access_layer/src/common/utils/lac_log_message.c @@ -32,7 +32,6 @@ #include "icp_accel_devices.h" #include "sal_statistics.h" #include "sal_string_parse.h" -#include "icp_adf_debug.h" #include "lac_sal_types.h" /* diff --git a/quickassist/lookaside/access_layer/src/common/utils/lac_mem.c b/quickassist/lookaside/access_layer/src/common/utils/lac_mem.c index 04960c5f..0d38e34d 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/lac_mem.c +++ b/quickassist/lookaside/access_layer/src/common/utils/lac_mem.c @@ -27,7 +27,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" #include "lac_mem.h" #include "lac_mem_pools.h" @@ -86,7 +85,8 @@ Cpa8U *icp_LacBufferResize(CpaInstanceHandle instanceHandle, padSize = workingLen - userLen; /* check size */ - if (padSize > 0) + if ((padSize > 0) || + (IS_GEN6_DEV(instanceHandle) && !IS_4BYTE_ALIGNED(pUserBuffer))) { do { @@ -193,36 +193,15 @@ CpaPhysicalAddr SalMem_virt2PhysInternal(void *pVirtAddr, void *pServiceGen) size_t icp_sal_iommu_get_remap_size(size_t size) { -#if (defined(USER_SPACE) || defined(_WIN64)) - return osalIOMMUgetRemappingSize(size); -#else - int pages = size % PAGE_SIZE ? size / PAGE_SIZE + 1 : size / PAGE_SIZE; - size_t new_size = (pages * PAGE_SIZE); - return new_size; -#endif + return 0; } CpaStatus icp_sal_iommu_map(Cpa64U phaddr, Cpa64U iova, size_t size) { -#if (defined(USER_SPACE) || defined(_WIN64)) - return osalIOMMUMap((UINT64)phaddr, (UINT64)iova, size) == 0 - ? CPA_STATUS_SUCCESS - : CPA_STATUS_FAIL; -#else - void *virt_addr = phys_to_virt(phaddr); - return qdm_iommu_map((void *)(LAC_ARCH_UINT)iova, virt_addr, size) == 0 - ? CPA_STATUS_SUCCESS - : CPA_STATUS_FAIL; -#endif + return CPA_STATUS_UNSUPPORTED; } CpaStatus icp_sal_iommu_unmap(Cpa64U iova, size_t size) { -#if (defined(USER_SPACE) || defined(_WIN64)) - return osalIOMMUUnmap((UINT64)iova, size) == 0 ? CPA_STATUS_SUCCESS - : CPA_STATUS_FAIL; -#else - return qdm_iommu_unmap(iova, size) == 0 ? CPA_STATUS_SUCCESS - : CPA_STATUS_FAIL; -#endif + return CPA_STATUS_UNSUPPORTED; } diff --git a/quickassist/lookaside/access_layer/src/common/utils/lac_mem_pools.c b/quickassist/lookaside/access_layer/src/common/utils/lac_mem_pools.c index 0b920ed2..0fe488e4 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/lac_mem_pools.c +++ b/quickassist/lookaside/access_layer/src/common/utils/lac_mem_pools.c @@ -22,7 +22,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "icp_adf_debug.h" #include "lac_log.h" #include "lac_lock_free_stack.h" #include "lac_mem_pools.h" diff --git a/quickassist/lookaside/access_layer/src/common/utils/lac_sw_responses.c b/quickassist/lookaside/access_layer/src/common/utils/lac_sw_responses.c index 673194df..6867de43 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/lac_sw_responses.c +++ b/quickassist/lookaside/access_layer/src/common/utils/lac_sw_responses.c @@ -64,6 +64,29 @@ void LacSwResp_InitNumPoolsBusy(void) #ifndef ICP_DC_ONLY #ifndef ASYM_NOT_SUPPORTED +/** + ******************************************************************************* + * @ingroup LacSwResponses + * This function frees the bucket with memblks containing in-flight requests. + ******************************************************************************/ +STATIC +void LacSwResp_MemBlkBucketDestroy(lac_memblk_bucket_t *pBucket) +{ + if (NULL == pBucket) + { + return; + } + + if (NULL != pBucket->mem_blk) + { + osalMemFree(pBucket->mem_blk); + } + + osalMemFree(pBucket); + + return; +} + /** ******************************************************************************* * @ingroup LacSwResponses @@ -125,6 +148,15 @@ lac_memblk_bucket_t *LacSwResp_MemBlkBucketCreate(lac_mem_pool_hdr_t *pPoolID) continue; } pBucket->numBlksInRing++; + if (pBucketBlk[opaque % numBlksUsed] != NULL) + { + LAC_LOG_ERROR1( + "Software response generation failed! pBucket index %llu " + "is already occupied!", + opaque % numBlksUsed); + LacSwResp_MemBlkBucketDestroy(pBucket); + return NULL; + } pBucketBlk[opaque % numBlksUsed] = pCurrentBlk; if (opaque < seq) { @@ -135,29 +167,6 @@ lac_memblk_bucket_t *LacSwResp_MemBlkBucketCreate(lac_mem_pool_hdr_t *pPoolID) return pBucket; } -/** - ******************************************************************************* - * @ingroup LacSwResponses - * This function frees the bucket with memblks containing in-flight requests. - ******************************************************************************/ -STATIC -void LacSwResp_MemBlkBucketDestroy(lac_memblk_bucket_t *pBucket) -{ - if (NULL == pBucket) - { - return; - } - - if (NULL != pBucket->mem_blk) - { - osalMemFree(pBucket->mem_blk); - } - - osalMemFree(pBucket); - - return; -} - STATIC CpaStatus LacSwResp_GenRespMsgCallback(lac_memblk_bucket_t *pBucket, sal_service_type_t type) diff --git a/quickassist/lookaside/access_layer/src/common/utils/sal_misc_error_stats.c b/quickassist/lookaside/access_layer/src/common/utils/sal_misc_error_stats.c index 895cb37e..1aea336b 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/sal_misc_error_stats.c +++ b/quickassist/lookaside/access_layer/src/common/utils/sal_misc_error_stats.c @@ -30,7 +30,6 @@ #include "sal_statistics.h" #include "icp_adf_user_proxy.h" -#include "icp_adf_debug.h" #include "lac_sal_types.h" #include "lac_sal.h" diff --git a/quickassist/lookaside/access_layer/src/common/utils/sal_service_state.c b/quickassist/lookaside/access_layer/src/common/utils/sal_service_state.c index 820c3ade..0537b2a8 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/sal_service_state.c +++ b/quickassist/lookaside/access_layer/src/common/utils/sal_service_state.c @@ -25,7 +25,6 @@ #include "cpa.h" #include "lac_list.h" #include "icp_accel_devices.h" -#include "icp_adf_debug.h" #include "lac_sal_types.h" #include "sal_service_state.h" diff --git a/quickassist/lookaside/access_layer/src/common/utils/sal_statistics.c b/quickassist/lookaside/access_layer/src/common/utils/sal_statistics.c index a15a5072..635f04ac 100644 --- a/quickassist/lookaside/access_layer/src/common/utils/sal_statistics.c +++ b/quickassist/lookaside/access_layer/src/common/utils/sal_statistics.c @@ -28,7 +28,6 @@ #include "icp_accel_devices.h" #include "sal_statistics.h" -#include "icp_adf_debug.h" #include "lac_sal_types.h" #include "lac_sal.h" diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_cfg.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_cfg.c index 083c7709..cb6797da 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_cfg.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_cfg.c @@ -222,6 +222,16 @@ STATIC CpaStatus cfg_getValueFromDeviceInfo(const Cpa32U accelId, return CPA_STATUS_SUCCESS; } + if (!ICP_STRNCMP_CONST(pParamName, "osal_log_level_debug")) + { +#ifdef ICP_DEBUG + snprintf(pParamValue, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "1"); +#else + snprintf(pParamValue, ADF_CFG_MAX_VAL_LEN_IN_BYTES, "0"); +#endif + return CPA_STATUS_SUCCESS; + } + ADF_ERROR("Unsupported config parameter %s\n", pParamName); return CPA_STATUS_FAIL; } @@ -709,7 +719,7 @@ CpaStatus adf_io_getHeartBeatStatus(Cpa32U packageId) if (packageId == VM_PACKAGE_ID_NONE) { - ADF_ERROR("This API is not supported on a VM"); + ADF_ERROR("This API is not supported on a VM\n"); return CPA_STATUS_UNSUPPORTED; } @@ -774,7 +784,7 @@ CpaStatus adf_io_heartbeatSimulateFailure(Cpa32U packageId) if (packageId == VM_PACKAGE_ID_NONE) { - ADF_ERROR("This API is not supported on a VM"); + ADF_ERROR("This API is not supported on a VM\n"); return CPA_STATUS_UNSUPPORTED; } diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_bundles.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_bundles.c index 8742d0c3..e3384620 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_bundles.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_bundles.c @@ -31,6 +31,7 @@ #include "qat_mgr.h" #include "qat_log.h" #include "qae_mem.h" +#include "adf_platform_common.h" #define STATIC static @@ -110,7 +111,7 @@ STATIC int adf_populate_accel_dev(int dev_id, struct qatmgr_msg_rsp rsp = { 0 }; int device_name_len; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(accel_dev, -EINVAL); memset(accel_dev, '\0', sizeof(*accel_dev)); @@ -133,6 +134,7 @@ STATIC int adf_populate_accel_dev(int dev_id, accel_dev->fw_caps.deflate_caps = rsp.device_info.fw_caps.deflate_caps; accel_dev->fw_caps.lz4_caps = rsp.device_info.fw_caps.lz4_caps; accel_dev->fw_caps.lz4s_caps = rsp.device_info.fw_caps.lz4s_caps; + accel_dev->fw_caps.zstd_caps = rsp.device_info.fw_caps.zstd_caps; accel_dev->fw_caps.is_fw_caps = 1; } @@ -186,7 +188,7 @@ int adf_io_create_accel(icp_accel_dev_t **accel_dev, int dev_id) struct qatmgr_transport *t_mgr = NULL; int status = -1; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(accel_dev, -EINVAL); t_mgr = get_transport_mgr(); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_proxy.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_proxy.c index b009503b..d62d6f17 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_proxy.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_common_user_proxy.c @@ -41,7 +41,7 @@ STATIC int reopen_vfio_dev(vfio_dev_info_t *vfio_dev, int accelId, int pciDevId) int group_fd; int vfio_container_fd; - ICP_CHECK_FOR_NULL_PARAM(vfio_dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(vfio_dev, -EINVAL); /* Get device identifier */ req.device_num = accelId; if (qatmgr_query(&req, &rsp, QATMGR_MSGTYPE_DEVICE_ID)) @@ -200,11 +200,18 @@ CpaBoolean adf_vfio_poll_proxy_event(Cpa32U *dev_id, enum adf_event *event) Cpa16U i; Cpa16U msg_type = 0xFFFF; vfio_dev_info_t *vfio_dev; - icp_accel_dev_t *accel_tb[ADF_MAX_DEVICES]; + /* + * This array does not need to be static. However, it is declared this way + * to avoid excessive use of stack memory and potential stack-overflow in + * this function. + */ + static icp_accel_dev_t *accel_tb[ADF_MAX_DEVICES]; Cpa16U num_instances; ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev_id, CPA_FALSE); ICP_CHECK_FOR_NULL_PARAM_RET_CODE(event, CPA_FALSE); + + memset(accel_tb, 0, sizeof(accel_tb)); icp_adf_getNumInstances(&num_instances); icp_adf_getInstances(num_instances, &accel_tb[0]); for (i = 0; i < num_instances; ++i) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_msg.h b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_msg.h index 1569ac02..8a2b818d 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_msg.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_msg.h @@ -312,7 +312,7 @@ struct capabilities_v4 u32 deflate_caps; u16 lz4_caps; u16 lz4s_caps; - u16 resrvd; + u16 zstd_caps; } __packed; /* PF/VF Ring to service mapping values */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.c index b915c660..f41c2b9b 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.c @@ -26,6 +26,9 @@ #define ADF_PFVF_GEN4_MSGDATA_SHIFT 8 #define ADF_PFVF_GEN4_MSGDATA_MASK 0xFFFFFF +#define ADF_PFVF_GEN4_VFINTMSKPF2VM_OFFSET 0x1004 +#define ADF_PFVF_GEN4_VFINTMSKPF2VM_INT_DISABLE 0x1 + #define ADF_PFVF_GEN4_PF2VF_CSR_ADDR_OFFSET 0x1008 #define ADF_PFVF_GEN4_VF2PF_CSR_ADDR_OFFSET 0x100C @@ -60,6 +63,17 @@ struct adf_pfvf_dev_data adf_init_pfvf_dev_data(void *pmiscbar_addr, int dev_id) dev.type_mask = ADF_PFVF_GEN4_MSGTYPE_MASK; dev.data_mask = ADF_PFVF_GEN4_MSGDATA_MASK; + /* Mask PF2VF interrupt source to prevent it from sharing the + * single MSI vector with ring interrupts. An unmasked PF2VF + * message can permanently block ring MSI delivery and stall + * epoll-based applications. PF2VF messages have always been + * handled by CSR polling via icp_sal_poll_device_events(), + * not by interrupts, so masking removes an unused interrupt + * source that can only cause harm. */ + ICP_ADF_CSR_WR(pmiscbar_addr, + ADF_PFVF_GEN4_VFINTMSKPF2VM_OFFSET, + ADF_PFVF_GEN4_VFINTMSKPF2VM_INT_DISABLE); + return dev; } @@ -69,8 +83,8 @@ static int adf_pfvf_msg_ack_timed_out(struct adf_pfvf_dev_data *dev, { int count = 0; - ICP_CHECK_FOR_NULL_PARAM(dev); - ICP_CHECK_FOR_NULL_PARAM(last); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(last, -EINVAL); for (; count < ADF_PFVF_MSG_ACK_MAX_RETRIES; ++count) { usleep(ADF_PFVF_MSG_ACK_DELAY_US); @@ -88,7 +102,7 @@ static int adf_pfvf_gen4_send(struct adf_pfvf_dev_data *dev, int ret = 0; uint32_t raw_msg; - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); raw_msg = (msg.type << dev->type_shift) | (msg.data << dev->data_shift); raw_msg |= ADF_PFVF_INT | ADF_PFVF_MSGORIGIN_SYSTEM; ICP_ADF_CSR_WR(dev->pmiscbar_addr, dev->local_csr_offset, raw_msg); @@ -172,8 +186,8 @@ int adf_send_vf2pf_req(struct adf_pfvf_dev_data *dev, int response_received = 0; int status = -EIO; - ICP_CHECK_FOR_NULL_PARAM(dev); - ICP_CHECK_FOR_NULL_PARAM(resp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(resp, -EINVAL); do { err = adf_send_vf2pf_msg(dev, req); @@ -207,8 +221,8 @@ STATIC int adf_vf2pf_blkmsg_data_req(struct adf_pfvf_dev_data *dev, uint16_t max_payload_size; int err; - ICP_CHECK_FOR_NULL_PARAM(dev); - ICP_CHECK_FOR_NULL_PARAM(data); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(data, -EINVAL); /* Build the block message */ if (type <= ADF_VF2PF_MAX_SMALL_MESSAGE_TYPE) { @@ -317,8 +331,6 @@ static uint8_t adf_pfvf_crc(uint8_t start_crc, uint8_t *buf, uint8_t len) { uint8_t crc = start_crc; - ICP_CHECK_FOR_NULL_PARAM(buf); - while (len-- > 0) crc = pfvf_crc8_table[(crc ^ *buf++) & 0xff]; @@ -341,9 +353,9 @@ int adf_send_vf2pf_blkmsg_req(struct adf_pfvf_dev_data *dev, uint16_t msg_len; int ret; - ICP_CHECK_FOR_NULL_PARAM(dev); - ICP_CHECK_FOR_NULL_PARAM(buffer); - ICP_CHECK_FOR_NULL_PARAM(buffer_len); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(buffer, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(buffer_len, -EINVAL); if (type > ADF_VF2PF_MAX_LARGE_MESSAGE_TYPE) { diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.h b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.h index b997ae27..ac6a6cc2 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_proto.h @@ -20,6 +20,7 @@ struct fw_caps uint32_t deflate_caps; uint16_t lz4_caps; uint16_t lz4s_caps; + uint16_t zstd_caps; uint8_t is_fw_caps; }; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_vf_msg.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_vf_msg.c index ca469d2a..c29db768 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_vf_msg.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_pfvf_vf_msg.c @@ -54,7 +54,7 @@ int adf_vf2pf_notify_init(struct adf_pfvf_dev_data *dev) { struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_INIT }; - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); if (!adf_vf2pf_available()) return -EIO; @@ -121,7 +121,7 @@ int adf_vf2pf_check_compat_version(struct adf_pfvf_dev_data *dev) }; struct pfvf_message req; - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); if (!adf_vf2pf_available()) return -EIO; @@ -197,7 +197,7 @@ int adf_vf2pf_get_ring_to_svc(struct adf_pfvf_dev_data *dev) uint16_t len = sizeof(rts_map_msg); - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); if (!adf_vf2pf_available()) return -EIO; @@ -236,7 +236,7 @@ int adf_vf2pf_get_capabilities(struct adf_pfvf_dev_data *dev) uint16_t len = sizeof(cap_msg); int ret = 0; - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); if (!adf_vf2pf_available()) return -EIO; @@ -266,6 +266,7 @@ int adf_vf2pf_get_capabilities(struct adf_pfvf_dev_data *dev) dev->fw_caps.deflate_caps = cap_msg.deflate_caps; dev->fw_caps.lz4_caps = cap_msg.lz4_caps; dev->fw_caps.lz4s_caps = cap_msg.lz4s_caps; + dev->fw_caps.zstd_caps = cap_msg.zstd_caps; dev->fw_caps.is_fw_caps = 1; } else @@ -314,7 +315,7 @@ int adf_vf2pf_get_capabilities(struct adf_pfvf_dev_data *dev) int adf_check_pf2vf_notification(struct adf_pfvf_dev_data *dev) { struct pfvf_message msg; - ICP_CHECK_FOR_NULL_PARAM(dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -EINVAL); msg = adf_recv_pf2vf_msg(dev); return msg.type; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_vfio_pf.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_vfio_pf.c index 6f9d47bd..c7b8c848 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_vfio_pf.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/adf_vfio_pf.c @@ -72,7 +72,7 @@ Cpa32S adf_vfio_init_pfs_info(icp_accel_pf_info_t *pf_info, size_t pf_info_len) { unsigned domain, bus, dev, func; struct dirent **namelist = NULL; - int32_t i, j, number_of_pfs = 0, total_no_pfs = 0; + int32_t i, j, num_pfs_per_type = 0, total_num_pfs = 0; int status = CPA_STATUS_FAIL; char dev_path[QATMGR_MAX_STRLEN] = { '\0' }; char *device_name = NULL; @@ -86,45 +86,49 @@ Cpa32S adf_vfio_init_pfs_info(icp_accel_pf_info_t *pf_info, size_t pf_info_len) { snprintf( dev_path, sizeof(dev_path), "%s/%s", DEVVFIO_DIR, device_name); - number_of_pfs = + num_pfs_per_type = scandir(dev_path, &namelist, &filter_pf_in_use, alphasort); /* This shows scandir dir failed. */ - if (number_of_pfs < 0) + if (num_pfs_per_type < 0) { ADF_ERROR("Failed to scan directory %s\n", DEVVFIO_DIR); return CPA_STATUS_FAIL; } - total_no_pfs += number_of_pfs; - if (pf_info_len < total_no_pfs) + /* Check before adding to prevent overflow */ + if (num_pfs_per_type > (int32_t)pf_info_len - total_num_pfs) { - ADF_ERROR("Given pf info array length is too small for %d " - "number of PFs\n", - number_of_pfs); - for (i = 0; i < number_of_pfs; i++) + ADF_ERROR("Remaining pf info array length %d is too small" + " for %d PFs\n", + (int32_t)pf_info_len - total_num_pfs, + num_pfs_per_type); + for (i = 0; i < num_pfs_per_type; i++) { free(namelist[i]); } free(namelist); return CPA_STATUS_INVALID_PARAM; } - for (i = 0; i < number_of_pfs; i++) + for (i = 0; i < num_pfs_per_type; i++) { + int pf_info_idx = total_num_pfs + i; sscanf(namelist[i]->d_name, "%x:%x:%x.%x", &domain, &bus, &dev, &func); - pf_info[i].pkg_id = i; - pf_info[i].domain = domain; - pf_info[i].bdf = + pf_info[pf_info_idx].pkg_id = pf_info_idx; + pf_info[pf_info_idx].domain = domain; + pf_info[pf_info_idx].bdf = ((0xFF & bus) << 8) + ((0x1F & dev) << 3) + (0x07 & func); - strncpy( - pf_info[i].device_gen, device_name, ADF_DEVICE_TYPE_LENGTH); + strncpy(pf_info[pf_info_idx].device_gen, + device_name, + ADF_DEVICE_TYPE_LENGTH); free(namelist[i]); } + total_num_pfs += num_pfs_per_type; free(namelist); } } - return total_no_pfs; + return total_num_pfs; } diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr.h b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr.h index 39da850e..de59063f 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr.h @@ -68,7 +68,7 @@ #define MAX_PAYLOAD_SIZE \ MAX(sizeof(struct qatmgr_msg_req), sizeof(struct qatmgr_msg_rsp)) -#define MAX_DEVS 512 +#define MAX_DEVS ADF_MAX_DEVICES /* Below definitions are dependent on kernel drivers for creating the same * mapping @@ -80,16 +80,13 @@ #define CFG_SERV_RING_PAIR_2_SHIFT 6 #define CFG_SERV_RING_PAIR_3_SHIFT 9 -#ifndef ENABLE_DC +/* The default map is assumed if a kernel doesn't respond to pfvfcomms + * queries. Early kernel drivers did not support pfvfcomms and also set a + * fixed service map of asym/sym/asym/sym, so this is a reasonable assumption. + */ #define DEFAULT_RING_TO_SRV_MAP \ (ASYM | SYM << CFG_SERV_RING_PAIR_1_SHIFT | \ ASYM << CFG_SERV_RING_PAIR_2_SHIFT | SYM << CFG_SERV_RING_PAIR_3_SHIFT) -#else -#define DEFAULT_RING_TO_SRV_MAP \ - (COMP | DECOMP << CFG_SERV_RING_PAIR_1_SHIFT | \ - COMP << CFG_SERV_RING_PAIR_2_SHIFT | \ - DECOMP << CFG_SERV_RING_PAIR_3_SHIFT) -#endif #define DC_ONLY_RING_TO_SRV_MAP \ (COMP | COMP << CFG_SERV_RING_PAIR_1_SHIFT | \ COMP << CFG_SERV_RING_PAIR_2_SHIFT | COMP << CFG_SERV_RING_PAIR_3_SHIFT) @@ -172,6 +169,7 @@ struct fw_caps_qat uint32_t deflate_caps; uint16_t lz4_caps; uint16_t lz4s_caps; + uint16_t zstd_caps; uint8_t is_fw_caps; }; @@ -378,13 +376,12 @@ int qatmgr_close(void); void qat_mgr_cleanup_cfg(void); int qat_mgr_get_vfio_dev_list(unsigned *num_devices, struct qatmgr_dev_data *dev_list, - const unsigned list_size, - int keep_fd); + const unsigned list_size); int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], const int num_devices, int policy, - int static_cfg); + int keep_device_open); bool qat_mgr_is_vfio_dev_available(void); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_client.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_client.c index 96e4d902..c1a70086 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_client.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_client.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include "icp_platform.h" #include "qat_log.h" @@ -89,11 +91,11 @@ static int qatmgr_socket_open(struct qatmgr_transport *t_mgr) int adf_vfio_build_sconfig(void) { - int ret; + int ret, lock_fd; char *env; long long devs = -1; unsigned n; - int i, j; + int i; char *fin; env = getenv(QAT_ENV_POLICY); @@ -105,46 +107,78 @@ int adf_vfio_build_sconfig(void) qat_log(LOG_LEVEL_ERROR, "Invalid environment value \"%s\"\n", env); return -EINVAL; } + if (devs == 0) + { + qat_log(LOG_LEVEL_ERROR, + "QAT_POLICY=0 is not supported in standalone mode. " + "Use QAT_POLICY >= 1 or unset QAT_POLICY\n"); + return -EINVAL; + } + } + + /* Acquire exclusive lock on /dev/vfio to serialize enumeration */ + lock_fd = open("/dev/vfio", O_RDONLY | O_DIRECTORY); + if (lock_fd < 0) + { + qat_log(LOG_LEVEL_ERROR, + "Failed to open /dev/vfio for locking: errno=%d\n", + errno); + return -errno; + } + + if (flock(lock_fd, LOCK_EX) < 0) + { + qat_log(LOG_LEVEL_ERROR, + "Failed to acquire /dev/vfio lock: errno=%d\n", + errno); + close(lock_fd); + return -errno; } /* If QAT_POLICY is not set, reserve all devices but then use only * the first MAX_DEVS_NO_POLICY - * If QAT_POLICY is set to 0, enumerate all devices without reserving - * them (qat_mgr_build_data might fail when devices are opened) * if QAT_POLICY is set to >0, reserve the first n devices */ if (devs < 0) - ret = qat_mgr_get_vfio_dev_list(&n, dev_list, MAX_DEVS, 1); - else if (devs == 0) - ret = qat_mgr_get_vfio_dev_list(&n, dev_list, MAX_DEVS, 0); + ret = qat_mgr_get_vfio_dev_list(&n, dev_list, MAX_DEVS); else - ret = qat_mgr_get_vfio_dev_list(&n, dev_list, devs, 1); + ret = qat_mgr_get_vfio_dev_list(&n, dev_list, devs); if (ret) + { + flock(lock_fd, LOCK_UN); + close(lock_fd); return ret; + } /* If no device is found return an error */ if (n == 0) { qat_log(LOG_LEVEL_ERROR, "No device found\n"); + flock(lock_fd, LOCK_UN); + close(lock_fd); return -ENODEV; } - /* Avoid using all devices if policy is not set */ - if (n > MAX_DEVS_NO_POLICY && devs < 0) + /* Check if sufficient devices are available for the requested policy */ + if (devs > 0 && n < devs) { - for (i = 0, j = 0; i < n; i++) - { - if (dev_list[i].group_fd > 0 && j < MAX_DEVS_NO_POLICY) - { - j++; - } - else if (dev_list[i].group_fd > 0) - { - close(dev_list[i].group_fd); - dev_list[i].group_fd = -1; - } - } - devs = j; + qat_log(LOG_LEVEL_ERROR, + "Insufficient devices: requested %lld devices via QAT_POLICY, " + "but only %u devices available\n", + devs, + n); + flock(lock_fd, LOCK_UN); + close(lock_fd); + return -ENODEV; + } + + /* Set device count when no policy is specified */ + if (devs < 0) + { + if (n > MAX_DEVS_NO_POLICY) + devs = MAX_DEVS_NO_POLICY; + else + devs = n; } for (i = 0; i < n; i++) @@ -159,12 +193,12 @@ int adf_vfio_build_sconfig(void) BDF_FUN(dev_list[i].bdf)); } - if (devs < 0) - devs = n; - if ((ret = qat_mgr_vfio_build_data(dev_list, n, devs, 1))) - return ret; + ret = qat_mgr_vfio_build_data(dev_list, n, devs, 1); - return 0; + /* Release lock */ + flock(lock_fd, LOCK_UN); + close(lock_fd); + return ret; } int qatmgr_open(void) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_lib.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_lib.c index 6ec4cefb..5dab2e05 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_lib.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/qat_mgr_lib.c @@ -23,6 +23,8 @@ #define QAT_402XX_DEVICE_ID 0x4944 #define QAT_420XXVF_DEVICE_ID 0x4947 #define QAT_420XX_DEVICE_ID 0x4946 +#define QAT_6XXXVF_DEVICE_ID 0x4949 +#define QAT_6XXX_DEVICE_ID 0x4948 #define ADDITIONAL_BUF_LEN 2 @@ -57,7 +59,11 @@ static const char *qatmgr_msgtype_str[] = { #define QATMGR_MSGTYPES_STR_MAX \ (sizeof(qatmgr_msgtype_str) / sizeof(qatmgr_msgtype_str[0]) - 1) -char *device_names[] = { "4xxx", "420xx" }; +char *device_names[] = { "4xxx", + "420xx", + "6xxx", +}; + int device_names_size = sizeof(device_names) / sizeof(device_names[0]); struct pf_capabilities *pf_capabilities_head = NULL; @@ -128,6 +134,8 @@ int is_qat_device(unsigned device_id) case QAT_402XX_DEVICE_ID: case QAT_420XXVF_DEVICE_ID: case QAT_420XX_DEVICE_ID: + case QAT_6XXXVF_DEVICE_ID: + case QAT_6XXX_DEVICE_ID: return 1; default: return 0; @@ -150,6 +158,10 @@ int qat_device_type(int device_id) case QAT_4XXX_DEVICE_ID: case QAT_402XX_DEVICE_ID: return DEVICE_4XXX; + case QAT_6XXXVF_DEVICE_ID: + return DEVICE_6XXXVF; + case QAT_6XXX_DEVICE_ID: + return DEVICE_6XXX; default: return 0; } @@ -174,6 +186,10 @@ char *qat_device_name(int device_id) return "4xxx"; case QAT_402XX_DEVICE_ID: return "402xx"; + case QAT_6XXXVF_DEVICE_ID: + return "6xxxvf"; + case QAT_6XXX_DEVICE_ID: + return "6xxx"; default: return "unknown"; } @@ -639,8 +655,8 @@ STATIC int handle_get_num_devices(struct qatmgr_msg_req *req, { struct qatmgr_section_data *section; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr)) { @@ -673,8 +689,8 @@ STATIC int handle_get_device_info(struct qatmgr_msg_req *req, struct qatmgr_section_data *section; unsigned device_num; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + sizeof(req->device_num)) { @@ -746,6 +762,8 @@ STATIC int handle_get_device_info(struct qatmgr_msg_req *req, section->device_data[device_num].fw_caps.lz4_caps; rsp->device_info.fw_caps.lz4s_caps = section->device_data[device_num].fw_caps.lz4s_caps; + rsp->device_info.fw_caps.zstd_caps = + section->device_data[device_num].fw_caps.zstd_caps; rsp->device_info.fw_caps.is_fw_caps = 1; } @@ -763,8 +781,8 @@ STATIC int handle_get_device_id(struct qatmgr_msg_req *req, struct qatmgr_device_data *device_data; unsigned device_num; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + sizeof(req->device_num)) { @@ -813,8 +831,8 @@ static int handle_get_vfio_name(struct qatmgr_msg_req *req, unsigned device_num; size_t len; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + sizeof(req->device_num)) { @@ -843,6 +861,12 @@ static int handle_get_vfio_name(struct qatmgr_msg_req *req, device_data = section->device_data; device_data += device_num; + qat_log(LOG_LEVEL_DEBUG, + "handle_get_vfio_name: section=%s, device=%u, file=%s\n", + section->section_name, + device_num, + device_data->device_file); + rsp->hdr.type = QATMGR_MSGTYPE_VFIO_FILE; rsp->hdr.version = THIS_LIB_VERSION; rsp->vfio_file.fd = device_data->group_fd; @@ -873,8 +897,8 @@ STATIC int handle_get_instance_name(struct qatmgr_msg_req *req, int device_num; char *inst_name; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + sizeof(req->inst)) { @@ -1057,8 +1081,8 @@ STATIC int handle_get_instance_info(struct qatmgr_msg_req *req, int instance_num; int device_num; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + sizeof(req->inst)) { @@ -1201,7 +1225,7 @@ STATIC int handle_get_instance_info(struct qatmgr_msg_req *req, int release_section(int index, unsigned long id, char *name, size_t name_len) { - ICP_CHECK_FOR_NULL_PARAM(name); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(name, -EINVAL); /* * In standalone mode, id is the process id of the client. In managed @@ -1237,8 +1261,8 @@ int release_section(int index, unsigned long id, char *name, size_t name_len) section_data[index].assigned_id); return -1; } - qat_log(LOG_LEVEL_DEBUG, "Released section %s\n", name); section_data[index].assigned_id = 0; + qat_log(LOG_LEVEL_DEBUG, "Released section %s (id=%lu)\n", name, id); return 0; } @@ -1260,6 +1284,10 @@ STATIC int get_section(unsigned long id, char **derived_section_name) section_data[i].assigned_id = id; assigned = 1; + qat_log(LOG_LEVEL_DEBUG, + "Assigned section %s to id=%lu\n", + section_data[i].section_name, + id); break; } @@ -1292,9 +1320,9 @@ STATIC int handle_section_request(struct qatmgr_msg_req *req, static pid_t pid = 0; int name_buf_size; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); - ICP_CHECK_FOR_NULL_PARAM(index); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(index, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + ICP_ARRAY_STRLEN_SANITIZE(req->name) + 1) @@ -1369,10 +1397,10 @@ STATIC int handle_section_release(struct qatmgr_msg_req *req, unsigned long id, int *index) { - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); - ICP_CHECK_FOR_NULL_PARAM(index); - ICP_CHECK_FOR_NULL_PARAM(section_name); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(index, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(section_name, -EINVAL); if (req->hdr.len != sizeof(req->hdr) + ICP_ARRAY_STRLEN_SANITIZE(req->name) + 1) @@ -1414,8 +1442,8 @@ static int handle_get_num_pf_devices(struct qatmgr_msg_req *req, struct qatmgr_msg_rsp *rsp) { int32_t num_devices; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); if (req->hdr.len != sizeof(req->hdr)) { @@ -1454,8 +1482,8 @@ STATIC int handle_get_pf_device_info(struct qatmgr_msg_req *req, { uint16_t device_num; int32_t num_devices; - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); /* Use header + additional info length to retrieve PF device information */ if (req->hdr.len != sizeof(req->hdr) + sizeof(req->device_num)) @@ -1507,10 +1535,10 @@ int handle_message(struct qatmgr_msg_req *req, unsigned long id, int *index) { - ICP_CHECK_FOR_NULL_PARAM(req); - ICP_CHECK_FOR_NULL_PARAM(rsp); - ICP_CHECK_FOR_NULL_PARAM(index); - ICP_CHECK_FOR_NULL_PARAM(section_name); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(req, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(rsp, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(index, -EINVAL); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(section_name, -EINVAL); memset(&(rsp->device_info.fw_caps), '\0', sizeof(rsp->device_info.fw_caps)); if (req->hdr.version != THIS_LIB_VERSION) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_lib.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_lib.c index 407f4666..071ab7a1 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_lib.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_lib.c @@ -102,17 +102,22 @@ static void remove_and_close_group(vfio_dev_info_t *dev) int ret = 0; ICP_CHECK_FOR_NULL_PARAM_VOID(dev); + /* Try to unset the container. Only one vfio_dev instance sharing a + * group_fd will succeed */ ret = ioctl( dev->vfio_group_fd, VFIO_GROUP_UNSET_CONTAINER, dev->vfio_container_fd); - if (ret) + if (ret == 0) { - ADF_ERROR("VFIO_GROUP_UNSET_CONTAINER ioctl failed\n"); + /* Only close the group_fd if we successfully unset the container. + * If unset failed, it means either: + * 1. Another vfio_dev instance sharing this FD already closed it + * 2. Another instance already unset the container + * In both cases, we shouldn't close the FD. */ + close(dev->vfio_group_fd); } + dev->vfio_group_fd = -1; if (container_fd_ref) --container_fd_ref; - close(dev->vfio_group_fd); - dev->vfio_group_fd = -1; - if (!container_fd_ref) { close(container_fd); @@ -139,6 +144,7 @@ int open_vfio_dev(const char *vfio_file, struct vfio_irq_set *irq_set; int *fd_ptr; int evtfd; + bool group_already_in_container; ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -1); ICP_CHECK_FOR_NULL_PARAM_RET_CODE(vfio_file, -1); @@ -189,7 +195,10 @@ int open_vfio_dev(const char *vfio_file, dev->vfio_group_fd = open(vfio_file, O_RDWR); if (dev->vfio_group_fd < 0) { - ADF_DEBUG("Cannot open %s\n", vfio_file); + ADF_DEBUG("Cannot open %s: errno=%d (%s)\n", + vfio_file, + errno, + strerror(errno)); return -1; } } @@ -199,25 +208,34 @@ int open_vfio_dev(const char *vfio_file, if (ret) { ADF_ERROR("VFIO_GROUP_GET_STATUS ioctl failed\n"); - close(dev->vfio_group_fd); - return -1; + goto err_close_group; } if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) { ADF_ERROR("Group is not viable (ie, not all devices bound for vfio)\n"); - close(dev->vfio_group_fd); - return -1; + goto err_close_group; } - /* Add the group to the container */ - ret = ioctl( - dev->vfio_group_fd, VFIO_GROUP_SET_CONTAINER, &dev->vfio_container_fd); - if (ret) + /* If group_fd was provided (>=0) and the group is already in a container, + * skip VFIO_GROUP_SET_CONTAINER. This handles the case where the + * device kept open from capability check and are now being called again for + * actual device usage. The container is already set from the first call. */ + group_already_in_container = + (group_fd >= 0 && + (group_status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)); + + if (!group_already_in_container) { - ADF_ERROR("VFIO_GROUP_SET_CONTAINER ioctl failed\n"); - close(dev->vfio_group_fd); - return -1; + /* Add the group to the container */ + ret = ioctl(dev->vfio_group_fd, + VFIO_GROUP_SET_CONTAINER, + &dev->vfio_container_fd); + if (ret) + { + ADF_ERROR("VFIO_GROUP_SET_CONTAINER ioctl failed\n"); + goto err_close_group; + } } container_fd_ref++; @@ -271,6 +289,12 @@ int open_vfio_dev(const char *vfio_file, { struct vfio_region_info reg = { .argsz = sizeof(reg) }; + /* Skip the legacy VGA region */ + if (i == VFIO_PCI_VGA_REGION_INDEX) + { + continue; + } + reg.index = i; /* Setup mappings... read/write offsets, mmaps @@ -366,6 +390,12 @@ int open_vfio_dev(const char *vfio_file, dev->event_fd = evtfd; return 0; + +err_close_group: + /* Only close FD if this function opened it (group_fd < 0) */ + if (group_fd < 0) + close(dev->vfio_group_fd); + return -1; } void close_vfio_dev(vfio_dev_info_t *dev) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_mgr_lib.c b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_mgr_lib.c index 90237691..e666399d 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_mgr_lib.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/adf_io/vfio/vfio_mgr_lib.c @@ -45,6 +45,11 @@ extern icp_accel_pf_info_t pf_data[ADF_MAX_PF_DEVICES]; * we want all the equivalent device/function entries for each of the PF * devices together to facilitate getting devices for policy 0. * 3d:01.0, 3f:01.0, da:01.0, 3d:01.1 ... + * + * When multiple domains with different values are present then domain is used + * as the final tie-breaker to ensure deterministic ordering while keeping + * equivalent device/function entries grouped together as below. + * 0000:3d:01.0, 0001:3d:01.0, 0002:3d:01.0, 0000:3f:01.0, 0001:3f:01.0 ... */ static int bdf_compare(const void *a, const void *b) { @@ -63,6 +68,10 @@ static int bdf_compare(const void *a, const void *b) return 1; if (BDF_BUS(dev_a->bdf) < BDF_BUS(dev_b->bdf)) return -1; + if (BDF_DOMAIN(dev_a->bdf) < BDF_DOMAIN(dev_b->bdf)) + return -1; + if (BDF_DOMAIN(dev_a->bdf) > BDF_DOMAIN(dev_b->bdf)) + return 1; return 0; } @@ -77,13 +86,11 @@ static void process_and_validate_vfio_device_group( int num_vfio_device, const char *vfio_file_name, struct dirent *vfio_entry, - int vfiofile, struct qatmgr_dev_data *dev_list, - int *num_devs, - int keep_fd) + int *num_devs) { char filename[256], *bdfname; - int sysfile_fd, numa_node = 0, found = 0, i; + int sysfile_fd, numa_node = 0, i; unsigned device = 0, vendor = 0, domain, bus, dev, func; uint32_t vfio_dir_name_len, device_dir_name_len, buf_size, str_len; struct dirent *device_entry; @@ -267,13 +274,9 @@ static void process_and_validate_vfio_device_group( numa_node = 0; dev_list[*num_devs].numa_node = numa_node; - found = 1; dev_list[*num_devs].devid = device; - if (keep_fd) - dev_list[*num_devs].group_fd = vfiofile; - else - dev_list[*num_devs].group_fd = -1; + dev_list[*num_devs].group_fd = -1; (*num_devs)++; @@ -286,16 +289,11 @@ static void process_and_validate_vfio_device_group( } free(sysdevice_dir); } - if (!found && vfiofile >= 0) - { - close(vfiofile); - } } int qat_mgr_get_vfio_dev_list(unsigned *num_devices, struct qatmgr_dev_data *dev_list, - const unsigned list_size, - int keep_fd) + const unsigned list_size) { struct dirent **devvfio_dir = NULL; struct dirent **sysdevice_dir = NULL; @@ -354,11 +352,7 @@ int qat_mgr_get_vfio_dev_list(unsigned *num_devices, if (vfiofile < 0) continue; - if (!keep_fd) - { - close(vfiofile); - vfiofile = -1; - } + close(vfiofile); /* * For noiommu, the file name has the format of noiommu- in @@ -375,10 +369,6 @@ int qat_mgr_get_vfio_dev_list(unsigned *num_devices, if (buf_size <= str_len) { qat_log(LOG_LEVEL_ERROR, "Failed to copy device directory name\n"); - if (vfiofile != -1) - { - close(vfiofile); - } continue; } snprintf(devices_dir_name, @@ -391,10 +381,6 @@ int qat_mgr_get_vfio_dev_list(unsigned *num_devices, devices_dir_name, &sysdevice_dir, filter_vfio_files, alphasort); if (num_vfio_device < 0) { - if (vfiofile != -1) - { - close(vfiofile); - } continue; } @@ -403,10 +389,8 @@ int qat_mgr_get_vfio_dev_list(unsigned *num_devices, num_vfio_device, vfio_file_name, vfio_entry, - vfiofile, dev_list, - &num_devs, - keep_fd); + &num_devs); if (num_devs >= list_size) break; @@ -434,7 +418,8 @@ STATIC int qat_mgr_get_device_capabilities( bool *compatible, uint32_t *ext_dc_caps, uint32_t *capabilities, - uint32_t *ring_to_svc_map) + uint32_t *ring_to_svc_map, + int keep_device_open) { int ret; vfio_dev_info_t vfio_dev; @@ -518,11 +503,22 @@ STATIC int qat_mgr_get_device_capabilities( device_data->fw_caps.deflate_caps = vfio_dev.pfvf.fw_caps.deflate_caps; device_data->fw_caps.lz4_caps = vfio_dev.pfvf.fw_caps.lz4_caps; device_data->fw_caps.lz4s_caps = vfio_dev.pfvf.fw_caps.lz4s_caps; + device_data->fw_caps.zstd_caps = vfio_dev.pfvf.fw_caps.zstd_caps; device_data->fw_caps.is_fw_caps = 1; } - close_vfio_dev(&vfio_dev); - device_data->group_fd = -1; + /* In standalone mode, keep device open to maintain exclusive lock. + * This prevents other processes from grabbing this device. + * In daemon mode, close it so clients can open later. */ + if (keep_device_open) + { + device_data->group_fd = vfio_dev.vfio_group_fd; + } + else + { + close_vfio_dev(&vfio_dev); + device_data->group_fd = -1; + } return 0; } @@ -608,7 +604,7 @@ static int get_pkg_id(unsigned vf_bdf, int32_t *vf_pkg_id) int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], const int num_vf_devices, int policy, - int static_cfg) + int keep_device_open) { int i, j, k; struct qatmgr_section_data *section; @@ -623,8 +619,13 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], unsigned devid; char pf_str[10]; ENTRY pf_entry = { pf_str, NULL }; - int pfs_per_vf_group[ADF_MAX_DEVICES] = { 0 }; - uint32_t ext_dc_caps, capabilities; + /* + * This array does not need to be static. However, it is declared this way + * to avoid excessive use of stack memory and potential stack-overflow in + * this function. + */ + static int pfs_per_vf_group[ADF_MAX_DEVICES]; + uint32_t ext_dc_caps = 0, capabilities = 0; uint32_t ring_to_svc_map; bool compatible; bool vm = false; @@ -638,6 +639,8 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], int32_t num_pfs; int num_section_data = 0; + memset(pfs_per_vf_group, 0, sizeof(pfs_per_vf_group)); + if (!num_vf_devices) return -EINVAL; @@ -676,7 +679,7 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], * We know we have a new group when we find a PF that already exists in * the first group. */ - if (!static_cfg) + if (!keep_device_open) { num_vf_groups = 1; @@ -863,7 +866,6 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], device_data->max_banks = 4; device_data->max_rings_per_bank = 2; device_data->arb_mask = 0x01; -#ifndef ENABLE_DC device_data->accel_capabilities = ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC | ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | @@ -877,23 +879,6 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], ICP_ACCEL_CAPABILITIES_AESGCM_SPC | ICP_ACCEL_CAPABILITIES_AES_V2; device_data->extended_capabilities = 0x0; -#else - /* For Legacy Chaining we set the following - * AUTHENTICATION and Bit 21 - * Bit 21 used to enabling the hash then compress - * chaining support. - */ - device_data->accel_capabilities = - ICP_ACCEL_CAPABILITIES_COMPRESSION | - ICP_ACCEL_CAPABILITIES_CNV_INTEGRITY64 | - ICP_ACCEL_CAPABILITIES_LZ4_COMPRESSION | - ICP_ACCEL_CAPABILITIES_LZ4S_COMPRESSION | - ICP_ACCEL_CAPABILITIES_AUTHENTICATION | - ICP_ACCEL_CAPABILITIES_CRYPTO_SHA3 | - ICP_ACCEL_CAPABILITIES_SHA3_EXT; - - device_data->extended_capabilities = BIT(21) | BIT(0); -#endif /** * Send query to get capabilities from PF. * qat_mgr_get_device_capabilities will open device, initialize @@ -939,6 +924,8 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], cached_capabilities->fw_caps.lz4_caps; device_data->fw_caps.lz4s_caps = cached_capabilities->fw_caps.lz4s_caps; + device_data->fw_caps.zstd_caps = + cached_capabilities->fw_caps.zstd_caps; device_data->fw_caps.is_fw_caps = cached_capabilities->fw_caps.is_fw_caps; } @@ -946,35 +933,112 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], } else if (adf_vf2pf_available()) { - ret = qat_mgr_get_device_capabilities(device_data, - devid, - &compatible, - &ext_dc_caps, - &capabilities, - &ring_to_svc_map); - if (0 == ret) - { - /* - * Override the ecEdMont capability - * reported by the kernel. The reason for this is that - * some kernel drivers don't report this capability - * even though it is present in all devices that have asym. - */ - if (capabilities & ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) - capabilities |= ICP_ACCEL_CAPABILITIES_ECEDMONT; - device_data->accel_capabilities = capabilities; - device_data->extended_capabilities = ext_dc_caps; - } - else if (!compatible) + /* Try to acquire this device. If it's busy (another + * process owns it), then try the next device in + * dev_list. + */ + int retries_left = num_vf_devices - vf_idx; + int original_vf_idx = vf_idx; + + while (retries_left > 0) { - qat_log(LOG_LEVEL_ERROR, - "Detected not compatible PF driver\n"); - qat_mgr_cleanup_cfg(); - return ret; + ret = qat_mgr_get_device_capabilities(device_data, + devid, + &compatible, + &ext_dc_caps, + &capabilities, + &ring_to_svc_map, + keep_device_open); + if (0 == ret) + { + /* Device acquired successfully */ + break; + } + else if (!compatible) + { + qat_log(LOG_LEVEL_ERROR, + "Incompatible PF driver detected\n"); + qat_mgr_cleanup_cfg(); + return ret; + } + else if (!adf_vf2pf_available()) + { + /* The PF driver does not support VF2PF messaging, so + * capabilities cannot be queried. This is not a busy + * device, so don't cycle through the remaining VFs. + * Fall back to the hardcoded default configuration. + * and stop retrying. + */ + qat_log( + LOG_LEVEL_INFO, + "PF-VF comms not supported by PF, using default " + "configuration\n"); + capabilities = device_data->accel_capabilities; + ext_dc_caps = device_data->extended_capabilities; + ring_to_svc_map = DEFAULT_RING_TO_SRV_MAP; + break; + } + else + { + /* Device busy, try next one */ + vf_idx++; + retries_left--; + + if (retries_left == 0) + { + qat_log(LOG_LEVEL_ERROR, + "No available devices after trying %d " + "devices\n", + num_vf_devices - original_vf_idx); + qat_mgr_cleanup_cfg(); + return -ENODEV; + } + + /* Update device_data with next device info */ + device_data->group_fd = dev_list[vf_idx].group_fd; + device_data->node = dev_list[vf_idx].numa_node; + devid = dev_list[vf_idx].devid; + /* Update pkg_id for new VF */ + if (get_pkg_id(dev_list[vf_idx].bdf, &vf_pkg_id)) + { + qat_log(LOG_LEVEL_ERROR, + "Failed to find pkg_id for the device\n"); + qat_mgr_cleanup_cfg(); + return -EAGAIN; + } + if (vf_pkg_id == VM_PACKAGE_ID_NONE) + vf_pkg_id = device_data->accelid; + device_data->pkg_id = vf_pkg_id; + snprintf(device_data->device_id, + sizeof(device_data->device_id), + "%04x:%02x:%02x.%01x", + BDF_DOMAIN(dev_list[vf_idx].bdf), + BDF_BUS(dev_list[vf_idx].bdf), + BDF_DEV(dev_list[vf_idx].bdf), + BDF_FUN(dev_list[vf_idx].bdf)); + snprintf(device_data->device_file, + sizeof(device_data->device_file), + "%.*s", + VFIO_FILE_SIZE, + dev_list[vf_idx].vfio_file); + } } - if (0 == ret && !vm) + /* + * Override the ecEdMont capability + * reported by the kernel. The reason for this is that + * some kernel drivers don't report this capability + * even though it is present in all devices that have asym. + */ + if (capabilities & ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) + capabilities |= ICP_ACCEL_CAPABILITIES_ECEDMONT; + device_data->accel_capabilities = capabilities; + device_data->extended_capabilities = ext_dc_caps; + + if (!vm) { + /* Recalculate PF if retry loop switched to different VF */ + pf = PF(dev_list[vf_idx].bdf); cached_capabilities = calloc(1, sizeof(struct pf_capabilities)); if (!cached_capabilities) @@ -1000,6 +1064,8 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], device_data->fw_caps.lz4_caps; cached_capabilities->fw_caps.lz4s_caps = device_data->fw_caps.lz4s_caps; + cached_capabilities->fw_caps.zstd_caps = + device_data->fw_caps.zstd_caps; cached_capabilities->fw_caps.is_fw_caps = 1; } add_pf_capabilities(cached_capabilities); @@ -1013,6 +1079,10 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], if (IS_QAT_GEN4_2(qat_device_type(devid))) device_data->accel_capabilities &= ~ICP_ACCEL_CAPABILITIES_ZUC_256; + + /* Populate service configuration for a device and + * determine the number of instances per device + */ snprintf(device_data->name, sizeof(device_data->name), "%s", @@ -1020,9 +1090,6 @@ int qat_mgr_vfio_build_data(const struct qatmgr_dev_data dev_list[], device_data->device_type = qat_device_type(devid); device_data->pci_id = devid; - /* Populate service configuration for a device and - * determine the number of instances per device - */ ret = get_num_instances( device_data, devid, ring_to_svc_map, INSTANCES_PER_DEVICE); if (ret) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_dev_ring_ctl.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_dev_ring_ctl.h index 1aac539e..ab5455a3 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_dev_ring_ctl.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_dev_ring_ctl.h @@ -85,6 +85,8 @@ typedef struct adf_dev_ring_handle_s uint32_t csrTailOffset; uint32_t *csr_addr; + Cpa32U coalescingTimerNs; /* coalescing timer (ns) cached for restore */ + CpaBoolean coalescingTimerUserSet; /* CPA_TRUE if set by caller */ } adf_dev_ring_handle_t; #define IS_RING_IN_WQ_MODE(ring) ((ring)->ringMode == ADF_RING_WQ_MODE) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_acceldev_common.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_acceldev_common.h index e73e4ba1..83b2d948 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_acceldev_common.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_acceldev_common.h @@ -25,7 +25,44 @@ /* Coalesced Interrupt Enable */ #define ETR_CSR_INTR_COL_CTL_ENABLE 0x80000000 -#define ETR_CSR_INTR_COL_CTL_TIME 0x0000FFFF + +/* + * Interrupt coalescing timer hardware constants. + * + * CSR_INT_COL_CTL CSR + * | Bit 31 | Bits 30..16 | Bits 15..0 | + * | enable | reserved | delcnt | + * + * CSR_INT_COL_CTL DELCNT is decremented every ICP_INT_COL_CTL_CYCLES_PER_DECR + * clock cycles of the CPP clock. With a 1 GHz clock and 256 cycles per + * decrement the granularity is 256 ns and the maximum delay is 0xFFFF * 256 ns. + */ +#define ICP_INT_COL_CTL_CPP_FREQ_HZ (1000000000ULL) /* 1 GHz */ +#define ICP_INT_COL_CTL_CYCLES_PER_DECR (256U) +#define ICP_INT_COL_CTL_DELCNT_MIN (0x1U) +#define ICP_INT_COL_CTL_DELCNT_MAX (0xFFFFU) +/* Mask for the DELCNT field in the CSR_INT_COL_CTL register (bits [15:0]). */ +#define ICP_INT_COL_CTL_DELCNT_MASK (0xFFFFU) +#define ICP_NS_PER_SECOND (1000000000ULL) +#define ICP_INT_COL_DEFAULT_TIMER_NS 10000 + +/* Hardware maximum expressed in ns (~16.78 ms). */ +#define ICP_INT_COL_MAX_CSR_TIMER_NS \ + ((Cpa32U)(ICP_DELCNT_TO_NS(ICP_INT_COL_CTL_DELCNT_MAX))) + +/* Software cap (512 us) to avoid excessive interrupt latency. */ +#define ICP_INT_COL_MAX_CFG_TIMER_NS 512000U + +/* Effective maximum is the lower of the hardware limit and the software cap. */ +#define ICP_INT_COL_MAX_TIMER_NS \ + (ICP_INT_COL_MAX_CFG_TIMER_NS < ICP_INT_COL_MAX_CSR_TIMER_NS \ + ? ICP_INT_COL_MAX_CFG_TIMER_NS \ + : ICP_INT_COL_MAX_CSR_TIMER_NS) + +/* Convert a DELCNT hardware counter value to nanoseconds. */ +#define ICP_DELCNT_TO_NS(cnt) \ + ((cnt)*ICP_INT_COL_CTL_CYCLES_PER_DECR * ICP_NS_PER_SECOND / \ + ICP_INT_COL_CTL_CPP_FREQ_HZ) /* Ring Csrs offsets */ #define ICP_RING_CSR_RING_CONFIG 0x000 @@ -98,6 +135,9 @@ #define READ_CSR_INT_EN(bank_offset) \ ICP_ADF_CSR_RD(csr_base_addr, bank_offset + ICP_RING_CSR_INT_EN) +#define READ_CSR_INT_COL_CTL(bank_offset) \ + ICP_ADF_CSR_RD(csr_base_addr, bank_offset + ICP_RING_CSR_INT_COL_CTL) + #define WRITE_CSR_RING_CONFIG(bank_offset, ring, value) \ ICP_ADF_CSR_WR(csr_base_addr, \ bank_offset + ICP_RING_CSR_RING_CONFIG + (ring << 2), \ @@ -151,6 +191,11 @@ static inline Cpa64U read_base(Cpa32U *csr_base_addr, bank_offset + ICP_RING_CSR_INT_COL_CTL, \ ETR_CSR_INTR_COL_CTL_ENABLE | value) +/* Disable interrupt coalescing: clears the ENABLE bit entirely so the + * hardware fires an interrupt immediately on each response. */ +#define WRITE_CSR_INT_COL_CTL_DISABLE(bank_offset) \ + ICP_ADF_CSR_WR(csr_base_addr, bank_offset + ICP_RING_CSR_INT_COL_CTL, 0) + #define WRITE_CSR_INT_FLAG_AND_COL(bank_offset, value) \ ICP_ADF_CSR_WR( \ csr_base_addr, bank_offset + ICP_RING_CSR_FLAG_AND_COL_EN, value) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_common.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_common.h index 6956a5e0..2d79424d 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_common.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_platform_common.h @@ -18,6 +18,8 @@ #ifndef ADF_PLATFORM_COMMON_H #define ADF_PLATFORM_COMMON_H +#include + /* Number of Rings Per Bank */ #define ICP_ETR_MAX_RINGS_PER_BANK 16 @@ -64,7 +66,7 @@ #define ICP_RING_NEAR_WATERMARK_KILO_256 0x11 /* Bundle size */ -#define ICP_BUNDLE_SIZE 0x1000 +#define ADF_RING_BUNDLE_SIZE 0x2000 /* For coalescing based on number of messages define the required ring message * count, and the limits on the allowed thresholds. @@ -254,12 +256,42 @@ static inline unsigned int modulo(unsigned int data, unsigned int shift) } /* Ring controller CSR Accessor Macros */ -/* CSR write macro */ +/* Force MMIO stores to remain 32-bit wide. Some compilers may optimize a + * volatile 32-bit CSR write to a narrower access, which breaks QAT + * mailbox CSRs that require DWORD transactions. */ +static inline void icp_adf_csr_wr(void *csrAddr, + uint32_t csrOffset, + uint32_t val) +{ + volatile void *addr = ((char *)csrAddr) + csrOffset; + +#if defined(__x86_64__) + __asm__ __volatile__("movl %0, (%1)" : : "r"(val), "r"(addr) : "memory"); +#else +#error "Unsupported architecture for icp_adf_csr_wr" +#endif +} + #define ICP_ADF_CSR_WR(csrAddr, csrOffset, val) \ - (void)((*((volatile Cpa32U *)(((Cpa8U *)csrAddr) + csrOffset)) = (val))) + icp_adf_csr_wr(csrAddr, csrOffset, val) + +/* Force MMIO loads to remain 32-bit wide. Some compilers may optimize a + * volatile 32-bit CSR read to a narrower access, which breaks QAT + * mailbox CSRs that require DWORD transactions. */ +static inline uint32_t icp_adf_csr_rd(void *csrAddr, uint32_t csrOffset) +{ + const volatile void *addr = ((char *)csrAddr) + csrOffset; + uint32_t val; + +#if defined(__x86_64__) + __asm__ __volatile__("movl (%1), %0" : "=r"(val) : "r"(addr) : "memory"); +#else +#error "Unsupported architecture for icp_adf_csr_rd" +#endif + + return val; +} -/* CSR read macro */ -#define ICP_ADF_CSR_RD(csrAddr, csrOffset) \ - (*((volatile Cpa32U *)(((Cpa8U *)csrAddr) + csrOffset))) +#define ICP_ADF_CSR_RD(csrAddr, csrOffset) icp_adf_csr_rd(csrAddr, csrOffset) #endif /* ADF_PLATFORM_COMMON_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_user_ring.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_user_ring.h index 45f58676..090f6c2f 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_user_ring.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_user_ring.h @@ -61,6 +61,7 @@ int32_t adf_user_check_ring_error(adf_dev_ring_handle_t *pRingHandle); CpaBoolean adf_user_check_resp_ring(adf_dev_ring_handle_t *ring); CpaStatus adf_user_notify_msgs_poll(adf_dev_ring_handle_t *ring); +void adf_user_sync_ring_head(adf_dev_ring_handle_t *ring); int32_t adf_user_get_inflight_requests(adf_dev_ring_handle_t *ring, uint32_t *maxInflightRequests, uint32_t *numInflightRequests); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/icp_platform.h b/quickassist/lookaside/access_layer/src/qat_direct/include/icp_platform.h index 92d70e07..a8945a29 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/icp_platform.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/icp_platform.h @@ -247,19 +247,19 @@ char *icp_module_name = "XEN"; #define ADF_ERROR(format, args...) \ osalLog(OSAL_LOG_LVL_ERROR, OSAL_LOG_DEV_STDERR, "%s: %s: " format, \ icp_module_name, (__func__), ##args) -#ifdef _DEBUG_ +#ifdef ICP_DEBUG #define ADF_DEBUG(format, args...) \ do \ { \ osalLog(OSAL_LOG_LVL_DEBUG1, OSAL_LOG_DEV_STDOUT, "%s: %s: " format, \ icp_module_name, (__func__), ##args); \ } while (0) -#else /*_DEBUG_*/ +#else /*ICP_DEBUG*/ #define ADF_DEBUG(format, args...) \ do \ { \ } while (0) -#endif /*_DEBUG_*/ +#endif /*ICP_DEBUG*/ /* memory management */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_device.c b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_device.c index 47c5e465..55dd1eec 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_device.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_device.c @@ -318,6 +318,17 @@ STATIC CpaStatus subsystem_notify(Cpa32U accelId, Cpa32U event) adf_io_vf2pf_notify_restarting_complete(accel_dev); break; case ADF_EVENT_RESTARTED: + /* RESTARTED may be delivered more than once per reset (the VF + * proxy synthesizes one on vfio reopen and also reads the real + * PF2VF RESTARTED). accel_dev_restarting_state is cleared by the + * first RESTARTED; ignore any replay to avoid re-running the + * restart flow on an already-running instance. */ + if (accel_dev_restarting_state[accel_dev->accelId] == 0) + { + ADF_DEBUG("accelID %d duplicate RESTARTED event ignored\n", + accel_dev->accelId); + break; + } accel_dev_restarting_state[accel_dev->accelId] = 0; stat_restart = adf_proxy_restart_device(accelId); if (CPA_STATUS_SUCCESS == stat_restart) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_init.c b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_init.c index d62f8dce..98fef8fe 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_init.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_init.c @@ -32,7 +32,7 @@ STATIC subservice_registation_handle_t *pSubsystemTable = NULL; STATIC subservice_registation_handle_t *pSubsystemTableHead = NULL; STATIC ICP_MUTEX subsystemTableLock = { 0 }; -char *icp_module_name = "ADF_UIO_PROXY"; +char *icp_module_name = "ADF_IO_PROXY"; /* Slepping time before subsystem is started */ #define SLEEP_TIME 50000 @@ -686,20 +686,14 @@ CpaStatus adf_subsystemError(icp_accel_dev_t *accel_dev) } /* - * Function to reset subsystem table head, the pointer - * to the head of the list and lock. + * Function to reset subsystem table, the pointer + * to the head of the list and lock. This function should be + * called only if the subsystem table is empty. */ CpaStatus icp_adf_resetSubsystemTable(void) { pSubsystemTable = NULL; pSubsystemTableHead = NULL; - if (0 == subsystemTableLock) - { - if (OSAL_SUCCESS != ICP_MUTEX_INIT(&subsystemTableLock)) - { - ADF_ERROR("Mutex init failed for subsystemTabl lock\n"); - return CPA_STATUS_RESOURCE; - } - } + subsystemTableLock = 0; return CPA_STATUS_SUCCESS; } diff --git a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_ring.c b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_ring.c index 6fc6b48e..c4234576 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_ring.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_ring.c @@ -194,16 +194,11 @@ int32_t adf_user_check_ring_error(adf_dev_ring_handle_t *ring) { uint8_t *csr_base_addr = NULL; uint32_t ring_stat = 0; - device_type_t deviceType; - ICP_CHECK_FOR_NULL_PARAM(ring); - - deviceType = ring->accel_dev->deviceType; + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(ring, -EINVAL); /* if generation is not supporting ring error reporting assume there was no * error */ - if (IS_QAT_GEN2(deviceType)) - return 0; csr_base_addr = ((uint8_t *)ring->csr_addr); @@ -312,6 +307,27 @@ CpaStatus adf_user_notify_msgs_poll(adf_dev_ring_handle_t *ring) return CPA_STATUS_SUCCESS; } +/* + * Force a sync of the HW ring head CSR with the SW shadow ring->head value. + * + * adf_user_notify_msgs_poll() coalesces head CSR writes to reduce MMIO impact, + * so the HW head can lag behind the SW head between polls. When switching + * POLL <-> EPOLL at runtime, the HW must be updated so it is informed of the + * responses that have been collected and will not generate unnecessary + * interrupts for already collected responses. + */ +void adf_user_sync_ring_head(adf_dev_ring_handle_t *ring) +{ + ICP_CHECK_FOR_NULL_PARAM_VOID(ring); + + if (IS_RING_IN_WQ_MODE(ring)) + { + WRITE_CSR_RING_HEAD( + ring->csr_addr, ring->bank_offset, ring->ring_num, ring->head); + ring->coal_write_count = ring->min_resps_per_head_write; + } +} + static void adf_populate_ring_config(adf_dev_ring_handle_t *ring, adf_dev_bank_handle_t *bank, uint32_t ring_size_cfg) @@ -320,9 +336,6 @@ static void adf_populate_ring_config(adf_dev_ring_handle_t *ring, uint8_t nearly_full_wm = ICP_RING_NEAR_WATERMARK_512; uint8_t nearly_empty_wm = ICP_RING_NEAR_WATERMARK_0; uint32_t *csr_base_addr = ring->csr_addr; - device_type_t deviceType; - - deviceType = ring->accel_dev->deviceType; if (bank->tx_rings_mask & (1 << ring->ring_num)) { @@ -334,7 +347,6 @@ static void adf_populate_ring_config(adf_dev_ring_handle_t *ring, ring_size_cfg, nearly_full_wm, nearly_empty_wm); } - if (!IS_QAT_GEN2(deviceType)) { ring_base_cfg = BUILD_RING_BASE_ADDR_GEN4(ring->ring_phys_base_addr, ring_size_cfg); @@ -343,13 +355,6 @@ static void adf_populate_ring_config(adf_dev_ring_handle_t *ring, WRITE_CSR_RING_CONFIG_GEN4( csr_base_addr, ring->bank_offset, ring->ring_num, ring_config); } - else - { - ring_base_cfg = - BUILD_RING_BASE_ADDR(ring->ring_phys_base_addr, ring_size_cfg); - WRITE_CSR_RING_BASE(ring->bank_offset, ring->ring_num, ring_base_cfg); - WRITE_CSR_RING_CONFIG(ring->bank_offset, ring->ring_num, ring_config); - } } static int32_t adf_init_ring_internal(adf_dev_ring_handle_t *ring, @@ -366,7 +371,7 @@ static int32_t adf_init_ring_internal(adf_dev_ring_handle_t *ring, uint32_t ring_size_bytes = ICP_ET_SIZE_TO_BYTES(ring_size_cfg); uint32_t max_space = ring_size_bytes; - ICP_CHECK_FOR_NULL_PARAM(ring->accel_dev); + ICP_CHECK_FOR_NULL_PARAM_RET_CODE(ring->accel_dev, -EINVAL); /* Exclusive access to one ring */ if (adf_reserve_ring(bank, ring_num)) @@ -467,25 +472,18 @@ static void adf_clean_ring(adf_dev_ring_handle_t *ring) { uint32_t *csr_base_addr = ring->csr_addr; ICP_CHECK_FOR_NULL_PARAM_VOID(ring->accel_dev); - device_type_t deviceType = ring->accel_dev->deviceType; adf_io_disable_ring(ring); if (IS_RING_IN_WQ_MODE(ring)) { /* Clear CSR configuration */ - if (!IS_QAT_GEN2(deviceType)) { WRITE_CSR_RING_CONFIG_GEN4( csr_base_addr, ring->bank_offset, ring->ring_num, 0); WRITE_CSR_RING_BASE_GEN4( csr_base_addr, ring->bank_offset, ring->ring_num, 0); } - else - { - WRITE_CSR_RING_CONFIG(ring->bank_offset, ring->ring_num, 0); - WRITE_CSR_RING_BASE(ring->bank_offset, ring->ring_num, 0); - } } adf_unreserve_ring(ring->bank_data, ring->ring_num); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_transport_ctrl.c b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_transport_ctrl.c index 2b0a8ae7..82894e1b 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_transport_ctrl.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/io/adf_user_transport_ctrl.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -54,11 +55,54 @@ extern void *adf_get_bank_base_addr(int accelId, int bankid, uint32_t *offset, uint32_t *size); + adf_dev_bank_handle_t *get_banks(icp_accel_dev_t *dev) { return dev->banks; } +/* + * Calculate the CSR_INT_COL_CTL DELCNT value from a nanosecond delay. + * + * Result is clamped to the valid hardware range + * [ICP_INT_COL_CTL_DELCNT_MIN, ICP_INT_COL_CTL_DELCNT_MAX]. + */ +STATIC Cpa32U adf_calc_del_cnt(Cpa32U coalescingTimerInNs) +{ + Cpa64U delcnt; /* holds delay counter value */ + + delcnt = ((Cpa64U)coalescingTimerInNs * ICP_INT_COL_CTL_CPP_FREQ_HZ) / + ((Cpa64U)ICP_INT_COL_CTL_CYCLES_PER_DECR * ICP_NS_PER_SECOND); + + if (delcnt < ICP_INT_COL_CTL_DELCNT_MIN) + delcnt = ICP_INT_COL_CTL_DELCNT_MIN; + else if (delcnt > ICP_INT_COL_CTL_DELCNT_MAX) + delcnt = ICP_INT_COL_CTL_DELCNT_MAX; + + return (Cpa32U)delcnt; +} + +/* + * Write the coalescing timer CSR for a ring handle. + * Restores the user-set timer if one was configured, otherwise writes the + * hardware default. Called on ring create, mode switch, and reinit. + * To ensure thread-safety, ring lock must be held when this function + * is called. + */ +STATIC void adf_write_coalescing_timer(adf_dev_ring_handle_t *pRingHandle) +{ + uint32_t *csr_base_addr = pRingHandle->csr_addr; + Cpa32U timerNs = pRingHandle->coalescingTimerUserSet + ? pRingHandle->coalescingTimerNs + : ICP_INT_COL_DEFAULT_TIMER_NS; + + if (timerNs == 0) + WRITE_CSR_INT_COL_CTL_DISABLE(pRingHandle->bank_offset); + else + WRITE_CSR_INT_COL_CTL(pRingHandle->bank_offset, + adf_calc_del_cnt(timerNs)); +} + STATIC CpaStatus init_rings_from_bank(icp_accel_dev_t *accel_dev, adf_dev_bank_handle_t *bank) { @@ -93,13 +137,13 @@ CpaStatus init_bank_from_accel(icp_accel_dev_t *accel_dev, bank->csr_addr = (uint32_t *)bundle->ptr; - bank->csr_addr_shadow = (uint32_t *)ICP_MALLOC_GEN(ICP_BUNDLE_SIZE); + bank->csr_addr_shadow = (uint32_t *)ICP_MALLOC_GEN(ADF_RING_BUNDLE_SIZE); if (NULL == bank->csr_addr_shadow) { adf_io_free_bundle(bundle); return CPA_STATUS_FAIL; } - ICP_MEMSET(bank->csr_addr_shadow, 0, ICP_BUNDLE_SIZE); + ICP_MEMSET(bank->csr_addr_shadow, 0, ADF_RING_BUNDLE_SIZE); bank->bundle = bundle; /* allocate ring handles for this bank */ @@ -132,7 +176,7 @@ STATIC CpaStatus reinit_bank_from_accel(icp_accel_dev_t *accel_dev, } bank->csr_addr = (uint32_t *)bundle->ptr; - ICP_MEMSET(bank->csr_addr_shadow, 0, ICP_BUNDLE_SIZE); + ICP_MEMSET(bank->csr_addr_shadow, 0, ADF_RING_BUNDLE_SIZE); bank->bundle = bundle; /* allocate ring handles for this bank */ @@ -634,8 +678,13 @@ CpaStatus icp_adf_transCreateHandle(icp_accel_dev_t *accel_dev, uint32_t *csr_base_addr = pRingHandle->csr_addr; WRITE_CSR_INT_COL_EN(pRingHandle->bank_offset, banks[pRingHandle->bank_num].interrupt_mask); - WRITE_CSR_INT_COL_CTL(pRingHandle->bank_offset, - ETR_CSR_INTR_COL_CTL_TIME); + } + /* Restore coalescing timer in IRQ mode always, and in POLL mode when + * the caller previously configured a custom value (cached in the ring + * handle but reset to 0 by hardware on device restart). */ + if (ICP_RESP_TYPE_IRQ == resp || pRingHandle->coalescingTimerUserSet) + { + adf_write_coalescing_timer(pRingHandle); } return CPA_STATUS_SUCCESS; @@ -758,8 +807,13 @@ CpaStatus icp_adf_transReinitHandle(icp_accel_dev_t *accel_dev, uint32_t *csr_base_addr = pRingHandle->csr_addr; WRITE_CSR_INT_COL_EN(pRingHandle->bank_offset, banks[pRingHandle->bank_num].interrupt_mask); - WRITE_CSR_INT_COL_CTL(pRingHandle->bank_offset, - ETR_CSR_INTR_COL_CTL_TIME); + } + /* Restore coalescing timer in IRQ mode always, and in POLL mode when + * the caller previously configured a custom value (cached in the ring + * handle but reset to 0 by hardware on device restart). */ + if (ICP_RESP_TYPE_IRQ == resp || pRingHandle->coalescingTimerUserSet) + { + adf_write_coalescing_timer(pRingHandle); } return CPA_STATUS_SUCCESS; @@ -777,6 +831,7 @@ CpaStatus icp_adf_transSetRespMode(icp_comms_trans_handle *trans_handle, adf_dev_bank_handle_t *banks = NULL; adf_dev_bank_handle_t *bank = NULL; uint32_t *csr_base_addr = NULL; + CpaStatus status = CPA_STATUS_SUCCESS; ICP_CHECK_FOR_NULL_PARAM(trans_handle); pRingHandle = (adf_dev_ring_handle_t *)trans_handle; @@ -795,8 +850,15 @@ CpaStatus icp_adf_transSetRespMode(icp_comms_trans_handle *trans_handle, return CPA_STATUS_SUCCESS; } + status = ICP_MUTEX_LOCK(&pRingHandle->user_lock); + if (status) + { + ADF_ERROR("Failed to lock ring with error %d\n", status); + return CPA_STATUS_FAIL; + } if (irq_enable) { + adf_user_sync_ring_head(pRingHandle); pRingHandle->interrupt_user_mask = 1 << pRingHandle->ring_num; bank->interrupt_mask |= pRingHandle->interrupt_user_mask; } @@ -808,9 +870,101 @@ CpaStatus icp_adf_transSetRespMode(icp_comms_trans_handle *trans_handle, csr_base_addr = pRingHandle->csr_addr; WRITE_CSR_INT_COL_EN(pRingHandle->bank_offset, bank->interrupt_mask); - WRITE_CSR_INT_COL_CTL(pRingHandle->bank_offset, ETR_CSR_INTR_COL_CTL_TIME); + /* Restore coalescing timer on mode switch. */ + adf_write_coalescing_timer(pRingHandle); pRingHandle->resp = irq_enable ? ICP_RESP_TYPE_IRQ : ICP_RESP_TYPE_POLL; + status = ICP_MUTEX_UNLOCK(&pRingHandle->user_lock); + if (status) + { + ADF_ERROR("Failed to unlock ring with error %d\n", status); + } + + return status ? CPA_STATUS_FAIL : CPA_STATUS_SUCCESS; +} + +/* + * Configure the Interrupt Coalescing Timer on an RX ring. + * + * The value is written to hardware immediately and cached so it survives + * mode switches and Stop/Start cycles. Pass 0 to disable coalescing. + * Values exceeding the allowed maximum return CPA_STATUS_INVALID_PARAM. + */ +CpaStatus icp_adf_transSetIntCoalTimer(icp_comms_trans_handle trans_handle, + Cpa32U coalescingTimerInNs) +{ + adf_dev_ring_handle_t *pRingHandle = NULL; + Cpa32U max_timer_ns; + CpaStatus status = CPA_STATUS_SUCCESS; + + ICP_CHECK_FOR_NULL_PARAM(trans_handle); + pRingHandle = (adf_dev_ring_handle_t *)trans_handle; + + /* Reject values that exceed the effective maximum (software cap). */ + max_timer_ns = ICP_INT_COL_MAX_TIMER_NS; + if (coalescingTimerInNs > max_timer_ns) + { + ADF_ERROR("coalescingTimerInNs (%u) exceeds maximum (%u)\n", + coalescingTimerInNs, + max_timer_ns); + return CPA_STATUS_INVALID_PARAM; + } + + /* + * Acquire the ring lock to ensure only one thread at a time updates + * the cached timer fields and the COL_CTL hardware register. + */ + status = ICP_MUTEX_LOCK(&pRingHandle->user_lock); + if (status) + { + ADF_ERROR("Failed to lock ring with error %d\n", status); + return CPA_STATUS_FAIL; + } + pRingHandle->coalescingTimerNs = coalescingTimerInNs; + pRingHandle->coalescingTimerUserSet = CPA_TRUE; + adf_write_coalescing_timer(pRingHandle); + status = ICP_MUTEX_UNLOCK(&pRingHandle->user_lock); + if (status) + { + ADF_ERROR("Failed to unlock ring with error %d\n", status); + } + + return status ? CPA_STATUS_FAIL : CPA_STATUS_SUCCESS; +} + +/* + * Return the current Interrupt Coalescing Timer configuration for an + * RX ring, together with the hardware maximum and granularity. + * The timer value is read directly from the CSR. + */ +CpaStatus icp_adf_transGetIntCoalTimerData(icp_comms_trans_handle trans_handle, + Cpa32U *pCoalTimerInNs, + Cpa32U *pMaxCoalTimerInNs, + Cpa32U *pGranularityInNs) +{ + adf_dev_ring_handle_t *pRingHandle = NULL; + uint32_t *csr_base_addr = NULL; + Cpa32U reg = 0; + Cpa32U delcnt = 0; + + ICP_CHECK_FOR_NULL_PARAM(trans_handle); + ICP_CHECK_FOR_NULL_PARAM(pCoalTimerInNs); + ICP_CHECK_FOR_NULL_PARAM(pMaxCoalTimerInNs); + ICP_CHECK_FOR_NULL_PARAM(pGranularityInNs); + + pRingHandle = (adf_dev_ring_handle_t *)trans_handle; + + /* Read timer from CSR. */ + csr_base_addr = pRingHandle->csr_addr; + reg = READ_CSR_INT_COL_CTL(pRingHandle->bank_offset); + delcnt = reg & ICP_INT_COL_CTL_DELCNT_MASK; + *pCoalTimerInNs = (Cpa32U)(ICP_DELCNT_TO_NS(delcnt)); + + /* Maximum: effective cap (lower of hardware limit and software cap). */ + *pMaxCoalTimerInNs = ICP_INT_COL_MAX_TIMER_NS; + + /* Granularity: 1 unit = ICP_INT_COL_CTL_CYCLES_PER_DECR clock cycles. */ + *pGranularityInNs = (Cpa32U)(ICP_DELCNT_TO_NS(1)); return CPA_STATUS_SUCCESS; } @@ -1290,6 +1444,21 @@ CpaStatus icp_adf_transGetFdForHandle(icp_comms_trans_handle trans_hnd, int *fd) } } +/* + * Drain the eventfd event counter for a bundle. Interrupt for + * the instance is expected to be masked at this point. The eventfd + * is created with EFD_NONBLOCK so the read will not block. + */ +static void consume_efd_events(struct adf_io_user_bundle *bundle) +{ + uint64_t val; + ssize_t r; + + r = read(bundle->efd, &val, sizeof(val)); + if (r < 0 && errno != EAGAIN) + ADF_ERROR("Can't read eventfd: %s\n", strerror(errno)); +} + /* * This function allows the user to poll the response ring. The * ring number to be polled is supplied by the user via the @@ -1318,7 +1487,9 @@ CpaStatus icp_adf_pollInstance(icp_comms_trans_handle *trans_hnd, return CPA_STATUS_FAIL; } +#ifndef ICP_WITHOUT_QP_SUBMISSION_LOCK ICP_MUTEX_LOCK(&ring_hnd_first->user_lock); +#endif csr_base_addr = (Cpa8U *)ring_hnd_first->csr_addr; for (i = 0; i < num_transHandles; i++) @@ -1326,7 +1497,9 @@ CpaStatus icp_adf_pollInstance(icp_comms_trans_handle *trans_hnd, ring_hnd = (adf_dev_ring_handle_t *)trans_hnd[i]; if (!ring_hnd) { +#ifndef ICP_WITHOUT_QP_SUBMISSION_LOCK ICP_MUTEX_UNLOCK(&ring_hnd_first->user_lock); +#endif return CPA_STATUS_FAIL; } /* And with polling ring mask. If the @@ -1346,13 +1519,16 @@ CpaStatus icp_adf_pollInstance(icp_comms_trans_handle *trans_hnd, /* Re-enable interrupts in case we are using epoll mode */ if (ICP_RESP_TYPE_IRQ == ring_hnd->resp) { + consume_efd_events( + (struct adf_io_user_bundle *)ring_hnd->bank_data->bundle); WRITE_CSR_INT_COL_EN(ring_hnd->bank_offset, ring_hnd->bank_data->interrupt_mask); - WRITE_CSR_INT_COL_CTL(ring_hnd->bank_offset, - ETR_CSR_INTR_COL_CTL_TIME); + adf_write_coalescing_timer(ring_hnd); } } +#ifndef ICP_WITHOUT_QP_SUBMISSION_LOCK ICP_MUTEX_UNLOCK(&ring_hnd_first->user_lock); +#endif /* If any of the rings in the instance had data and was polled * return SUCCESS. */ if (stat_total) diff --git a/quickassist/lookaside/access_layer/src/sample_code/README.txt b/quickassist/lookaside/access_layer/src/sample_code/README.txt index 52dca5d7..edafbe77 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/README.txt +++ b/quickassist/lookaside/access_layer/src/sample_code/README.txt @@ -200,6 +200,7 @@ The runTests parameter is a bit masked variable used to control which tests are runTests=32 runStateful=1 useCnv=1 Run CNV test. runTests=1024 Run SM2 test. runTests=2048 Run SM3&4 test. + runTests=64 Run Stateless Decompression test. The current default is runTests=63, run all tests. diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c new file mode 100644 index 00000000..ea9f0f19 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_main.c @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_ecdsa_sample_main.c + * + *****************************************************************************/ +#include "cpa_types.h" +#include "cpa_sample_utils.h" +#include "icp_sal_user.h" + +extern CpaStatus kptEcdsaOp(void); + +int main(int argc, const char **argv) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + PRINT("Starting KPT ECDSA Sample Code App ...\n"); + + status = qaeMemInit(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to initialise memory driver\n"); + return (int)status; + } + + status = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to start user process SSL\n"); + qaeMemDestroy(); + return (int)status; + } + + status = kptEcdsaOp(); + if (CPA_STATUS_SUCCESS == status) + { + PRINT("\nKPT ECDSA Sample Code App finished\n"); + } + else + { + PRINT_ERR("\nKPT ECDSA Sample Code App failed\n"); + } + + icp_sal_userStop(); + qaeMemDestroy(); + + return (int)status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c new file mode 100644 index 00000000..368b68b8 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_ecdsa_sample/kpt_ecdsa_sample_op.c @@ -0,0 +1,866 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_rsa_sample_op.c + * + *****************************************************************************/ + +#include "kpt_sample_common.h" + +#define BITS_IN_BYTE 8 +#define P256_SIZE_IN_BITS 256 +#define SHA512_DIGEST_LEN_IN_BYTES (512 / BITS_IN_BYTE) + +/* AAD value is hardcode in KPT rather than random number, see KPT document */ +static const Cpa8U aad[] = { 0x06, 0x08, 0x2A, 0x86, 0x48, + 0xCE, 0x3D, 0x03, 0x01, 0x07 }; + +static const Cpa8U iv[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, + 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }; + +static const Cpa8U sampleSWK[] = { + 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, + 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, + 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, +}; + +static Cpa8U nist_p256_a[] = { 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc }; + +static Cpa8U nist_p256_b[] = { 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, + 0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98, 0x86, 0xbc, + 0x65, 0x1d, 0x6, 0xb0, 0xcc, 0x53, 0xb0, 0xf6, + 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b }; + +static Cpa8U nist_p256_r[] = { 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, + 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51 }; + +static Cpa8U nist_p256_p[] = { 0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x1, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + +static Cpa8U nist_p256_xg[] = { + 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, + 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x3, 0x7d, 0x81, 0x2d, 0xeb, + 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96 +}; + +static Cpa8U nist_p256_yg[] = { + 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, + 0x4a, 0x7c, 0xf, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, + 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5 +}; + +static Cpa8U nist_p256_xp[] = { + 0xd4, 0x7, 0x8c, 0x89, 0x34, 0xc7, 0x7b, 0x8f, 0xb7, 0xde, 0x74, + 0x38, 0x5a, 0xf4, 0x93, 0x11, 0x36, 0x17, 0x44, 0x4, 0xce, 0x79, + 0x9b, 0x0, 0x5a, 0xe6, 0x7c, 0xfb, 0xaf, 0x92, 0x1b, 0x14 +}; + +static Cpa8U nist_p256_yp[] = { 0x3a, 0x5b, 0xba, 0x62, 0x84, 0xf6, 0x54, 0x79, + 0xa4, 0x70, 0xb1, 0xb1, 0xaa, 0x40, 0x32, 0xe3, + 0xf4, 0x8, 0xad, 0x98, 0xdc, 0x67, 0xa8, 0x8a, + 0xfd, 0xf0, 0x4e, 0x5c, 0xd3, 0x61, 0x2d, 0x1 }; + +static Cpa8U nist_p256_d[] = { 0xb4, 0xf0, 0x54, 0x82, 0xa0, 0x24, 0x3, 0x9a, + 0x4f, 0x69, 0x1d, 0x4c, 0xd5, 0xbe, 0xbc, 0x0, + 0xca, 0x7e, 0xa2, 0x4, 0x3c, 0xde, 0xbb, 0x52, + 0xd, 0x3e, 0x3f, 0xa0, 0xc9, 0xd0, 0xb5, 0x2b }; + +static void freeEcdsaOpDataMemory(CpaCyEcdsaVerifyOpData ecdsaVerifyOpdata) +{ + if (NULL != ecdsaVerifyOpdata.a.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.a.pData); + } + if (NULL != ecdsaVerifyOpdata.b.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.b.pData); + } + if (NULL != ecdsaVerifyOpdata.n.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.n.pData); + } + if (NULL != ecdsaVerifyOpdata.q.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.q.pData); + } + if (NULL != ecdsaVerifyOpdata.xg.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.xg.pData); + } + if (NULL != ecdsaVerifyOpdata.yg.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.yg.pData); + } + if (NULL != ecdsaVerifyOpdata.xp.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.xp.pData); + } + if (NULL != ecdsaVerifyOpdata.yp.pData) + { + qaeMemFreeNUMA((void **)&ecdsaVerifyOpdata.yp.pData); + } +} + +static CpaStatus kptEcdsaSignRS(CpaInstanceHandle cyInstHandle, + Cpa32U node, + CpaFlatBuffer *r, + CpaFlatBuffer *s, + CpaFlatBuffer digest) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaCyKptEcdsaSignRSOpData kptSignRSOpData = { { 0 } }; + CpaCyKptUnwrapContext kptUnwrapCtx = { 0 }; + CpaFlatBuffer wpkAndAuthTag = { 0 }; + CpaBoolean stat = CPA_TRUE; + Cpa32U wpkSize = 0; + Cpa8U authTag[AUTH_TAG_LEN] = { 0 }; + CpaFlatBuffer privateKey = { 0 }; + CpaBoolean signStatus = CPA_FALSE; + CpaStatus retStatus = CPA_STATUS_SUCCESS; + CpaCyKptKeyManagementStatus kptStatus = CPA_CY_KPT_SUCCESS; + + status = encryptAndLoadSWK( + cyInstHandle, node, &kptUnwrapCtx.kptHandle, (Cpa8U *)sampleSWK); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("encrypt And Load SWK failed!\n"); + return status; + } + + memcpy(kptUnwrapCtx.iv, iv, sizeof(iv)); + memcpy(kptUnwrapCtx.additionalAuthData, aad, sizeof(aad)); + kptUnwrapCtx.aadLenInBytes = sizeof(aad); + + wpkAndAuthTag.dataLenInBytes = + (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE + AUTH_TAG_LEN; + wpkAndAuthTag.pData = + qaeMemAllocNUMA(wpkAndAuthTag.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == wpkAndAuthTag.pData) + { + PRINT_ERR("qaeMemAlloc wpkAndAuthTag error\n"); + return CPA_STATUS_FAIL; + } + memset(wpkAndAuthTag.pData, 0, wpkAndAuthTag.dataLenInBytes); + + privateKey.dataLenInBytes = + (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + privateKey.pData = qaeMemAlloc(privateKey.dataLenInBytes); + if (NULL == privateKey.pData) + { + PRINT_ERR("qaeMemAlloc privateKey failed\n"); + qaeMemFreeNUMA((void **)&wpkAndAuthTag.pData); + return CPA_STATUS_FAIL; + } + memset(privateKey.pData, 0, privateKey.dataLenInBytes); + memcpy(privateKey.pData + privateKey.dataLenInBytes - sizeof(nist_p256_d), + nist_p256_d, + sizeof(nist_p256_d)); + + stat = encryptPrivateKey(privateKey.pData, + privateKey.dataLenInBytes, + (Cpa8U *)sampleSWK, + (Cpa8U *)iv, + sizeof(iv), + wpkAndAuthTag.pData, + &wpkSize, + authTag, + (Cpa8U *)aad, + sizeof(aad)); + if (CPA_TRUE != stat) + { + PRINT_ERR("encryptPrivateKey failed!\n"); + qaeMemFreeNUMA((void **)&wpkAndAuthTag.pData); + qaeMemFree((void **)&privateKey.pData); + return CPA_STATUS_FAIL; + } + + memcpy(wpkAndAuthTag.pData + wpkSize, authTag, AUTH_TAG_LEN); + + kptSignRSOpData.privateKey = wpkAndAuthTag; + + kptSignRSOpData.m.dataLenInBytes = digest.dataLenInBytes; + kptSignRSOpData.m.pData = qaeMemAllocNUMA( + kptSignRSOpData.m.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == kptSignRSOpData.m.pData) + { + PRINT_ERR("qaeMemAllocNUMA kptSignRSOpData.m.pData failed!\n"); + qaeMemFreeNUMA((void **)&wpkAndAuthTag.pData); + qaeMemFree((void **)&privateKey.pData); + return CPA_STATUS_FAIL; + } + memset(kptSignRSOpData.m.pData, 0, kptSignRSOpData.m.dataLenInBytes); + memcpy(kptSignRSOpData.m.pData, + digest.pData, + kptSignRSOpData.m.dataLenInBytes); + + status = cpaCyKptEcdsaSignRS(cyInstHandle, + NULL, + NULL, + &kptSignRSOpData, + &signStatus, + r, + s, + &kptUnwrapCtx); + if ((CPA_STATUS_SUCCESS != status) || (CPA_TRUE != signStatus)) + { + PRINT_ERR("cpaCyKptEcdsaSignRS failed\n"); + status = CPA_STATUS_FAIL; + } + + retStatus = + cpaCyKptDeleteKey(cyInstHandle, kptUnwrapCtx.kptHandle, &kptStatus); + if ((CPA_STATUS_SUCCESS != retStatus) || (CPA_CY_KPT_SUCCESS != kptStatus)) + { + PRINT_ERR("Delete SWK failed with status: %d, kptStatus: %d\n", + retStatus, + kptStatus); + status = CPA_STATUS_FAIL; + } + + qaeMemFreeNUMA((void **)&wpkAndAuthTag.pData); + qaeMemFree((void **)&privateKey.pData); + qaeMemFreeNUMA((void **)&kptSignRSOpData.m.pData); + return status; +} + +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) +static CpaStatus swEcdsaVerifySign(CpaFlatBuffer r, + CpaFlatBuffer s, + CpaFlatBuffer digest) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + int result = 0; + EVP_PKEY *pkey = NULL; + EVP_PKEY_CTX *ctx = NULL; + BIGNUM *r_bn = NULL, *s_bn = NULL; + ECDSA_SIG *sig = NULL; + unsigned char *sig_der = NULL; + int sig_len = 0, pub_key_len = 0; + unsigned char *pub_key = NULL; + EVP_PKEY_CTX *pctx = NULL; + OSSL_PARAM_BLD *param_bld = NULL; + OSSL_PARAM *params = NULL; + Cpa32U xp_len = sizeof(nist_p256_xp); + Cpa32U yp_len = sizeof(nist_p256_yp); + + pkey = EVP_PKEY_new(); + if (NULL == pkey) + { + PRINT_ERR("EVP_PKEY_new() failed\n"); + return CPA_STATUS_FAIL; + } + + /* Convert binary data to BIGNUMs */ + r_bn = BN_bin2bn(r.pData, r.dataLenInBytes, NULL); + s_bn = BN_bin2bn(s.pData, s.dataLenInBytes, NULL); + if (NULL == r_bn || NULL == s_bn) + { + PRINT_ERR("BN_bin2bn() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + /* Create the ECDSA_SIG object from r and s */ + sig = ECDSA_SIG_new(); + if (NULL == sig) + { + PRINT_ERR("ECDSA_SIG_new() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + if (1 != ECDSA_SIG_set0(sig, r_bn, s_bn)) + { + PRINT_ERR("ECDSA_SIG_set0() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + /* Set these to NULL since they are now owned by obj */ + r_bn = NULL; + s_bn = NULL; + + /* Convert ECDSA_SIG to DER format */ + sig_len = i2d_ECDSA_SIG(sig, &sig_der); + if (sig_len <= 0) + { + PRINT_ERR("i2d_ECDSA_SIG() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + pub_key_len = xp_len + yp_len + 1; + pub_key = qaeMemAlloc(pub_key_len); + if (NULL == pub_key) + { + PRINT_ERR("Could not allocate memory for pub_key\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + pub_key[0] = POINT_CONVERSION_UNCOMPRESSED; + memcpy(pub_key + 1, nist_p256_xp, xp_len); + memcpy(pub_key + 1 + xp_len, nist_p256_yp, yp_len); + + /* Create the public key using EVP interface */ + param_bld = OSSL_PARAM_BLD_new(); + if (NULL == param_bld) + { + PRINT_ERR("OSSL_PARAM_BLD_new() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + if (OSSL_PARAM_BLD_push_utf8_string( + param_bld, OSSL_PKEY_PARAM_GROUP_NAME, SN_X9_62_prime256v1, 0) && + OSSL_PARAM_BLD_push_octet_string( + param_bld, OSSL_PKEY_PARAM_PUB_KEY, pub_key, pub_key_len)) + { + params = OSSL_PARAM_BLD_to_param(param_bld); + } + + if (NULL == params) + { + PRINT_ERR("OSSL_PARAM_BLD_to_param() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); + if (NULL == pctx) + { + PRINT_ERR("EVP_PKEY_CTX_new_id() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + if (EVP_PKEY_fromdata_init(pctx) <= 0) + { + PRINT_ERR("EVP_PKEY_fromdata_init() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + if (EVP_PKEY_fromdata(pctx, &pkey, EVP_PKEY_PUBLIC_KEY, params) <= 0) + { + PRINT_ERR("EVP_PKEY_fromdata() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + /* Create and initialize the context for verification */ + ctx = EVP_PKEY_CTX_new(pkey, NULL); + if (NULL == ctx) + { + PRINT_ERR("EVP_PKEY_CTX_new() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + if (EVP_PKEY_verify_init(ctx) <= 0) + { + PRINT_ERR("EVP_PKEY_verify_init() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + /* Verify the signature */ + result = EVP_PKEY_verify( + ctx, sig_der, sig_len, digest.pData, digest.dataLenInBytes); + if (1 != result) + { + PRINT_ERR("EVP_PKEY_verify() failed\n"); + status = CPA_STATUS_FAIL; + } + +exit: + if (r_bn) + BN_free(r_bn); + if (s_bn) + BN_free(s_bn); + if (sig) + ECDSA_SIG_free(sig); + if (sig_der) + OPENSSL_free(sig_der); + if (pkey) + EVP_PKEY_free(pkey); + if (ctx) + EVP_PKEY_CTX_free(ctx); + if (pctx) + EVP_PKEY_CTX_free(pctx); + if (params) + OSSL_PARAM_free(params); + if (param_bld) + OSSL_PARAM_BLD_free(param_bld); + if (pub_key) + qaeMemFree((void **)&pub_key); + + return status; +} +#else +static CpaStatus swEcdsaVerifySign(CpaFlatBuffer r, + CpaFlatBuffer s, + CpaFlatBuffer digest) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + int result = 0; + EC_KEY *eckey = NULL; + const EC_GROUP *group = NULL; + EC_POINT *pub_key_point = NULL; + BIGNUM *x_bn = NULL; + BIGNUM *y_bn = NULL; + BIGNUM *r_bn = NULL; + BIGNUM *s_bn = NULL; + ECDSA_SIG *sig = NULL; + + eckey = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); + if (NULL == eckey) + { + PRINT_ERR("EC_KEY_new_by_curve_name() failed\n"); + return CPA_STATUS_FAIL; + } + + // Create a new EC_POINT for the public key + group = EC_KEY_get0_group(eckey); + pub_key_point = EC_POINT_new(group); + if (NULL == pub_key_point) + { + PRINT_ERR("EC_POINT_new() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + // Convert the X and Y coordinates to an EC_POINT + x_bn = BN_bin2bn(nist_p256_xp, sizeof(nist_p256_xp), NULL); + y_bn = BN_bin2bn(nist_p256_yp, sizeof(nist_p256_yp), NULL); + if (NULL == x_bn || NULL == y_bn) + { + PRINT_ERR("BN_bin2bn() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + // Set the X and Y coordinates to the EC_POINT +#if (OPENSSL_VERSION_NUMBER < 0x10101000L) + if (1 != EC_POINT_set_affine_coordinates_GFp( + group, pub_key_point, x_bn, y_bn, NULL)) + { + PRINT_ERR("EC_POINT_set_affine_coordinates_GFp() failed: Unable to set " + "the affine coordinates for the given EC_POINT.\n"); + status = CPA_STATUS_FAIL; + goto exit; + } +#else + if (1 != + EC_POINT_set_affine_coordinates(group, pub_key_point, x_bn, y_bn, NULL)) + { + PRINT_ERR("EC_POINT_set_affine_coordinates() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } +#endif + // Set the public key + if (1 != EC_KEY_set_public_key(eckey, pub_key_point)) + { + PRINT_ERR("EC_KEY_set_public_key() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + sig = ECDSA_SIG_new(); + if (NULL == sig) + { + PRINT_ERR("ECDSA_SIG_new() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + r_bn = BN_bin2bn(r.pData, r.dataLenInBytes, NULL); + s_bn = BN_bin2bn(s.pData, s.dataLenInBytes, NULL); + if (NULL == r_bn || NULL == s_bn) + { + PRINT_ERR("BN_bin2bn() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + // Set the r and s values + if (1 != ECDSA_SIG_set0(sig, r_bn, s_bn)) + { + PRINT_ERR("ECDSA_SIG_set0() failed\n"); + status = CPA_STATUS_FAIL; + goto exit; + } + + /* Set these to NULL since they are now owned by obj */ + r_bn = NULL; + s_bn = NULL; + + /* Verify the signature */ + result = ECDSA_do_verify(digest.pData, digest.dataLenInBytes, sig, eckey); + if (1 != result) + { + PRINT_ERR("ECDSA_do_verify() failed\n"); + status = CPA_STATUS_FAIL; + } + +exit: + if (x_bn) + BN_free(x_bn); + if (y_bn) + BN_free(y_bn); + if (pub_key_point) + EC_POINT_free(pub_key_point); + if (eckey) + EC_KEY_free(eckey); + if (r_bn) + BN_free(r_bn); + if (s_bn) + BN_free(s_bn); + if (sig) + ECDSA_SIG_free(sig); + + return status; +} +#endif + +static CpaStatus ecdsaVerifySign(CpaInstanceHandle cyInstHandle, + Cpa32U node, + CpaFlatBuffer r, + CpaFlatBuffer s, + CpaFlatBuffer digest) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaCyEcdsaVerifyOpData ecdsaVerifyOpdata = { { 0 } }; + CpaBoolean verifyStatus = CPA_FALSE; + + ecdsaVerifyOpdata.fieldType = CPA_CY_EC_FIELD_TYPE_PRIME; + + ecdsaVerifyOpdata.a.dataLenInBytes = sizeof(nist_p256_a); + ecdsaVerifyOpdata.a.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.a.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.a.pData) + { + PRINT_ERR("qaeMemAllocNUMA a elliptic curve coefficient failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.a.pData, 0, ecdsaVerifyOpdata.a.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.a.pData, nist_p256_a, sizeof(nist_p256_a)); + + ecdsaVerifyOpdata.b.dataLenInBytes = sizeof(nist_p256_b); + ecdsaVerifyOpdata.b.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.b.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.b.pData) + { + PRINT_ERR("qaeMemAllocNUMA b elliptic curve coefficient failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.b.pData, 0, ecdsaVerifyOpdata.b.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.b.pData, nist_p256_b, sizeof(nist_p256_b)); + + ecdsaVerifyOpdata.m.dataLenInBytes = digest.dataLenInBytes; + ecdsaVerifyOpdata.m.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.m.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.m.pData) + { + PRINT_ERR("qaeMemAllocNUMA digest failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memcpy(ecdsaVerifyOpdata.m.pData, + digest.pData, + ecdsaVerifyOpdata.m.dataLenInBytes); + + ecdsaVerifyOpdata.n.dataLenInBytes = sizeof(nist_p256_r); + ecdsaVerifyOpdata.n.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.n.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.n.pData) + { + PRINT_ERR("qaeMemAllocNUMA order of the base point G failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.n.pData, 0, ecdsaVerifyOpdata.n.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.n.pData, nist_p256_r, sizeof(nist_p256_r)); + + ecdsaVerifyOpdata.q.dataLenInBytes = sizeof(nist_p256_p); + ecdsaVerifyOpdata.q.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.q.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.q.pData) + { + PRINT_ERR("qaeMemAllocNUMA prime modulus or irreducible polynomial " + "over GF failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.q.pData, 0, ecdsaVerifyOpdata.q.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.q.pData, nist_p256_p, sizeof(nist_p256_p)); + + ecdsaVerifyOpdata.r = r; + ecdsaVerifyOpdata.s = s; + + ecdsaVerifyOpdata.xg.dataLenInBytes = sizeof(nist_p256_xg); + ecdsaVerifyOpdata.xg.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.xg.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.xg.pData) + { + PRINT_ERR("qaeMemAllocNUMA x coordinate of base point G failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.xg.pData, 0, ecdsaVerifyOpdata.xg.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.xg.pData, nist_p256_xg, sizeof(nist_p256_xg)); + + ecdsaVerifyOpdata.yg.dataLenInBytes = sizeof(nist_p256_yg); + ecdsaVerifyOpdata.yg.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.yg.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.yg.pData) + { + PRINT_ERR("qaeMemAllocNUMA y coordinate of base point G failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.yg.pData, 0, ecdsaVerifyOpdata.yg.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.yg.pData, nist_p256_yg, sizeof(nist_p256_yg)); + + ecdsaVerifyOpdata.xp.dataLenInBytes = sizeof(nist_p256_xp); + ecdsaVerifyOpdata.xp.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.xp.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.xp.pData) + { + PRINT_ERR( + "qaeMemAllocNUMA x coordinate of point P (public key) failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.xp.pData, 0, ecdsaVerifyOpdata.xp.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.xp.pData, nist_p256_xp, sizeof(nist_p256_xp)); + + ecdsaVerifyOpdata.yp.dataLenInBytes = sizeof(nist_p256_yp); + ecdsaVerifyOpdata.yp.pData = (Cpa8U *)qaeMemAllocNUMA( + ecdsaVerifyOpdata.yp.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == ecdsaVerifyOpdata.yp.pData) + { + PRINT_ERR("qaeMemAllocNUMA y coordinate of base point G failed\n"); + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return CPA_STATUS_FAIL; + } + memset(ecdsaVerifyOpdata.yp.pData, 0, ecdsaVerifyOpdata.yp.dataLenInBytes); + memcpy(ecdsaVerifyOpdata.yp.pData, nist_p256_yp, sizeof(nist_p256_yp)); + + status = cpaCyEcdsaVerify( + cyInstHandle, NULL, NULL, &ecdsaVerifyOpdata, &verifyStatus); + if ((CPA_STATUS_SUCCESS != status) || (CPA_TRUE != verifyStatus)) + { + PRINT_ERR("ECDSA Verify function failed\n"); + status = CPA_STATUS_FAIL; + } + + freeEcdsaOpDataMemory(ecdsaVerifyOpdata); + return status; +} + +CpaStatus kptEcdsaOp(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceHandle cyInstHandle = 0; + CpaCyCapabilitiesInfo pCapInfo = { 0 }; + CpaInstanceInfo2 instanceInfo = { 0 }; + Cpa32U node = 0; + CpaFlatBuffer r = { 0 }; + CpaFlatBuffer s = { 0 }; + CpaFlatBuffer msg = { 0 }; + CpaFlatBuffer z = { 0 }; + CpaFlatBuffer digest = { 0 }; + + sampleAsymGetInstance(&cyInstHandle); + if (cyInstHandle == NULL) + { + return CPA_STATUS_FAIL; + } + + status = cpaCyInstanceGetInfo2(cyInstHandle, &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("%s::%d cpaCyInstanceGetInfo2 failed", __func__, __LINE__); + return status; + } + + status = queryCapabilitiesForKpt(cyInstHandle, instanceInfo, &pCapInfo); + if ((CPA_STATUS_SUCCESS != status) || + ((CPA_STATUS_SUCCESS == status) && !pCapInfo.kptSupported)) + { + return status; + } + + status = cpaCyStartInstance(cyInstHandle); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCyStartInstance failed\n"); + return status; + } + status = cpaCySetAddressTranslation(cyInstHandle, sampleVirtToPhys); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCySetAddressTranslation failed\n"); + cpaCyStopInstance(cyInstHandle); + return status; + } + sampleCyStartPolling(cyInstHandle); + + node = instanceInfo.nodeAffinity; + + msg.dataLenInBytes = (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + msg.pData = + (Cpa8U *)qaeMemAllocNUMA(msg.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == msg.pData) + { + PRINT_ERR("qaeMemAllocNUMA msg failed\n"); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(msg.pData, 0, msg.dataLenInBytes); + + PRINT("\ngenerate random message\n"); + genRandomData(msg.pData, msg.dataLenInBytes); + hexLog(msg.pData, msg.dataLenInBytes, "message"); + + digest.dataLenInBytes = SHA512_DIGEST_LEN_IN_BYTES; + digest.pData = (Cpa8U *)qaeMemAllocNUMA( + digest.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == digest.pData) + { + PRINT_ERR("qaeMemAllocNUMA digest failed\n"); + qaeMemFreeNUMA((void **)&msg.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(digest.pData, 0, digest.dataLenInBytes); + + PRINT("\ncalculate digest\n"); + if (NULL == SHA512(msg.pData, msg.dataLenInBytes, digest.pData)) + { + PRINT_ERR("ECDSA Calc Digest Error\n"); + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + hexLog(digest.pData, digest.dataLenInBytes, "digest"); + + r.dataLenInBytes = (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + r.pData = + (Cpa8U *)qaeMemAllocNUMA(r.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == r.pData) + { + PRINT_ERR("qaeMemAllocNUMA sign R failed\n"); + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(r.pData, 0, r.dataLenInBytes); + + s.dataLenInBytes = (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + s.pData = + (Cpa8U *)qaeMemAllocNUMA(s.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == s.pData) + { + PRINT_ERR("qaeMemAllocNUMA sign S failed\n"); + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + qaeMemFreeNUMA((void **)&r.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(s.pData, 0, s.dataLenInBytes); + + z.dataLenInBytes = (P256_SIZE_IN_BITS + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + z.pData = + (Cpa8U *)qaeMemAllocNUMA(z.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == z.pData) + { + PRINT_ERR("qaeMemAllocNUMA sign S failed\n"); + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + qaeMemFreeNUMA((void **)&r.pData); + qaeMemFreeNUMA((void **)&s.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(z.pData, 0, z.dataLenInBytes); + memcpy(z.pData, digest.pData, z.dataLenInBytes); + + PRINT("\ncalling kptEcdsaSignRS : Sign the digest of a random message " + "using elliptic curve data\n"); + status = kptEcdsaSignRS(cyInstHandle, node, &r, &s, z); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("kptEcdsaSignRS Error\n"); + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + qaeMemFreeNUMA((void **)&r.pData); + qaeMemFreeNUMA((void **)&s.pData); + qaeMemFreeNUMA((void **)&z.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + + /* Verify signature in HW if ecdsa capability is supported, else + * verify using SW */ + if (CPA_TRUE == pCapInfo.ecdsaSupported) + { + PRINT("\ncalling ecdsaVerifySign : verify the signatures to the " + "digest\n"); + status = ecdsaVerifySign(cyInstHandle, node, r, s, z); + } + else + { + PRINT("\ncalling swEcdsaVerifySign : verify the signatures to the " + "digest\n"); + status = swEcdsaVerifySign(r, s, z); + } + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Signature verification failed\n"); + } + else + { + PRINT("\nSignature verification succeeded\n"); + } + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + + qaeMemFreeNUMA((void **)&msg.pData); + qaeMemFreeNUMA((void **)&digest.pData); + qaeMemFreeNUMA((void **)&r.pData); + qaeMemFreeNUMA((void **)&s.pData); + qaeMemFreeNUMA((void **)&z.pData); + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c new file mode 100644 index 00000000..fe9b363d --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_main.c @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_rsa_sample_main.c + * + *****************************************************************************/ +#include "cpa_types.h" +#include "cpa_sample_utils.h" +#include "icp_sal_user.h" + +extern CpaStatus kptRsaOp(void); + +int main(int argc, const char **argv) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + PRINT("Starting KPT RSA Sample Code App ...\n"); + + status = qaeMemInit(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to initialise memory driver\n"); + return (int)status; + } + + status = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to start user process SSL\n"); + qaeMemDestroy(); + return (int)status; + } + + status = kptRsaOp(); + if (CPA_STATUS_SUCCESS == status) + { + PRINT("\nKPT RSA Sample Code App finished\n"); + } + else + { + PRINT_ERR("\nKPT RSA Sample Code App failed\n"); + } + + icp_sal_userStop(); + qaeMemDestroy(); + + return (int)status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c new file mode 100644 index 00000000..45ebbaa0 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_rsa_sample/kpt_rsa_sample_op.c @@ -0,0 +1,884 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_rsa_sample_op.c + * + *****************************************************************************/ + +#include "kpt_sample_common.h" + +#define KEY_SIZE_3072_BIT 3072 +#define BITS_IN_BYTE 8 +#define KEY_PAIRS_NUM 2 +#define MSB_SETTING (0x80) + +/* AAD value is hardcode in KPT rather than random number, see KPT document */ +static const Cpa8U aad[] = { 0x06, 0x08, 0x2A, 0x86, 0x48, + 0x86, 0xF7, 0x0D, 0x01, 0x01 }; + +static const Cpa8U iv[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, + 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc }; + +static const Cpa8U sampleSWK[] = { + 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, + 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, + 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, +}; + +static const Cpa8U qinv_3072[] = { + 0x88, 0x12, 0x11, 0x81, 0x47, 0x68, 0x02, 0x4A, 0xCA, 0x57, 0x28, 0x3E, + 0x2D, 0x33, 0xA3, 0x10, 0x11, 0x77, 0x7F, 0x32, 0x14, 0x08, 0x29, 0xBF, + 0xED, 0x2F, 0x5E, 0x1B, 0x76, 0x63, 0x95, 0x11, 0x61, 0x2F, 0xB2, 0x85, + 0x17, 0xE7, 0x66, 0x71, 0x3D, 0xB4, 0xA6, 0x35, 0x3E, 0x04, 0x1E, 0x23, + 0xE3, 0xF3, 0xF8, 0x87, 0x23, 0x38, 0x99, 0x1E, 0x43, 0xC1, 0xDB, 0xF4, + 0x0C, 0xA3, 0xA5, 0x5D, 0x33, 0x5F, 0x1F, 0x99, 0x0D, 0xAE, 0xF7, 0x81, + 0xD2, 0x8F, 0x30, 0x67, 0xCE, 0x44, 0x88, 0x24, 0xC2, 0x77, 0x3D, 0x1D, + 0xC5, 0xF7, 0x07, 0xE1, 0x64, 0x41, 0x89, 0x7E, 0x22, 0x9F, 0x2B, 0x93, + 0xA0, 0x95, 0xCB, 0x03, 0xD6, 0x73, 0x57, 0x0B, 0x32, 0x8D, 0xA5, 0x28, + 0x2B, 0xD1, 0xBA, 0x06, 0x89, 0xE6, 0x68, 0xDB, 0xDE, 0x8E, 0x3A, 0x2A, + 0xA9, 0xBF, 0x73, 0xAC, 0x33, 0xB8, 0x6F, 0x49, 0x8E, 0x09, 0xA1, 0xE2, + 0x54, 0x96, 0x4E, 0x0D, 0x29, 0x47, 0xA2, 0x59, 0xAC, 0x86, 0x8B, 0xEE, + 0xF6, 0x5D, 0x14, 0x65, 0x32, 0xCB, 0xA9, 0xB9, 0x47, 0xE3, 0x8F, 0x5A, + 0x40, 0xF7, 0xF4, 0x67, 0xB7, 0x92, 0xFF, 0x53, 0x38, 0xA3, 0xC9, 0x5E, + 0xC6, 0xAC, 0xA9, 0x50, 0x65, 0x1F, 0x6A, 0x49, 0x2F, 0x22, 0x1D, 0xEC, + 0x5C, 0xA0, 0x22, 0xE1, 0x2B, 0x20, 0x74, 0x44, 0xB7, 0x1E, 0x72, 0x09 +}; + +static const Cpa8U dp_3072[] = { + 0x85, 0x1E, 0x35, 0x4F, 0x9C, 0xAF, 0x9B, 0xF7, 0xAF, 0xFE, 0xCC, 0xFA, + 0x67, 0x26, 0x4D, 0xDB, 0x43, 0x51, 0x5E, 0xAC, 0xF5, 0x72, 0x41, 0x27, + 0x0C, 0x66, 0x02, 0x87, 0x30, 0xF0, 0xD0, 0xE0, 0xEC, 0x42, 0xA0, 0x01, + 0x25, 0x98, 0xEB, 0x51, 0xC3, 0xCC, 0x68, 0x85, 0x4E, 0xD4, 0x1B, 0x2C, + 0x51, 0x2F, 0xCF, 0x53, 0x22, 0x09, 0xCF, 0x4C, 0x5E, 0xAD, 0x4D, 0x83, + 0x39, 0xFA, 0x1C, 0x88, 0xED, 0x66, 0xAE, 0x87, 0x9A, 0xE0, 0xBA, 0xD4, + 0x1E, 0xD2, 0x63, 0x06, 0x5E, 0xB6, 0xBD, 0xEE, 0x11, 0xE1, 0x3D, 0x44, + 0x6E, 0x92, 0x88, 0x15, 0x58, 0x06, 0xAB, 0x84, 0x83, 0x95, 0x81, 0x62, + 0xE7, 0x9C, 0x1B, 0x99, 0xD4, 0x51, 0x3E, 0x37, 0x2B, 0x34, 0xBC, 0x17, + 0xA0, 0xBB, 0x2F, 0x3A, 0xDE, 0xE6, 0xDF, 0xE8, 0x4B, 0xD2, 0xA8, 0x9E, + 0x6C, 0x73, 0xE0, 0xC1, 0xA4, 0xA7, 0x07, 0x61, 0x12, 0x20, 0x03, 0x41, + 0xF5, 0x79, 0xEB, 0x40, 0x76, 0x92, 0x04, 0x47, 0x8D, 0x9C, 0x87, 0x2D, + 0xD9, 0x1A, 0x12, 0x65, 0xAD, 0x10, 0x70, 0x77, 0x6B, 0x1B, 0x5A, 0x3A, + 0x9B, 0xB3, 0x52, 0xF2, 0xFC, 0xDC, 0x73, 0x25, 0x33, 0x06, 0xBD, 0x5C, + 0x22, 0xCA, 0x50, 0x90, 0x94, 0xD3, 0x12, 0x8B, 0x1D, 0x2C, 0x63, 0xC2, + 0x26, 0xDA, 0x9A, 0x75, 0x22, 0x0E, 0x0F, 0xFA, 0x85, 0xE9, 0x4D, 0xB7 +}; + +static const Cpa8U dq_3072[] = { + 0x85, 0x1E, 0x2E, 0xAA, 0x2D, 0xCF, 0x64, 0x31, 0x76, 0x39, 0x9A, 0x33, + 0x6B, 0x19, 0x4B, 0x1C, 0xC9, 0x4B, 0x0B, 0xF4, 0xF5, 0x01, 0x29, 0x40, + 0xFE, 0x31, 0x9D, 0xEC, 0xBF, 0x50, 0xD4, 0xBE, 0x4D, 0x91, 0xD7, 0x0A, + 0x04, 0x94, 0x36, 0x19, 0xEF, 0x87, 0x48, 0xA6, 0x39, 0xE7, 0x92, 0x8C, + 0x2C, 0x09, 0xAF, 0x91, 0x9D, 0x9E, 0x14, 0x8E, 0x20, 0x26, 0x8A, 0x7B, + 0xCB, 0x15, 0x2D, 0x70, 0x6C, 0xF3, 0x5F, 0x38, 0x3A, 0x3B, 0x8A, 0x75, + 0x0C, 0x99, 0x49, 0x9B, 0xEE, 0x63, 0xB1, 0x94, 0x2B, 0x32, 0x62, 0xB4, + 0xB5, 0xD0, 0x77, 0xD2, 0x2F, 0x9A, 0x60, 0x91, 0xD5, 0x38, 0x88, 0x9B, + 0xB0, 0x46, 0xB9, 0xC3, 0x8E, 0x3C, 0xD3, 0x30, 0x6A, 0x57, 0x41, 0x03, + 0x8F, 0x8C, 0xB2, 0xE5, 0x56, 0x17, 0xAD, 0x84, 0xC6, 0x0D, 0x6E, 0x1D, + 0x1A, 0xEF, 0x65, 0x58, 0xF4, 0x58, 0x85, 0x24, 0x6B, 0xDE, 0xAD, 0x39, + 0xDA, 0x7B, 0xF7, 0xBE, 0x09, 0x3A, 0x61, 0xC7, 0xB1, 0x3E, 0xA1, 0xF2, + 0xC9, 0x45, 0xA9, 0xA2, 0xFE, 0x17, 0xA8, 0x49, 0x8D, 0x91, 0xBD, 0x2F, + 0x46, 0x43, 0x6E, 0xB7, 0xC9, 0x2D, 0xDA, 0xFD, 0x08, 0xC9, 0x70, 0x31, + 0x1C, 0xA4, 0x84, 0x76, 0xF7, 0x1F, 0xC8, 0xB6, 0xDD, 0x86, 0x38, 0x81, + 0x69, 0x3A, 0xF0, 0xE2, 0x6F, 0x60, 0x36, 0x00, 0x2C, 0xC2, 0x77, 0xCB +}; + +static const Cpa8U p_3072[] = { + 0xc7, 0xad, 0x4f, 0xf7, 0x6b, 0x07, 0x69, 0xf3, 0x87, 0xfe, 0x33, 0x77, + 0x9a, 0xb9, 0x74, 0xc8, 0xe4, 0xfa, 0x0e, 0x03, 0x70, 0x2b, 0x61, 0xba, + 0x92, 0x99, 0x03, 0xca, 0xc9, 0x69, 0x39, 0x51, 0x62, 0x63, 0xf0, 0x01, + 0xb8, 0x65, 0x60, 0xfa, 0xa5, 0xb2, 0x9c, 0xc7, 0xf6, 0x3e, 0x28, 0xc2, + 0x79, 0xc7, 0xb6, 0xfc, 0xb3, 0x0e, 0xb6, 0xf2, 0x8e, 0x03, 0xf4, 0x44, + 0xd6, 0xf7, 0x2a, 0xcd, 0x64, 0x1a, 0x05, 0xcb, 0x68, 0x51, 0x18, 0x3e, + 0x2e, 0x3b, 0x94, 0x89, 0x8e, 0x12, 0x1c, 0xe5, 0x1a, 0xd1, 0xdb, 0xe6, + 0xa5, 0xdb, 0xcc, 0x20, 0x04, 0x0a, 0x01, 0x46, 0xc5, 0x60, 0x42, 0x14, + 0x5b, 0x6a, 0x29, 0x66, 0xbe, 0x79, 0xdd, 0x52, 0xc0, 0xcf, 0x1a, 0x23, + 0x71, 0x18, 0xc6, 0xd8, 0x4e, 0x5a, 0x4f, 0xdc, 0x71, 0xbb, 0xfc, 0xed, + 0xa2, 0xad, 0xd1, 0x22, 0x76, 0xfa, 0x8b, 0x11, 0x9b, 0x30, 0x04, 0xe2, + 0xf0, 0x36, 0xe0, 0xe0, 0xb1, 0xdb, 0x06, 0x6b, 0x54, 0x6a, 0xca, 0xc4, + 0xc5, 0xa7, 0x1b, 0x98, 0x83, 0x98, 0xa8, 0xb3, 0x20, 0xa9, 0x07, 0x57, + 0xe9, 0x8c, 0xfc, 0x6c, 0x7b, 0x4a, 0xac, 0xb7, 0xcc, 0x8a, 0x1c, 0x0a, + 0x34, 0x2f, 0x78, 0xd8, 0xdf, 0x3c, 0x9b, 0xd0, 0xab, 0xc2, 0x95, 0xa3, + 0x3a, 0x47, 0xe7, 0xaf, 0xb3, 0x15, 0x17, 0xf7, 0xc8, 0xdd, 0xf4, 0x93 +}; + +static const Cpa8U q_3072[] = { + 0xc7, 0xad, 0x45, 0xff, 0x44, 0xb7, 0x16, 0x4a, 0x31, 0x56, 0x67, 0x4d, + 0x20, 0xa5, 0xf0, 0xab, 0x2d, 0xf0, 0x91, 0xef, 0x6f, 0x81, 0xbd, 0xe1, + 0x7d, 0x4a, 0x6c, 0xe3, 0x1e, 0xf9, 0x3f, 0x1d, 0x74, 0x5a, 0xc2, 0x8f, + 0x06, 0xde, 0x51, 0x26, 0xe7, 0x4a, 0xec, 0xf9, 0x56, 0xdb, 0x5b, 0xd2, + 0x42, 0x0e, 0x87, 0x5a, 0x6c, 0x6d, 0x1e, 0xd5, 0x30, 0x39, 0xcf, 0xb9, + 0xb0, 0x9f, 0xc4, 0x28, 0xa3, 0x6d, 0x0e, 0xd4, 0x57, 0x59, 0x4f, 0xaf, + 0x92, 0xe5, 0xee, 0x69, 0xe5, 0x95, 0x8a, 0x5e, 0x40, 0xcb, 0x94, 0x0f, + 0x10, 0xb8, 0xb3, 0xbb, 0x47, 0x67, 0x90, 0xda, 0xbf, 0xd4, 0xcc, 0xe9, + 0x88, 0x6a, 0x16, 0xa5, 0x55, 0x5b, 0x3c, 0xc8, 0x9f, 0x82, 0xe1, 0x85, + 0x57, 0x53, 0x0c, 0x58, 0x01, 0x23, 0x84, 0x47, 0x29, 0x14, 0x25, 0x2b, + 0xa8, 0x67, 0x18, 0x05, 0x6e, 0x84, 0xc7, 0xb6, 0xa1, 0xce, 0x03, 0xd6, + 0xc7, 0xb9, 0xf3, 0x9d, 0x0d, 0xd7, 0x92, 0xab, 0x89, 0xdd, 0xf2, 0xec, + 0x2d, 0xe8, 0x7e, 0x74, 0x7d, 0x23, 0x7c, 0x6e, 0x54, 0x5a, 0x9b, 0xc6, + 0xe9, 0x65, 0x26, 0x13, 0xad, 0xc4, 0xc8, 0x7b, 0x8d, 0x2e, 0x28, 0x49, + 0xaa, 0xf6, 0xc6, 0xb2, 0x72, 0xaf, 0xad, 0x12, 0x4c, 0x49, 0x54, 0xc2, + 0x1d, 0xd8, 0x69, 0x53, 0xa7, 0x10, 0x51, 0x00, 0x43, 0x23, 0xb3, 0xb1 +}; + +static const Cpa8U n_3072[] = { + 0x9B, 0xBE, 0xDF, 0xE1, 0x30, 0x2F, 0x46, 0x30, 0x29, 0xFA, 0x1A, 0x49, + 0xD8, 0x02, 0x96, 0x16, 0xC1, 0x94, 0x31, 0x5F, 0x0C, 0x7D, 0xE7, 0xC7, + 0xE3, 0x36, 0xA7, 0x99, 0x6A, 0xCF, 0x82, 0x38, 0xE9, 0x40, 0xAC, 0x56, + 0xC2, 0x10, 0x4C, 0xF9, 0x1F, 0x46, 0x3E, 0xA7, 0xF1, 0xDF, 0x07, 0x19, + 0xD1, 0xED, 0xB8, 0xF7, 0xBE, 0x7E, 0xB3, 0x6D, 0x00, 0x2F, 0x91, 0xB0, + 0x39, 0x98, 0x48, 0x5D, 0xA8, 0x17, 0x42, 0xF2, 0x4A, 0x45, 0x49, 0x2C, + 0xF5, 0x66, 0xAF, 0xB9, 0x9A, 0x89, 0x3D, 0x5A, 0xEB, 0x2B, 0xE5, 0x58, + 0xDD, 0x21, 0x77, 0xF8, 0x77, 0xB5, 0xFF, 0xCD, 0xAF, 0x38, 0xDA, 0x48, + 0x43, 0xC1, 0x02, 0x92, 0x5C, 0x0F, 0xAE, 0xE5, 0x87, 0xC2, 0x39, 0xCB, + 0x3F, 0x64, 0xDB, 0xF7, 0xA9, 0x0E, 0x68, 0xBC, 0xC8, 0x59, 0x8D, 0x60, + 0xBA, 0xDB, 0xCC, 0xB7, 0x7F, 0x79, 0x99, 0x96, 0x95, 0x1D, 0x42, 0x08, + 0x4A, 0x45, 0x05, 0xDC, 0xB9, 0xCD, 0x08, 0x90, 0x61, 0xB3, 0xD1, 0x32, + 0x88, 0x4C, 0x50, 0xB1, 0x8A, 0x30, 0x26, 0x3F, 0x66, 0xD6, 0x93, 0x2F, + 0x24, 0x0F, 0xF9, 0xD0, 0x79, 0x66, 0x1B, 0x8E, 0x4B, 0x47, 0x06, 0x97, + 0x79, 0x4F, 0x8D, 0xB5, 0x36, 0x65, 0xFE, 0xFE, 0xC9, 0xE0, 0x05, 0xB5, + 0x57, 0x8C, 0x4C, 0xD9, 0xAC, 0xD1, 0x8B, 0xEA, 0x61, 0x31, 0x44, 0x77, + 0x35, 0x7A, 0x84, 0xC0, 0x0E, 0x4E, 0xAA, 0x7D, 0x2D, 0x29, 0x06, 0x44, + 0x0C, 0xC2, 0xCA, 0xF3, 0xFB, 0xC0, 0xC3, 0x95, 0xB0, 0x17, 0x3E, 0xE7, + 0x8E, 0xFA, 0x64, 0xDA, 0x48, 0xB3, 0x2B, 0xAC, 0x21, 0x91, 0xA0, 0xCC, + 0x7F, 0x40, 0x31, 0x3D, 0x08, 0xE7, 0x01, 0xA3, 0x0C, 0x47, 0x7D, 0x14, + 0x88, 0xFC, 0x1D, 0x44, 0xAA, 0xD9, 0x1A, 0x36, 0x55, 0x8F, 0x65, 0x07, + 0xCA, 0x8A, 0xF9, 0x58, 0x59, 0xA8, 0x25, 0x62, 0x26, 0xF7, 0x48, 0x48, + 0x19, 0x9C, 0xE3, 0x49, 0x3C, 0x74, 0x10, 0xAC, 0x0C, 0xBC, 0xD9, 0x99, + 0x94, 0xC3, 0xC2, 0x36, 0x59, 0x21, 0x8A, 0xD4, 0x1A, 0xFE, 0x49, 0x1F, + 0xF3, 0x33, 0x3B, 0x90, 0xA0, 0xF6, 0x62, 0x0A, 0xA8, 0xBA, 0x8C, 0xA7, + 0xAB, 0xEA, 0x81, 0x59, 0x36, 0xF8, 0x68, 0xD1, 0x43, 0xCC, 0xFD, 0xE4, + 0xC8, 0xF1, 0x28, 0x2A, 0x8B, 0xD9, 0x05, 0x9D, 0x19, 0x4C, 0x87, 0x8D, + 0x52, 0xA1, 0x83, 0x38, 0xF5, 0xA8, 0xC3, 0xAF, 0x45, 0x2C, 0xB8, 0xF7, + 0xB6, 0xE1, 0x5B, 0x5A, 0xF2, 0x26, 0xAA, 0xB3, 0x99, 0x37, 0x23, 0x5F, + 0xF3, 0x76, 0x23, 0xF5, 0x4B, 0xDD, 0x2B, 0x02, 0x9D, 0x27, 0x74, 0xCC, + 0x5F, 0x9D, 0xA6, 0x05, 0x9D, 0x4A, 0x17, 0x10, 0x46, 0xB5, 0x86, 0xCB, + 0x38, 0x04, 0x61, 0x7D, 0x1A, 0x5C, 0xE4, 0x1F, 0xFC, 0x91, 0xE2, 0xA3 +}; + +static const Cpa8U e_3072[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 +}; + +static void makeParam1SmallerThanParam2(Cpa8U *param1, + Cpa8U *param2, + Cpa32U len, + CpaBoolean msbSettingRequired) +{ + Cpa32U i = 0; + int startLen = 0; + if (msbSettingRequired == CPA_TRUE) + { + + /*set startLen = 1 so that next for loop starts + * at 1 rather than 0, + * we handle element 0 here*/ + startLen = 1; + /*Ignoring MSB, if param2 is less than param1, and param2 is not 0, + * then make param1 to be smaller than param2, and we are done*/ + if (((param2[0] & (~MSB_SETTING)) <= (param1[0] & (~MSB_SETTING))) && + (param2[0] & (~MSB_SETTING)) != 0) + { + param1[0] = param2[0] - 1; + return; + } + /*Ignoring MSB, if param2 is 0 then param1 needs to be zero with MSB + * set and we check the next index*/ + else if ((param2[0] & (~MSB_SETTING)) == 0) + { + param1[i] = MSB_SETTING; + } + /*else Param1 is smaller than param2 so set i = len to skip next for + * loop*/ + else + { + return; + } + } + for (i = startLen; i < len; i++) + { + /*if param2 is less than param1, and param2 is not 0, then make param1 + * to be smaller than param2, and we are done*/ + if ((param2[i] <= param1[i]) && param2[i] != 0) + { + param1[i] = param2[i] - 1; + break; + } + + /*if param2 is 0 then param1 needs to be zero and we check the next + * index*/ + else if (param2[i] == 0) + { + param1[i] = 0; + } + /*Param1 is smaller than param2 so we break*/ + else + { + break; + } + } +} + +static CpaStatus setKptRsaDecryptOpData( + Cpa32U node, + CpaFlatBuffer inputData, + CpaCyKptRsaDecryptOpData *pKptRsaDecOpdata) +{ + CpaFlatBuffer rsaPrivateKey = { 0 }; + CpaFlatBuffer wpkAndAuthTag = { 0 }; + Cpa8U authTag[AUTH_TAG_LEN] = { 0 }; + Cpa32U wpkSize = 0; + CpaBoolean stat = CPA_TRUE; + + pKptRsaDecOpdata->pRecipientPrivateKey = qaeMemAllocNUMA( + sizeof(CpaCyKptRsaPrivateKey *), node, BYTE_ALIGNMENT_64); + if (NULL == pKptRsaDecOpdata->pRecipientPrivateKey) + { + PRINT_ERR( + "qaeMemAllocNUMA pKptRsaDecOpdata->pRecipientPrivateKey error\n"); + return CPA_STATUS_FAIL; + } + + rsaPrivateKey.dataLenInBytes = + sizeof(qinv_3072) + sizeof(dp_3072) + sizeof(dq_3072) + sizeof(p_3072) + + sizeof(q_3072) + sizeof(p_3072) * KEY_PAIRS_NUM; + + rsaPrivateKey.pData = qaeMemAlloc(rsaPrivateKey.dataLenInBytes); + if (NULL == rsaPrivateKey.pData) + { + PRINT_ERR("qaeMemAlloc rsaPrivateKey error\n"); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->pRecipientPrivateKey)); + return CPA_STATUS_FAIL; + } + + memset(rsaPrivateKey.pData, 0, rsaPrivateKey.dataLenInBytes); + memcpy(rsaPrivateKey.pData, p_3072, sizeof(p_3072)); + + memcpy(rsaPrivateKey.pData + sizeof(p_3072), q_3072, sizeof(q_3072)); + + memcpy(rsaPrivateKey.pData + sizeof(p_3072) + sizeof(q_3072), + dp_3072, + sizeof(dp_3072)); + + memcpy(rsaPrivateKey.pData + sizeof(p_3072) + sizeof(q_3072) + + sizeof(dp_3072), + dq_3072, + sizeof(dq_3072)); + + memcpy(rsaPrivateKey.pData + sizeof(p_3072) + sizeof(q_3072) + + sizeof(dp_3072) + sizeof(dq_3072), + qinv_3072, + sizeof(qinv_3072)); + + memcpy(rsaPrivateKey.pData + sizeof(p_3072) + sizeof(q_3072) + + sizeof(dp_3072) + sizeof(dq_3072) + sizeof(qinv_3072) + + sizeof(p_3072) * KEY_PAIRS_NUM - sizeof(e_3072), + e_3072, + sizeof(e_3072)); + + wpkAndAuthTag.dataLenInBytes = rsaPrivateKey.dataLenInBytes + AUTH_TAG_LEN; + wpkAndAuthTag.pData = qaeMemAlloc(wpkAndAuthTag.dataLenInBytes); + if (NULL == wpkAndAuthTag.pData) + { + PRINT_ERR("qaeMemAlloc wpkAndAuthTag error\n"); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->pRecipientPrivateKey)); + qaeMemFree((void **)&rsaPrivateKey.pData); + return CPA_STATUS_FAIL; + } + + stat = encryptPrivateKey(rsaPrivateKey.pData, + rsaPrivateKey.dataLenInBytes, + (Cpa8U *)sampleSWK, + (Cpa8U *)iv, + sizeof(iv), + wpkAndAuthTag.pData, + &wpkSize, + authTag, + (Cpa8U *)aad, + sizeof(aad)); + if (CPA_FALSE == stat) + { + PRINT_ERR("encryptPrivateKey failed!\n"); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->pRecipientPrivateKey)); + qaeMemFree((void **)&rsaPrivateKey.pData); + qaeMemFree((void **)&wpkAndAuthTag.pData); + return CPA_STATUS_FAIL; + } + + memcpy(wpkAndAuthTag.pData + wpkSize, authTag, AUTH_TAG_LEN); + + pKptRsaDecOpdata->inputData.dataLenInBytes = inputData.dataLenInBytes; + pKptRsaDecOpdata->inputData.pData = (Cpa8U *)qaeMemAllocNUMA( + inputData.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == pKptRsaDecOpdata->inputData.pData) + { + PRINT_ERR("qaeMemAllocNUMA pKptRsaDecOpdata->inputData error\n"); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->pRecipientPrivateKey)); + qaeMemFree((void **)&rsaPrivateKey.pData); + qaeMemFree((void **)&wpkAndAuthTag.pData); + return CPA_STATUS_FAIL; + } + memcpy(pKptRsaDecOpdata->inputData.pData, + inputData.pData, + inputData.dataLenInBytes); + + pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRep2.privateKey + .dataLenInBytes = wpkSize + AUTH_TAG_LEN; + pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRep2.privateKey.pData = + (Cpa8U *)qaeMemAllocNUMA(pKptRsaDecOpdata->pRecipientPrivateKey + ->privateKeyRep2.privateKey.dataLenInBytes, + node, + BYTE_ALIGNMENT_64); + if (NULL == + pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRep2.privateKey.pData) + { + PRINT_ERR("qaeMemAllocNUMA " + "pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRep2." + "privateKey error\n"); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->pRecipientPrivateKey)); + qaeMemFreeNUMA((void **)&(pKptRsaDecOpdata->inputData.pData)); + qaeMemFree((void **)&rsaPrivateKey.pData); + qaeMemFree((void **)&wpkAndAuthTag.pData); + return CPA_STATUS_FAIL; + } + memcpy( + pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRep2.privateKey.pData, + wpkAndAuthTag.pData, + wpkSize + AUTH_TAG_LEN); + + pKptRsaDecOpdata->pRecipientPrivateKey->privateKeyRepType = + CPA_CY_RSA_PRIVATE_KEY_REP_TYPE_2; + pKptRsaDecOpdata->pRecipientPrivateKey->version = + CPA_CY_RSA_VERSION_TWO_PRIME; + + qaeMemFree((void **)&rsaPrivateKey.pData); + qaeMemFree((void **)&wpkAndAuthTag.pData); + + return CPA_STATUS_SUCCESS; +} + +static CpaStatus swRsaSampleEnc(CpaInstanceHandle cyInstHandle, + Cpa32U node, + CpaFlatBuffer inputData, + CpaFlatBuffer *pOutputData) +{ + + CpaStatus status = CPA_STATUS_SUCCESS; + EVP_PKEY *pPubKey = NULL; + EVP_PKEY_CTX *pCtx = NULL; + int ret = 0; +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + OSSL_PARAM_BLD *pBld = NULL; + BIGNUM *pE_bn = NULL; + BIGNUM *pN_bn = NULL; + OSSL_PARAM *pParams = NULL; +#else + CpaBoolean retStatus = CPA_TRUE; + RSA *pKey = NULL; +#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */ +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + if (CPA_STATUS_SUCCESS == status) + { + pBld = OSSL_PARAM_BLD_new(); + if ((NULL == pBld)) + { + PRINT("OSSL_PARAM_BLD_new() failed \n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + pN_bn = BN_new(); + pE_bn = BN_new(); + if ((NULL == pN_bn) || (NULL == pE_bn)) + { + PRINT(" BN_new() failed \n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + BN_bin2bn(n_3072, sizeof(n_3072), pN_bn); + OSSL_PARAM_BLD_push_BN(pBld, "n", pN_bn); + BN_bin2bn(e_3072, sizeof(e_3072), pE_bn); + OSSL_PARAM_BLD_push_BN(pBld, "e", pE_bn); + + pParams = OSSL_PARAM_BLD_to_param(pBld); + if (NULL == pParams) + { + PRINT("OSSL_PARAM_BLD_to_param() failed \n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + pCtx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates generate key context failed!\n"); + status = CPA_STATUS_FAIL; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + EVP_PKEY_fromdata_init(pCtx); + EVP_PKEY_fromdata(pCtx, &pPubKey, EVP_PKEY_PUBLIC_KEY, pParams); + EVP_PKEY_CTX_free(pCtx); + pCtx = EVP_PKEY_CTX_new(pPubKey, NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } +#else + if (CPA_STATUS_SUCCESS == status) + { + pKey = RSA_new(); + pPubKey = EVP_PKEY_new(); + if (NULL == pKey) + { + PRINT("RSA_new() failed \n"); + status = CPA_STATUS_FAIL; + } + else if (NULL == pPubKey) + { + PRINT("EVP_PKEY_new() failed"); + RSA_free(pKey); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + /*-----set public key with n and e-----*/ + retStatus = RSA_set0_key(pKey, + BN_bin2bn(n_3072, sizeof(n_3072), NULL), + BN_bin2bn(e_3072, sizeof(e_3072), NULL), + NULL); + if (CPA_TRUE != retStatus) + { + PRINT_ERR("RSA_set0_key failed \n"); + RSA_free(pKey); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + EVP_PKEY_assign_RSA(pPubKey, pKey); + pCtx = EVP_PKEY_CTX_new(pPubKey, NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } +#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */ + if (CPA_STATUS_SUCCESS == status) + { + if (EVP_PKEY_encrypt_init(pCtx) > 0) + { + EVP_PKEY_CTX_ctrl_str(pCtx, "rsa_padding_mode", "none"); + } + else + { + PRINT_ERR("Initializes a public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + ret = EVP_PKEY_encrypt(pCtx, + pOutputData->pData, + (size_t *)&(pOutputData->dataLenInBytes), + inputData.pData, + inputData.dataLenInBytes); + + if ((ret <= 0) || (0 == pOutputData->dataLenInBytes) || + (pOutputData->dataLenInBytes > + (KEY_SIZE_3072_BIT + BITS_IN_BYTE - 1) / BITS_IN_BYTE)) + { + PRINT_ERR("EVP_PKEY_encrypt failed!\n"); + status = CPA_STATUS_FAIL; + } + } +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + if (NULL != pBld) + { + OSSL_PARAM_BLD_free(pBld); + } + if (NULL != pN_bn) + { + BN_free(pN_bn); + } + if (NULL != pE_bn) + { + BN_free(pE_bn); + } + if (NULL != pParams) + { + OSSL_PARAM_free(pParams); + } + if (NULL != pCtx) + { + EVP_PKEY_CTX_free(pCtx); + } +#else + if (NULL != pCtx) + { + EVP_PKEY_CTX_free(pCtx); + } + if (NULL != pPubKey) + { + EVP_PKEY_free(pPubKey); + } +#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */ + + return status; +} +static CpaStatus rsaSampleEnc(CpaInstanceHandle cyInstHandle, + Cpa32U node, + CpaFlatBuffer inputData, + CpaFlatBuffer *pOutputData) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaCyRsaEncryptOpData encryptOpData = { 0 }; + + encryptOpData.inputData.dataLenInBytes = inputData.dataLenInBytes; + encryptOpData.inputData.pData = (Cpa8U *)qaeMemAllocNUMA( + inputData.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == encryptOpData.inputData.pData) + { + PRINT_ERR("Failed to allocate mem for encrypt input data\n"); + return CPA_STATUS_FAIL; + } + memset(encryptOpData.inputData.pData, 0, inputData.dataLenInBytes); + memcpy(encryptOpData.inputData.pData, + inputData.pData, + inputData.dataLenInBytes); + + encryptOpData.pPublicKey = qaeMemAlloc(sizeof(CpaCyRsaPublicKey)); + if (NULL == encryptOpData.pPublicKey) + { + PRINT_ERR("Failed to allocate mem for RSA public key\n"); + qaeMemFreeNUMA((void **)&encryptOpData.inputData.pData); + return CPA_STATUS_FAIL; + } + memset(encryptOpData.pPublicKey, 0, sizeof(CpaCyRsaPublicKey)); + + encryptOpData.pPublicKey->modulusN.dataLenInBytes = sizeof(n_3072); + encryptOpData.pPublicKey->modulusN.pData = + (Cpa8U *)qaeMemAllocNUMA(sizeof(n_3072), node, BYTE_ALIGNMENT_64); + if (NULL == encryptOpData.pPublicKey->modulusN.pData) + { + PRINT_ERR("Failed to allocate mem for modulusN\n"); + qaeMemFreeNUMA((void **)&encryptOpData.inputData.pData); + qaeMemFree((void **)&encryptOpData.pPublicKey); + return CPA_STATUS_FAIL; + } + memset(encryptOpData.pPublicKey->modulusN.pData, 0, sizeof(n_3072)); + memcpy(encryptOpData.pPublicKey->modulusN.pData, n_3072, sizeof(n_3072)); + + encryptOpData.pPublicKey->publicExponentE.dataLenInBytes = sizeof(e_3072); + encryptOpData.pPublicKey->publicExponentE.pData = + (Cpa8U *)qaeMemAllocNUMA(sizeof(e_3072), node, BYTE_ALIGNMENT_64); + if (NULL == encryptOpData.pPublicKey->publicExponentE.pData) + { + PRINT_ERR("Failed to allocate mem for publicExponentE\n"); + qaeMemFreeNUMA((void **)&encryptOpData.pPublicKey->modulusN.pData); + qaeMemFreeNUMA((void **)&encryptOpData.inputData.pData); + qaeMemFree((void **)&encryptOpData.pPublicKey); + return CPA_STATUS_FAIL; + } + memset(encryptOpData.pPublicKey->publicExponentE.pData, 0, sizeof(e_3072)); + memcpy(encryptOpData.pPublicKey->publicExponentE.pData, + e_3072, + sizeof(e_3072)); + + status = cpaCyRsaEncrypt(cyInstHandle, + NULL, /*callback function not required*/ + NULL, /*opaque data not required*/ + &encryptOpData, + pOutputData); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("RSA encrypt failed\n"); + } + + qaeMemFreeNUMA((void **)&encryptOpData.pPublicKey->publicExponentE.pData); + qaeMemFreeNUMA((void **)&encryptOpData.pPublicKey->modulusN.pData); + qaeMemFreeNUMA((void **)&encryptOpData.inputData.pData); + qaeMemFree((void **)&encryptOpData.pPublicKey); + + return status; +} + +static CpaStatus kptRsaSampleDec(CpaInstanceHandle cyInstHandle, + Cpa32U node, + CpaFlatBuffer inputData, + CpaFlatBuffer *pOutputData) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaCyKptRsaDecryptOpData kptRsaDecOpdata = { 0 }; + CpaCyKptUnwrapContext kptUnwrapCtx = { 0 }; + CpaCyKptKeyManagementStatus kptStatus = CPA_CY_KPT_SUCCESS; + + status = encryptAndLoadSWK( + cyInstHandle, node, &kptUnwrapCtx.kptHandle, (Cpa8U *)sampleSWK); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("encrypt And Load SWK failed!\n"); + return status; + } + + memcpy(kptUnwrapCtx.iv, iv, sizeof(iv)); + memcpy(kptUnwrapCtx.additionalAuthData, aad, sizeof(aad)); + kptUnwrapCtx.aadLenInBytes = sizeof(aad); + + status = setKptRsaDecryptOpData(node, inputData, &kptRsaDecOpdata); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("setKptRsaDecryptOpData failed!\n"); + cpaCyKptDeleteKey(cyInstHandle, kptUnwrapCtx.kptHandle, &kptStatus); + return status; + } + + pOutputData->dataLenInBytes = KEY_SIZE_3072_BIT / BITS_IN_BYTE; + pOutputData->pData = (Cpa8U *)qaeMemAllocNUMA( + pOutputData->dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == pOutputData->pData) + { + PRINT_ERR("qaeMemAllocNUMA pOutputData failed\n"); + cpaCyKptDeleteKey(cyInstHandle, kptUnwrapCtx.kptHandle, &kptStatus); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.inputData.pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.pRecipientPrivateKey + ->privateKeyRep2.privateKey.pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.pRecipientPrivateKey)); + return CPA_STATUS_FAIL; + } + + status = cpaCyKptRsaDecrypt(cyInstHandle, + NULL, /*callback function not required*/ + NULL, /*opaque data not required*/ + &kptRsaDecOpdata, + pOutputData, + &kptUnwrapCtx); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCyKptRsaDecrypt failed, status =%d \n", status); + cpaCyKptDeleteKey(cyInstHandle, kptUnwrapCtx.kptHandle, &kptStatus); + qaeMemFreeNUMA((void **)&(pOutputData->pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.inputData.pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.pRecipientPrivateKey + ->privateKeyRep2.privateKey.pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.pRecipientPrivateKey)); + return status; + } + + printf("key deletion, handle is 0x%lx \n", kptUnwrapCtx.kptHandle); + status = + cpaCyKptDeleteKey(cyInstHandle, kptUnwrapCtx.kptHandle, &kptStatus); + if ((CPA_STATUS_SUCCESS != status) || (CPA_CY_KPT_SUCCESS != kptStatus)) + { + PRINT_ERR("Delete SWK failed with status: %d,kpt2Status: %d.\n", + status, + kptStatus); + qaeMemFreeNUMA((void **)&(pOutputData->pData)); + status = CPA_STATUS_FAIL; + } + + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.inputData.pData)); + qaeMemFreeNUMA((void **)&( + kptRsaDecOpdata.pRecipientPrivateKey->privateKeyRep2.privateKey.pData)); + qaeMemFreeNUMA((void **)&(kptRsaDecOpdata.pRecipientPrivateKey)); + + return status; +} + +CpaStatus kptRsaOp(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceHandle cyInstHandle = 0; + CpaCyCapabilitiesInfo pCapInfo = { 0 }; + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaFlatBuffer rsaEncInputData = { 0 }; + CpaFlatBuffer rsaEncOutputData = { 0 }; + CpaFlatBuffer kptRsaDecOutputData = { 0 }; + Cpa32U node = 0; + Cpa16U num = 0; + + cpaCyGetNumInstances(&num); + sampleCyGetInstance(&cyInstHandle); + if (cyInstHandle == NULL) + { + return CPA_STATUS_FAIL; + } + + status = cpaCyInstanceGetInfo2(cyInstHandle, &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("%s::%d cpaCyInstanceGetInfo2 failed", __func__, __LINE__); + return CPA_STATUS_FAIL; + } + + status = queryCapabilitiesForKpt(cyInstHandle, instanceInfo, &pCapInfo); + if ((CPA_STATUS_SUCCESS != status) || + ((CPA_STATUS_SUCCESS == status) && !pCapInfo.kptSupported)) + { + return status; + } + + status = cpaCyStartInstance(cyInstHandle); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCyStartInstance failed\n"); + return status; + } + status = cpaCySetAddressTranslation(cyInstHandle, sampleVirtToPhys); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCySetAddressTranslation failed\n"); + cpaCyStopInstance(cyInstHandle); + return status; + } + sampleCyStartPolling(cyInstHandle); + + node = instanceInfo.nodeAffinity; + + rsaEncInputData.dataLenInBytes = + (KEY_SIZE_3072_BIT + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + rsaEncInputData.pData = (Cpa8U *)qaeMemAllocNUMA( + rsaEncInputData.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == rsaEncInputData.pData) + { + PRINT_ERR("qaeMemAlloc inputData->pData error\n"); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + rsaEncOutputData.dataLenInBytes = + (KEY_SIZE_3072_BIT + BITS_IN_BYTE - 1) / BITS_IN_BYTE; + rsaEncOutputData.pData = (Cpa8U *)qaeMemAllocNUMA( + rsaEncOutputData.dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == rsaEncOutputData.pData) + { + PRINT_ERR("qaeMemAlloc pRsaEncOutputData->pData error\n"); + qaeMemFreeNUMA((void **)&rsaEncInputData.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + memset(rsaEncOutputData.pData, 0, rsaEncOutputData.dataLenInBytes); + + PRINT("Generate random data for RSA encryption\n"); + genRandomData(rsaEncInputData.pData, rsaEncInputData.dataLenInBytes); + makeParam1SmallerThanParam2( + rsaEncInputData.pData, (Cpa8U *)n_3072, sizeof(n_3072), CPA_FALSE); + hexLog(rsaEncInputData.pData, + rsaEncInputData.dataLenInBytes, + "encrypt input data"); + + if (CPA_TRUE == pCapInfo.rsaSupported) + { + PRINT("Calling rsaSampleEnc : Encrypt input data\n"); + status = rsaSampleEnc( + cyInstHandle, node, rsaEncInputData, &rsaEncOutputData); + } + else + { + PRINT("Calling swRsaSampleEnc : Encrypt input data\n"); + status = swRsaSampleEnc( + cyInstHandle, node, rsaEncInputData, &rsaEncOutputData); + } + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("RSA encryption failed, status = %d\n", status); + qaeMemFreeNUMA((void **)&rsaEncInputData.pData); + qaeMemFreeNUMA((void **)&rsaEncOutputData.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return status; + } + hexLog(rsaEncOutputData.pData, + rsaEncOutputData.dataLenInBytes, + "RSA encrypted data"); + + PRINT("calling kptRsaSampleDec : Decrypt encrypted data\n"); + status = kptRsaSampleDec( + cyInstHandle, node, rsaEncOutputData, &kptRsaDecOutputData); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("kptRsaSampleDec not a success, status = %d\n", status); + qaeMemFreeNUMA((void **)&rsaEncInputData.pData); + qaeMemFreeNUMA((void **)&rsaEncOutputData.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return status; + } + + hexLog(kptRsaDecOutputData.pData, + kptRsaDecOutputData.dataLenInBytes, + "KPT RSA decrypted data"); + + if (memcmp(rsaEncInputData.pData, + kptRsaDecOutputData.pData, + kptRsaDecOutputData.dataLenInBytes) != 0) + { + PRINT_ERR("RSA match error\n"); + qaeMemFreeNUMA((void **)&rsaEncInputData.pData); + qaeMemFreeNUMA((void **)&rsaEncOutputData.pData); + qaeMemFreeNUMA((void **)&kptRsaDecOutputData.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + return CPA_STATUS_FAIL; + } + + PRINT("RSA match succeeded\n"); + + qaeMemFreeNUMA((void **)&rsaEncInputData.pData); + qaeMemFreeNUMA((void **)&rsaEncOutputData.pData); + qaeMemFreeNUMA((void **)&kptRsaDecOutputData.pData); + sampleCyStopPolling(); + cpaCyStopInstance(cyInstHandle); + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c new file mode 100644 index 00000000..add93c9b --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.c @@ -0,0 +1,570 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_sample_common.c + * + *****************************************************************************/ + +#include "kpt_sample_common.h" + +CpaStatus queryCapabilitiesForKpt(CpaInstanceHandle cyInstHandle, + CpaInstanceInfo2 instanceInfo, + CpaCyCapabilitiesInfo *pCapInfo) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + status = cpaCyQueryCapabilities(cyInstHandle, pCapInfo); + if ((CPA_STATUS_SUCCESS == status) && !pCapInfo->kptSupported) + { + PRINT_ERR("Inst (BDF:%02x:%02d.%d) does not support KPT2!\n", + (Cpa8U)(instanceInfo.physInstId.busAddress >> BUS_DIGIT), + (Cpa8U)((instanceInfo.physInstId.busAddress & 0xFF) >> + DEVICE_DIGIT), + (Cpa8U)(instanceInfo.physInstId.busAddress & FUNCTION_DIGIT)); + return CPA_STATUS_FAIL; + } + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCyQueryCapabilities failed!\n"); + } + + return status; +} + +/*************************************************************************** + * @description + * + * This function is to encrypt SWKs. + * + * @param[in] instanceHandle Instance Handle + * @param[in] node node + * @param[in] sampleSWK SWK + * @param[out] encryptedSWK encrypted SWK + * + * @retval CPA_STATUS_SUCCESS Setup successfully + * @retval CPA_STATUS_FAIL Setup failed + ***************************************************************************/ +static CpaStatus kptEncryptSWK(CpaInstanceHandle instanceHandle, + Cpa32U node, + Cpa8U *sampleSWK, + CpaFlatBuffer **encryptedSWK) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaCyKptValidationKey *pPerPartPublicKeyData = NULL; + EVP_PKEY *pPubKey = NULL; + EVP_PKEY_CTX *pCtx = NULL; +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + BN_CTX *pBn_ctx = NULL; + OSSL_PARAM_BLD *pBld = NULL; + BIGNUM *pE_bn = NULL; + BIGNUM *pN_bn = NULL; + OSSL_PARAM *pParams = NULL; +#else +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) + CpaBoolean retStatus = CPA_TRUE; + RSA *pKey = NULL; +#endif +#endif + + int ret = 0; + CpaCyKptKeyManagementStatus kptStatus = CPA_CY_KPT_SUCCESS; + Cpa32U keyProvisionRetryTimes = 0; + + pPerPartPublicKeyData = + qaeMemAllocNUMA(sizeof(CpaCyKptValidationKey), node, BYTE_ALIGNMENT_64); + if (NULL == pPerPartPublicKeyData) + { + status = CPA_STATUS_FAIL; + } + if (CPA_STATUS_SUCCESS == status) + { + /*get I-PuK*/ + pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes = + CPA_CY_RSA3K_SIG_SIZE_INBYTES; + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes = + PER_PART_PKEY_E_SIZE; + pPerPartPublicKeyData->publicKey.modulusN.pData = + qaeMemAllocNUMA(sizeof(Cpa8U) * CPA_CY_RSA3K_SIG_SIZE_INBYTES, + node, + BYTE_ALIGNMENT_64); + pPerPartPublicKeyData->publicKey.publicExponentE.pData = + qaeMemAllocNUMA( + sizeof(Cpa8U) * PER_PART_PKEY_E_SIZE, node, BYTE_ALIGNMENT_64); + if ((NULL == pPerPartPublicKeyData->publicKey.modulusN.pData) || + (NULL == pPerPartPublicKeyData->publicKey.publicExponentE.pData)) + { + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + do + { + status = cpaCyKptQueryDeviceCredentials( + instanceHandle, pPerPartPublicKeyData, &kptStatus); + keyProvisionRetryTimes++; + } while ((CPA_STATUS_RETRY == status) && + (keyProvisionRetryTimes <= KEY_PROVISION_RETRY_TIMES_LIMIT)); + if (1 < keyProvisionRetryTimes) + { + PRINT("KPT Get I-Pu Retry Times : %d\n", + keyProvisionRetryTimes - 1); + } + if (CPA_STATUS_SUCCESS != status || CPA_CY_KPT_SUCCESS != kptStatus) + { + PRINT_ERR("Get I-Pu failed with status: %d,kptStatus: %d\n", + status, + kptStatus); + status = CPA_STATUS_FAIL; + } + } +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + if (CPA_STATUS_SUCCESS == status) + { + pBn_ctx = BN_CTX_new(); + pBld = OSSL_PARAM_BLD_new(); + if ((NULL == pBn_ctx) || (NULL == pBld)) + { + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + pN_bn = BN_CTX_get(pBn_ctx); + pE_bn = BN_CTX_get(pBn_ctx); + if ((NULL == pN_bn) || (NULL == pE_bn)) + { + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + BN_bin2bn(pPerPartPublicKeyData->publicKey.modulusN.pData, + pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes, + pN_bn); + OSSL_PARAM_BLD_push_BN(pBld, "n", pN_bn); + + BN_bin2bn( + pPerPartPublicKeyData->publicKey.publicExponentE.pData, + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes, + pE_bn); + OSSL_PARAM_BLD_push_BN(pBld, "e", pE_bn); + + pParams = OSSL_PARAM_BLD_to_param(pBld); + if (NULL == pParams) + { + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + pCtx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates generate key context failed!\n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + EVP_PKEY_fromdata_init(pCtx); + EVP_PKEY_fromdata(pCtx, &pPubKey, EVP_PKEY_PUBLIC_KEY, pParams); + EVP_PKEY_CTX_free(pCtx); + + pCtx = EVP_PKEY_CTX_new(pPubKey, NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } +#else +#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) + if (CPA_STATUS_SUCCESS == status) + { + pKey = RSA_new(); + pPubKey = EVP_PKEY_new(); + if (NULL == pKey) + { + status = CPA_STATUS_FAIL; + } + else if (NULL == pPubKey) + { + RSA_free(pKey); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + /*-----set public key with n and e-----*/ + retStatus = RSA_set0_key( + pKey, + BN_bin2bn(pPerPartPublicKeyData->publicKey.modulusN.pData, + pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes, + NULL), + BN_bin2bn( + pPerPartPublicKeyData->publicKey.publicExponentE.pData, + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes, + NULL), + NULL); + if (CPA_TRUE != retStatus) + { + PRINT_ERR("RSA_set0_key failed \n"); + RSA_free(pKey); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + EVP_PKEY_assign_RSA(pPubKey, pKey); + pCtx = EVP_PKEY_CTX_new(pPubKey, NULL); + if (NULL == pCtx) + { + PRINT_ERR("Allocates public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } +#endif +#endif // #if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + if (CPA_STATUS_SUCCESS == status) + { + if (EVP_PKEY_encrypt_init(pCtx) > 0) + { + EVP_PKEY_CTX_ctrl_str(pCtx, "rsa_padding_mode", "oaep"); + EVP_PKEY_CTX_ctrl_str(pCtx, "rsa_oaep_md", "sha256"); + EVP_PKEY_CTX_ctrl_str(pCtx, "rsa_mgf1_md", "sha256"); + } + else + { + PRINT_ERR("Initializes a public key algorithm context failed!\n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + /*encrypt SWK*/ + (*encryptedSWK)->pData = qaeMemAlloc( + pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes + + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes); + if (NULL == (*encryptedSWK)->pData) + { + PRINT_ERR("qaeMemAlloc error\n"); + status = CPA_STATUS_FAIL; + } + } + if (CPA_STATUS_SUCCESS == status) + { + (*encryptedSWK)->dataLenInBytes = + pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes + + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes; + + ret = EVP_PKEY_encrypt(pCtx, + (*encryptedSWK)->pData, + (size_t *)&((*encryptedSWK)->dataLenInBytes), + sampleSWK, + SWK_LEN_IN_BYTES); + if ((ret <= 0) || (0 == (*encryptedSWK)->dataLenInBytes) || + ((*encryptedSWK)->dataLenInBytes > + (pPerPartPublicKeyData->publicKey.modulusN.dataLenInBytes + + pPerPartPublicKeyData->publicKey.publicExponentE.dataLenInBytes))) + { + PRINT_ERR("Encrypt SWK failed!\n"); + qaeMemFree((void **)&((*encryptedSWK)->pData)); + status = CPA_STATUS_FAIL; + } + } + +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) + if (NULL != pBn_ctx) + { + BN_CTX_free(pBn_ctx); + } + if (NULL != pBld) + { + OSSL_PARAM_BLD_free(pBld); + } + if (NULL != pParams) + { + OSSL_PARAM_free(pParams); + } +#endif + if (NULL != pCtx) + { + EVP_PKEY_CTX_free(pCtx); + } + if (NULL != pPubKey) + { + EVP_PKEY_free(pPubKey); + } + if (NULL != pPerPartPublicKeyData) + { + if (NULL != pPerPartPublicKeyData->publicKey.modulusN.pData) + { + qaeMemFreeNUMA( + (void **)&pPerPartPublicKeyData->publicKey.modulusN.pData); + } + if (NULL != pPerPartPublicKeyData->publicKey.publicExponentE.pData) + { + qaeMemFreeNUMA((void **)&pPerPartPublicKeyData->publicKey + .publicExponentE.pData); + } + qaeMemFreeNUMA((void **)&pPerPartPublicKeyData); + } + return status; +} + +/*************************************************************************** + * @description + * + * This function is to load encrypted SWKs to QAT + * + * @param[in] instanceHandle Instance handle + * @param[in] node node + * @param[out] kptKeyHandle keyhandle + * @param[in] encryptedSWK encrypted SWK + * + * @detail load 1 SWK, + * and expect the results to be successfully + * + * @retval CPA_STATUS_SUCCESS Load SWK successfully + * @retval CPA_STATUS_FAIL Load SWK failed + * + ***************************************************************************/ +static CpaStatus kptLoadSWK(CpaInstanceHandle instanceHandle, + Cpa32U node, + CpaCyKptHandle *kptKeyHandle, + CpaFlatBuffer *encryptedSWK) +{ + CpaStatus status = CPA_STATUS_FAIL; + CpaCyKptKeyManagementStatus kptStatus = CPA_CY_KPT_SUCCESS; + CpaCyKptLoadKey *pSWKLoadKey = NULL; + Cpa32U keyProvisionRetryTimes = 0; + + pSWKLoadKey = + qaeMemAllocNUMA(sizeof(CpaCyKptLoadKey), node, BYTE_ALIGNMENT_64); + if (NULL == pSWKLoadKey) + { + return CPA_STATUS_FAIL; + } + pSWKLoadKey->wrappingAlgorithm = CPA_CY_KPT_WRAPPING_KEY_TYPE_AES256_GCM; + pSWKLoadKey->eSWK.pData = + qaeMemAllocNUMA(encryptedSWK->dataLenInBytes, node, BYTE_ALIGNMENT_64); + if (NULL == pSWKLoadKey->eSWK.pData) + { + qaeMemFreeNUMA((void **)&pSWKLoadKey); + return CPA_STATUS_FAIL; + } + pSWKLoadKey->eSWK.dataLenInBytes = encryptedSWK->dataLenInBytes; + + memcpy(pSWKLoadKey->eSWK.pData, + encryptedSWK->pData, + encryptedSWK->dataLenInBytes); + do + { + status = cpaCyKptLoadKey( + instanceHandle, pSWKLoadKey, kptKeyHandle, &kptStatus); + keyProvisionRetryTimes++; + } while ((CPA_STATUS_RETRY == status) && + (keyProvisionRetryTimes <= KEY_PROVISION_RETRY_TIMES_LIMIT)); + if (1 < keyProvisionRetryTimes) + { + PRINT("KPT Load Key Retry Times : %d\n", keyProvisionRetryTimes - 1); + } + if (CPA_STATUS_SUCCESS == status) + { + if (CPA_CY_KPT_SUCCESS != kptStatus) + { + PRINT_ERR("Check CPA_CY_KPT_SUCCESS failed.\n"); + status = CPA_STATUS_FAIL; + } + } + else + { + PRINT_ERR("cpaCyKptLoadKey failed with status:%d.\n", status); + status = CPA_STATUS_FAIL; + } + + if (NULL != pSWKLoadKey) + { + if (NULL != pSWKLoadKey->eSWK.pData) + { + qaeMemFreeNUMA((void **)&pSWKLoadKey->eSWK.pData); + } + qaeMemFreeNUMA((void **)&pSWKLoadKey); + } + + return status; +} + +/*************************************************************************** + * @description + * + * This function is to encrypt customer private key by AES-256-GCM + * + * @param[in] pPrivateKey customer private key + * @param[in] privateKeyLength customer private key length + * @param[in] pSWK SWK + * @param[in] pIv iv + * @param[in] ivLength iv length + * @param[in] pAad Additional Authenticated Data + * @param[in] aadLenInBytes the length of aad + * @param[out] pWrappedPrivateKey wrapped private key + * @param[out] pWPKLength wrapped private key length + * @param[out] pAuthTag Authentication tag (16 Bytes) + * + * @retval CPA_TRUE Operation is successful + * @retval CPA_FALSE Operation is failure + ***************************************************************************/ +CpaBoolean encryptPrivateKey(Cpa8U *pPrivateKey, + Cpa32U privateKeyLength, + Cpa8U *pSWK, + Cpa8U *pIv, + Cpa32U ivLength, + Cpa8U *pWrappedPrivateKey, + Cpa32U *pWPKLength, + Cpa8U *pAuthTag, + Cpa8U *pAad, + Cpa32U aadLenInBytes) +{ + EVP_CIPHER_CTX *pCtx; + Cpa32U outputLength; + Cpa32U cipherTestLen; + + if (!(pCtx = EVP_CIPHER_CTX_new())) + { + PRINT_ERR("EVP_CIPHER_CTX_new() failed\n"); + return CPA_FALSE; + } + + if (EVP_EncryptInit_ex(pCtx, EVP_aes_256_gcm(), NULL, NULL, NULL) == 0) + { + PRINT_ERR("EVP_EncryptInit_ex() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + if (EVP_CIPHER_CTX_ctrl(pCtx, EVP_CTRL_GCM_SET_IVLEN, ivLength, NULL) == 0) + { + PRINT_ERR("EVP_CIPHER_CTX_ctrl() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + if (EVP_EncryptInit_ex(pCtx, NULL, NULL, pSWK, pIv) == 0) + { + PRINT_ERR("EVP_EncryptInit_ex() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + if (EVP_EncryptUpdate( + pCtx, NULL, (int *)&outputLength, pAad, aadLenInBytes) == 0) + { + PRINT_ERR("EVP_EncryptUpdate() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + if (EVP_EncryptUpdate(pCtx, + pWrappedPrivateKey, + (int *)&outputLength, + pPrivateKey, + privateKeyLength) == 0) + { + PRINT_ERR("EVP_EncryptUpdate() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + cipherTestLen = outputLength; + + if (EVP_EncryptFinal_ex( + pCtx, pWrappedPrivateKey + outputLength, (int *)&outputLength) == 0) + { + PRINT_ERR("EVP_EncryptFinal_ex() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + if (EVP_CIPHER_CTX_ctrl( + pCtx, EVP_CTRL_GCM_GET_TAG, AUTH_TAG_LEN, pAuthTag) == 0) + { + PRINT_ERR("EVP_CIPHER_CTX_ctrl() failed\n"); + EVP_CIPHER_CTX_free(pCtx); + return CPA_FALSE; + } + + EVP_CIPHER_CTX_free(pCtx); + + *pWPKLength = cipherTestLen + outputLength; + + return CPA_TRUE; +} + +/*************************************************************************** + * @description + * + * This function is to encrypt SWKs and load encrypted SWK to QAT + * + * @param[in] instanceHandle Instance handle + * @param[in] node node + * @param[out] kptKeyHandle key handle + * @param[in] sampleSWK SWK + * + * @detail Encrypt and load 1 SWK + * + * @retval CPA_STATUS_SUCCESS Load SWK successfully + * @retval CPA_STATUS_FAIL Load SWK failed + * + ***************************************************************************/ +CpaStatus encryptAndLoadSWK(CpaInstanceHandle instanceHandle, + Cpa32U node, + CpaCyKptHandle *kptKeyHandle, + Cpa8U *sampleSWK) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaFlatBuffer *encryptedSWK = NULL; + /*encrypt SWK*/ + encryptedSWK = qaeMemAlloc(sizeof(CpaFlatBuffer)); + if (NULL == encryptedSWK) + { + PRINT_ERR("qaeMemAlloc error\n"); + status = CPA_STATUS_FAIL; + } + if (CPA_STATUS_SUCCESS == status) + { + status = kptEncryptSWK(instanceHandle, node, sampleSWK, &encryptedSWK); + } + if (CPA_STATUS_SUCCESS == status) + { + /*Load SWKs*/ + status = kptLoadSWK(instanceHandle, node, kptKeyHandle, encryptedSWK); + } + if (NULL != encryptedSWK->pData) + { + qaeMemFree((void **)&encryptedSWK->pData); + } + if (NULL != encryptedSWK) + { + qaeMemFree((void **)&encryptedSWK); + } + return status; +} + +void genRandomData(Cpa8U *pWriteRandData, Cpa32U lengthOfRand) +{ + Cpa32U i = 0; + srand(sampleCoderdtsc()); + for (i = 0; i < lengthOfRand; i++) + { + pWriteRandData[i] = (Cpa8U)rand(); + } +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h new file mode 100644 index 00000000..3f9678a8 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/kpt/kpt_sample_common.h @@ -0,0 +1,70 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file kpt_sample_common.h + * + *****************************************************************************/ +#ifndef __KPT_SAMPLE_COMMON_H__ +#define __KPT_SAMPLE_COMMON_H__ + +#include "cpa.h" +#include "cpa_cy_kpt.h" + +#include "cpa_sample_utils.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (OPENSSL_VERSION_NUMBER >= 0x30000000L) +#include +#include +#endif + +#define AUTH_TAG_LEN 16 +#define PER_PART_PKEY_E_SIZE 8 +#define KEY_PROVISION_RETRY_TIMES_LIMIT 20 +#define SWK_LEN_IN_BYTES 32 +#define UPPER_HALF_OF_REGISTER 32 +#define BUS_DIGIT 8 +#define DEVICE_DIGIT 3 +#define FUNCTION_DIGIT 7 + +CpaStatus encryptAndLoadSWK(CpaInstanceHandle instanceHandle, + Cpa32U node, + CpaCyKptHandle *kptKeyHandle, + Cpa8U *sampleSWK); + +CpaBoolean encryptPrivateKey(Cpa8U *pPrivateKey, + Cpa32U privateKeyLength, + Cpa8U *pSWK, + Cpa8U *pIv, + Cpa32U ivLength, + Cpa8U *pWrappedPrivateKey, + Cpa32U *pWPKLength, + Cpa8U *pAuthTag, + Cpa8U *pAad, + Cpa32U aadLenInBytes); + +void genRandomData(Cpa8U *pWriteRandData, Cpa32U lengthOfRand); + +CpaStatus queryCapabilitiesForKpt(CpaInstanceHandle cyInstHandle, + CpaInstanceInfo2 instanceInfo, + CpaCyCapabilitiesInfo *pCapInfo); + +#endif diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c b/quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c index 77d44876..06c426e3 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/common/cpa_sample_utils.c @@ -55,14 +55,13 @@ CpaDcHuffType huffmanType_g = CPA_DC_HT_STATIC; * ************************************************************* */ -#ifdef DO_CRYPTO /* - * This function returns a handle to an instance of the - * API of the crypto service type. It does this by querying the API for all - * instances of the desired type and returning the first such instance. + * This function returns a handle to an instance + * specified by the acceleration service type. It returns the first instance + * of the desired type. */ -static void sampleCryptoGetInstance(CpaAccelerationServiceType accelSrvType, - CpaInstanceHandle *pInstHandle) +static void sampleGetInstance(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *pInstHandle) { CpaInstanceHandle instHandles[MAX_INSTANCES]; Cpa16U numInstances = 0; @@ -70,20 +69,46 @@ static void sampleCryptoGetInstance(CpaAccelerationServiceType accelSrvType, *pInstHandle = NULL; status = cpaGetNumInstances(accelSrvType, &numInstances); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Error while getting number of instances.\n"); + return; + } +#ifdef DO_CRYPTO + /* + * Try to get specific crypto instance type + * if not found try to get generic legacy crypto instance. + */ if (0 == numInstances && (accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_SYM || accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_ASYM)) { accelSrvType = CPA_ACC_SVC_TYPE_CRYPTO; status = cpaGetNumInstances(accelSrvType, &numInstances); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Error while getting number of instances.\n"); + return; + } } +#endif if (numInstances > MAX_INSTANCES) { numInstances = MAX_INSTANCES; } if (0 == numInstances) { - PRINT_ERR("No crypto instances found.\n"); + PRINT_ERR( + "No %s instance found.\n", + accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_SYM ? "symmetric crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_ASYM ? "asymmetric crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO ? "crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_DATA_COMPRESSION + ? "data compression" + : accelSrvType == CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION + ? "data decompression" + : "unknown"); + return; } if (status == CPA_STATUS_SUCCESS) { @@ -93,23 +118,34 @@ static void sampleCryptoGetInstance(CpaAccelerationServiceType accelSrvType, } else { - PRINT_ERR("Error while getting a crypto instance.\n"); + PRINT_ERR( + "Error while getting %s instance.\n", + accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_SYM ? "symmetric crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO_ASYM ? "asymmetric crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_CRYPTO ? "crypto" + : accelSrvType == CPA_ACC_SVC_TYPE_DATA_COMPRESSION + ? "data compression" + : accelSrvType == CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION + ? "data decompression" + : "unknown"); + return; } } +#ifdef DO_CRYPTO void sampleSymGetInstance(CpaInstanceHandle *pSymInstHandle) { - sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_SYM, pSymInstHandle); + sampleGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_SYM, pSymInstHandle); } void sampleAsymGetInstance(CpaInstanceHandle *pAsymInstHandle) { - sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, pAsymInstHandle); + sampleGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, pAsymInstHandle); } void sampleCyGetInstance(CpaInstanceHandle *pCyInstHandle) { - sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO, pCyInstHandle); + sampleGetInstance(CPA_ACC_SVC_TYPE_CRYPTO, pCyInstHandle); } void symSessionWaitForInflightReq(CpaCySymSessionCtx pSessionCtx) @@ -177,37 +213,15 @@ void sampleCyStopPolling(void) } #endif -/* - * This function returns a handle to an instance of the data - * compression API. It does this by querying the API for all - * instances and returning the first such instance. - */ -// void sampleDcGetInstance(CpaInstanceHandle *pDcInstHandle) { - CpaInstanceHandle dcInstHandles[MAX_INSTANCES]; - Cpa16U numInstances = 0; - CpaStatus status = CPA_STATUS_SUCCESS; - - *pDcInstHandle = NULL; - status = cpaDcGetNumInstances(&numInstances); - if (numInstances >= MAX_INSTANCES) - { - numInstances = MAX_INSTANCES; - } - if ((status == CPA_STATUS_SUCCESS) && (numInstances > 0)) - { - status = cpaDcGetInstances(numInstances, dcInstHandles); - if (status == CPA_STATUS_SUCCESS) - *pDcInstHandle = dcInstHandles[0]; - } + sampleGetInstance(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, pDcInstHandle); +} - if (0 == numInstances) - { - PRINT_ERR("No compression instances found.\n"); - } +void sampleDecompGetInstance(CpaInstanceHandle *pDecompInstHandle) +{ + sampleGetInstance(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, pDecompInstHandle); } -// /* * This function polls a compression instance. @@ -327,4 +341,127 @@ CpaPhysicalAddr virtAddrToDevAddr(void *pVirtAddr, { return (CpaPhysicalAddr)(uintptr_t)pVirtAddr; } -} \ No newline at end of file +} + +#ifdef USER_SPACE +/* + * This function copies a file to memory + */ +CpaStatus sample_getFile(const char *filename, file_data_t *file_data) +{ + FILE *srcFile = NULL; + Cpa8U *pBuff = NULL; + struct stat st = { 0 }; + long file_size = 0; + int fd = -1; + + /* Validate input parameters */ + if (NULL == filename || NULL == file_data || NULL == file_data->pSrcData || + NULL == file_data->bufferSize) + { + PRINT_ERR("Invalid NULL parameter passed to sample_getFile\n"); + return CPA_STATUS_INVALID_PARAM; + } + + fd = open(filename, O_RDONLY); + if (fd < 0) + { + PRINT_ERR("Could not open file %s\n", filename); + return CPA_STATUS_FAIL; + } + + /* Get filesize using fstat on the opened file descriptor */ + if (0 != fstat(fd, &st)) + { + PRINT_ERR("Could not get the file %s size\n", filename); + close(fd); + return CPA_STATUS_FAIL; + } + file_size = st.st_size; + + /* Validate file size is non-negative and reasonable */ + if (file_size <= 0) + { + PRINT_ERR("Invalid file size for %s\n", filename); + close(fd); + return CPA_STATUS_FAIL; + } + + /* Allocate memory for the file */ + pBuff = (Cpa8U *)qaeMemAlloc(file_size); + if (NULL == pBuff) + { + PRINT_ERR("Could not allocate memory for the file copy\n"); + close(fd); + return CPA_STATUS_FAIL; + } + + memset(pBuff, 0, file_size); + /* Convert file descriptor to FILE* stream */ + srcFile = fdopen(fd, "r"); + if (NULL == srcFile) + { + PRINT_ERR("Could not create file stream for %s\n", filename); + qaeMemFree((void **)&pBuff); + close(fd); + return CPA_STATUS_FAIL; + } + + /* Read the file */ + *(file_data->bufferSize) = fread(pBuff, 1, file_size, srcFile); + if (*(file_data->bufferSize) != file_size) + { + PRINT_ERR("Filesize doesn't match\n"); + qaeMemFree((void **)&pBuff); + fclose(srcFile); + return CPA_STATUS_FAIL; + } + + /* fclose also closes the underlying file descriptor */ + fclose(srcFile); + *(file_data->pSrcData) = pBuff; + return CPA_STATUS_SUCCESS; +} + +/* Free the memory after getting the file and copying the data */ +CpaStatus sample_freeFile(file_data_t *file_data) +{ + qaeMemFree((void **)(file_data->pSrcData)); + return CPA_STATUS_SUCCESS; +} + +CpaStatus sample_getPath(char *filePath, char *fileName) +{ + Cpa32S strSize = 0; + + if (filePath == NULL || fileName == NULL) + { + PRINT_ERR("Invalid input: filePath or fileName is NULL\n"); + return CPA_STATUS_FAIL; + } + + memset(filePath, 0, MAX_CORPUS_FILE_PATH_LEN); + + strSize = snprintf(filePath, + MAX_CORPUS_FILE_PATH_LEN, + "%s%s", + SAMPLE_CODE_CORPUS_PATH, + fileName); + + if (strSize < 0 || strSize > MAX_CORPUS_FILE_PATH_LEN) + { + PRINT("Error creating file path, incorrect path length: %s\n", + filePath); + return CPA_STATUS_FAIL; + } + + if (access(filePath, F_OK) != 0) + { + PRINT("Could not open corpus file: %s\n", filePath); + return CPA_STATUS_FAIL; + } + + return CPA_STATUS_SUCCESS; +} + +#endif diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c index aa29c1d3..2a849de3 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample_user.c @@ -29,6 +29,7 @@ int gDebugParam = 1; int useHardCodedCrc = 1; int useXstorExtensions = 0; +extern CpaStatus dcChainXstorSample(void); extern CpaStatus dcChainSample(void); int main(int argc, const char **argv) @@ -55,6 +56,12 @@ int main(int argc, const char **argv) } PRINT_DBG("Starting Chaining Sample Code App ...\n"); + /* GEN 6 does not support xstore extensions */ + if (useXstorExtensions) + { + PRINT_ERR("Xstore extensions are not supported on this device\n"); + return CPA_STATUS_UNSUPPORTED; + } stat = qaeMemInit(); if (CPA_STATUS_SUCCESS != stat) @@ -82,6 +89,25 @@ int main(int argc, const char **argv) PRINT_DBG("\nLegacy DC Chaining Sample Code App finished\n"); } + /* Xstor DC Chaining Sample Code */ + stat = dcChainXstorSample(); + if (CPA_STATUS_SUCCESS != stat) + { + if (CPA_STATUS_UNSUPPORTED == stat) + { + PRINT_ERR("\nXstor DC Chaining Sample Code App unsupported\n"); + stat = CPA_STATUS_SUCCESS; + } + else + { + PRINT_ERR("\nXstor DC Chaining Sample Code App failed\n"); + } + } + else + { + PRINT_DBG("\nXstor DC Chaining Sample Code App finished\n"); + } + icp_sal_userStop(); qaeMemDestroy(); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c new file mode 100644 index 00000000..af487191 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_xstor_sample.c @@ -0,0 +1,1305 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ + +/* + * This is sample code that demonstrates usage of the dc chain API, + * and specifically using this API to perform hash plus compression chain + * operation. + */ + +#include "cpa.h" +#include "cpa_cy_sym.h" +#include "cpa_dc.h" +#include "cpa_dc_chain.h" +#include "cpa_sample_utils.h" + +/* SAL hardcoded CRC parameters. Used in verification flow + * when useHardCodedCrc is enabled + * 0x42f0e1eba9ea3693ULL - polynomial + * 0x0ULL - initialValue + * 0x0 - reflectIn + * 0x0 - reflectOut + * 0x0ULL - xorOut + */ +#define HC_KEYCONTEXT_CRC64 0x8c051c844b2ac92aULL +#define HC_DC_COMPRESS_CRC64 0xbbdaff3b554c96fcULL +#define HC_SRC_INPUT_CRC64 0x18bea8299f01f41cULL + +#define PC_KEYCONTEXT_CRC64 0x3561d50aef618effULL +#define PC_DC_COMPRESS_CRC64 0x57d08bac40e1127eULL +#define PC_SRC_INPUT_CRC64 0x47dc490fc9c462dbULL + +/* Programmable CRC parameters to use */ +static CpaCrcControlData progCrcControlData = { + /**< polynomial */ + 0x239c9357ac3eccd3ULL, + /**< initialValue */ + 0x6386926455673254ULL, + /**< reflectIn */ + 0x1, + /**< reflectOut */ + 0x1, + /**< xorOut */ + 0x9465776698231213ULL +}; + +extern int gDebugParam; +extern int useHardCodedCrc; +extern int useXstorExtensions; + +/* Size in bytes of the crc appended to the compressed image */ +#define DC_APPEND_CRC_SIZE_IN_BYTES (8) + +#define SAMPLE_MAX_BUFF (1024) +#define TIMEOUT_MS (5000) /* 5 seconds */ +#define NUM_SESSIONS_TWO (2) + +/* Used by ZLIB */ +#define DEFLATE_DEF_WINBITS (15) + +#define TAG_LENGTH (16) +#define AES_BLOCK_SIZE (16) + +/* Key Context structure definitions */ +#define QATZIP_GCM_IV_SIZE_IN_BYTES (12) +#define QZ_KDF_INPUT_SIZE_IN_BYTES (128) + +/* Maximum number of possible byte values */ +#define MAX_NUM_BYTE_VALUES (256) + +typedef enum Qz_SHASz_E +{ + QZ_SHA1_128 = 128, + QZ_SHA2_256 = 256, + QZ_SHA2_512 = 512 +} QzSHASz_T; + +typedef struct QzKDFIn_S +{ + Cpa8U derive; + /**< flag for keymaterial or key */ + Cpa8U keyMaterial[(QZ_SHA2_256 / 8) + QZ_KDF_INPUT_SIZE_IN_BYTES]; + /**< concatenation of keyin and (n,label,0x00,context,hash_sz) + * < hash_sz represents the number of bytes produced with the + * < hmac hash operation. Currently, only QZ_SHA2_256 is supported */ + Cpa8U keyinLen; + /**< length of keyin octets */ + Cpa8U concatLen; + /**< length of ((n,label,0x00,context,hmac_sz) + * < Note: concateLen does not include the length of the input key */ +} QzKDFIn_T; + +typedef struct QzStor2KM_S +{ + QzKDFIn_T p_km1; + /**< Key material */ + QzKDFIn_T p_km2; + /**< not used if verify = 0 */ + Cpa8U p_iv[QATZIP_GCM_IV_SIZE_IN_BYTES]; + /**< IV */ +} QzStor2KM_T; + +/* Key context structure which contains 2 key materials (p_km1/p_km2) */ +static QzStor2KM_T sampleKeyContext = { + { 0x01, + { 0x3a, 0x68, 0x2c, 0x3a, 0x5d, 0xd2, 0xcb, 0xc1, 0x38, 0x31, 0xb9, 0xfe, + 0x80, 0xb2, 0x61, 0xd0, 0x61, 0x6b, 0xc4, 0x22, 0x1d, 0x74, 0xc7, 0xa9, + 0x25, 0x09, 0x84, 0xeb, 0x53, 0x73, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, + 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }, + 0x20, + 0x1e }, + { 0x01, + { 0x3a, 0x68, 0x2c, 0x3a, 0x5d, 0xd2, 0xcb, 0xc1, 0x38, 0x31, 0xb9, 0xfe, + 0x80, 0xb2, 0x61, 0xd0, 0x61, 0x6b, 0xc4, 0x22, 0x1d, 0x74, 0xc7, 0xa9, + 0x25, 0x09, 0x84, 0xeb, 0x53, 0x73, 0x01, 0x07, 0x00, 0x00, 0x00, 0x01, + 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 }, + 0x20, + 0x1e }, + { 0x52, 0x9b, 0xfd, 0x2a, 0xbb, 0xb3, 0xbb, 0x64, 0x8f, 0x9f, 0x43, 0xf9 } +}; + +static Cpa8U sampleAddAuthData[] = { 0xde, 0xad, 0xde, 0xad, 0xde, 0xad, 0xde, + 0xad, 0xde, 0xad, 0xde, 0xad, 0xde, 0xad, + 0xde, 0xad, 0xde, 0xad, 0xde, 0xad }; + +static Cpa8U samplePayload[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0xEF, 0xEF, 0xEF, 0x34, 0x53, 0x84, 0x68, 0x76, 0x34, 0x65, 0x36, + 0x45, 0x64, 0xab, 0xd5, 0x27, 0x4a, 0xcb, 0xbb, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xEF, 0xEF, 0xEF, + 0x34, 0x53, 0x84, 0x68, 0x76, 0x34, 0x65, 0x36, 0x45, 0x64, 0xab, 0xd5, + 0x27, 0x4a, 0xcb, 0xbb, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x08, 0x09, 0xEF, 0xEF, 0xEF, 0x34, 0x53, 0x84, 0x68, + 0x76, 0x34, 0x65, 0x36, 0x45, 0x64, 0xab, 0xd5, 0x27, 0x4a, 0xcb, 0xbb, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, + 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xDE, 0xAD, 0xEE, 0xEE, + 0xDE, 0xAD, 0xBB, 0xBF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0xEF, 0xEF, 0xEF, 0x34, 0x53, 0x84, 0x68, 0x76, 0x34, 0x65, 0x36, + 0x45, 0x64, 0xab, 0xd5, 0x27, 0x4A, 0xCB, 0xBB +}; + +/* AES key, 256 bits long. Derived from the above sampleKeyContext */ +static Cpa8U ctxSampleKey[] = { + 0x09, 0x96, 0xb0, 0xda, 0x0e, 0xac, 0xbe, 0x73, 0x7d, 0x2e, 0xaf, + 0xa5, 0x88, 0x95, 0x05, 0xca, 0x64, 0xb4, 0x66, 0x57, 0xcb, 0xe1, + 0xdf, 0x14, 0xd4, 0x71, 0x03, 0xbe, 0x1b, 0xc4, 0x7f, 0x7a +}; + +/* IV contained in the above sampleKeyContext */ +static Cpa8U ctxSampleIv[] = { 0x52, 0x9b, 0xfd, 0x2a, 0xbb, 0xb3, + 0xbb, 0x64, 0x8f, 0x9f, 0x43, 0xf9 }; + +static Cpa32U cipherSizeInBytes = 0; + +static void dcChainFreeBufferList(CpaBufferList **testBufferList); + +/* Copy multiple buffers data in buffer lists to flat buffer */ +static void copyMultiFlatBufferToBuffer(CpaBufferList *pBufferListSrc, + Cpa8U *pBufferDst) +{ + int i = 0; + int offset = 0; + CpaFlatBuffer *pBuffers = pBufferListSrc->pBuffers; + + for (; i < pBufferListSrc->numBuffers; i++) + { + memcpy(pBufferDst + offset, pBuffers->pData, pBuffers->dataLenInBytes); + offset += pBuffers->dataLenInBytes; + pBuffers++; + } +} + +/* + * Callback function + * + * This function is "called back" (invoked by the implementation of + * the API) when the asynchronous operation has completed. The + * context in which it is invoked depends on the implementation, but + * as described in the API it should not sleep (since it may be called + * in a context which does not permit sleeping, e.g. a Linux bottom + * half). + * + * This function can perform whatever processing is appropriate to the + * application. For example, it may free memory, continue processing + * of a packet, etc. In this example, the function only sets the + * complete variable to indicate it has been called. + */ +// +static void dcCallback(void *pCallbackTag, CpaStatus status) +{ + PRINT_DBG("Callback called with status = %d.\n", status); + + if (NULL != pCallbackTag) + { + /* indicate that the function has been called */ + COMPLETE((struct COMPLETION_STRUCT *)pCallbackTag); + } +} +// + +/* Build dc chain buffer lists */ +static CpaStatus dcChainBuildBufferList(CpaBufferList **testBufferList, + Cpa32U numBuffers, + Cpa32U bufferSize, + Cpa32U bufferMetaSize) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaBufferList *pBuffList = NULL; + CpaFlatBuffer *pFlatBuff = NULL; + Cpa32U curBuff = 0; + Cpa8U *pMsg = NULL; + /* + * allocate memory for bufferlist and array of flat buffers in a contiguous + * area and carve it up to reduce number of memory allocations required. + */ + Cpa32U bufferListMemSize = + sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer)); + + status = OS_MALLOC(&pBuffList, bufferListMemSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error in allocating pBuffList\n"); + return CPA_STATUS_FAIL; + } + + pBuffList->numBuffers = numBuffers; + + if (bufferMetaSize) + { + status = + PHYS_CONTIG_ALLOC(&pBuffList->pPrivateMetaData, bufferMetaSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error in allocating pBuffList->pPrivateMetaData\n"); + OS_FREE(pBuffList); + return CPA_STATUS_FAIL; + } + } + else + { + pBuffList->pPrivateMetaData = NULL; + } + + pFlatBuff = (CpaFlatBuffer *)(pBuffList + 1); + pBuffList->pBuffers = pFlatBuff; + + while (curBuff < numBuffers) + { + if (0 != bufferSize) + { + status = PHYS_CONTIG_ALLOC(&pMsg, bufferSize); + if (CPA_STATUS_SUCCESS != status || NULL == pMsg) + { + PRINT_ERR("Error in allocating pMsg\n"); + dcChainFreeBufferList(&pBuffList); + return CPA_STATUS_FAIL; + } + memset(pMsg, 0, bufferSize); + pFlatBuff->pData = pMsg; + } + else + { + pFlatBuff->pData = NULL; + } + pFlatBuff->dataLenInBytes = bufferSize; + pFlatBuff++; + curBuff++; + } + + *testBufferList = pBuffList; + + return CPA_STATUS_SUCCESS; +} + +/* Free dc chain buffer lists */ +static void dcChainFreeBufferList(CpaBufferList **testBufferList) +{ + CpaBufferList *pBuffList = *testBufferList; + CpaFlatBuffer *pFlatBuff = NULL; + Cpa32U curBuff = 0; + + if (NULL == pBuffList) + { + PRINT_ERR("testBufferList is NULL\n"); + return; + } + + pFlatBuff = pBuffList->pBuffers; + while (curBuff < pBuffList->numBuffers) + { + if (NULL != pFlatBuff->pData) + { + PHYS_CONTIG_FREE(pFlatBuff->pData); + pFlatBuff->pData = NULL; + } + pFlatBuff++; + curBuff++; + } + + if (NULL != pBuffList->pPrivateMetaData) + { + PHYS_CONTIG_FREE(pBuffList->pPrivateMetaData); + pBuffList->pPrivateMetaData = NULL; + } + + OS_FREE(pBuffList); + *testBufferList = NULL; +} + +/* + * This function performs a software verification of the QAT HW Chain Operation. + */ +static CpaStatus dcChainingVerify(void *pSrcBuffer, + Cpa32U srcBufferSize, + void *pExpectedBuffer, + Cpa32U expectedBufferSize, + CpaBoolean appendedCrc, + CpaBoolean verifyKeyContext, + CpaDcChainRqVResults *chainResult, + CpaDcChainOpData2 *pChainOpData2, + CpaCrcData *pCrcDataBuffer) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa64U keyContextCrc; + Cpa64U srcInputCrc; + if (useHardCodedCrc) + { + keyContextCrc = HC_KEYCONTEXT_CRC64; + srcInputCrc = HC_SRC_INPUT_CRC64; + } + else + { + keyContextCrc = PC_KEYCONTEXT_CRC64; + srcInputCrc = PC_SRC_INPUT_CRC64; + } + + if (verifyKeyContext && (keyContextCrc != chainResult->ctxCrc64)) + { + PRINT_ERR("pKeyContext: 0x%lx Expected CRC64: 0x%lx\n", + chainResult->ctxCrc64, + keyContextCrc); + status = CPA_STATUS_FAIL; + } + + if (CPA_STATUS_SUCCESS == status) + { + if (pChainOpData2->operation == CPA_DC_CHAIN_COMPRESS_THEN_AEAD) + { + if (appendedCrc) + { + /* Check that CRC64 appended to the image matches + * expected image CRC64 */ + if (srcInputCrc != chainResult->iDcCrc64) + { + status = CPA_STATUS_FAIL; + PRINT_ERR("iDcCrc64: 0x%lx Expected CRC64: " + "0x%lx\n", + chainResult->iDcCrc64, + srcInputCrc); + } + } + + if (srcInputCrc != pCrcDataBuffer->integrityCrc64b.iCrc) + { + PRINT_ERR("pCrcDataBuffer->integrityCrc64b.iCrc: 0x%lx " + "Expected CRC64: 0x%lx\n", + pCrcDataBuffer->integrityCrc64b.iCrc, + srcInputCrc); + status = CPA_STATUS_FAIL; + } + } + else + { + /* Compare Cleartext sample buffer with QAT HW decrypt/decompress + * buffer + */ + if (memcmp(pSrcBuffer, pExpectedBuffer, expectedBufferSize)) + { + status = CPA_STATUS_FAIL; + PRINT_ERR("Hardware decrypt/decompress buffer does not match " + "source buffer\n"); + } + else + { + if (appendedCrc && + (chainResult->storedCrc64 != chainResult->oDcCrc64)) + { + status = CPA_STATUS_FAIL; + PRINT_ERR("Stored CRC64: 0x%lx Expected CRC64: 0x%lx\n", + chainResult->storedCrc64, + chainResult->oDcCrc64); + } + else + { + PRINT_DBG( + "Hardware decrypt/decompress buffer matches source " + "buffer\n"); + } + } + } + } + return status; +} +/* + * This function performs a dc chain operation. + */ +static CpaStatus dcChainingPerformOp(CpaInstanceHandle dcInstHandle, + CpaDcSessionHandle sessionHdl, + CpaDcChainOperations operation, + void *pSrcBuffer, + Cpa32U srcBufferSize, + void *pDstBuffer, + Cpa32U dstBufferSize, + Cpa32U intermediateBufferSize, + Cpa8U *pDigestBuffer, + CpaBoolean testIntegrity) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U bufferMetaSize = 0; + CpaBufferList *pBufferListSrc = NULL; + CpaBufferList *pBufferListDst = NULL; + CpaBufferList *pBufferListIntermediate = NULL; + CpaFlatBuffer *pFlatBuffer = NULL; + Cpa32U numBuffers = 1; + CpaDcChainSubOpData2 chainOpData[2] = { { 0 }, { 0 } }; + CpaDcOpData2 dcOpData2 = { 0 }; + CpaCySymOpData2 cySymOpData2 = { 0 }; + CpaDcChainRqVResults chainResult = { 0 }; + Cpa8U numSessions = NUM_SESSIONS_TWO; + struct COMPLETION_STRUCT complete; + Cpa32U aadBuffSize = 0; + Cpa8U *pAadBuffer = NULL; + CpaDcChainOpData2 dcChainOpData2; + Cpa8U *pContextBuffer = NULL; + CpaCrcData *pCrcDataBuffer = NULL; + CpaBoolean appendedCrc = CPA_FALSE; + Cpa8U *pIvBuffer = NULL; + CpaBoolean verifyKeyContext = CPA_FALSE; + + PRINT_DBG("cpaDcBufferListGetMetaSize\n"); + + /* + * Different implementations of the API require different + * amounts of space to store meta-data associated with buffer + * lists. We query the API to find out how much space the current + * implementation needs, and then allocate space for the buffer + * meta data, the buffer list, and for the buffer itself. + */ + // + status = + cpaDcBufferListGetMetaSize(dcInstHandle, numBuffers, &bufferMetaSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error get meta size\n"); + return CPA_STATUS_FAIL; + } + + if (CPA_STATUS_SUCCESS == status) + { + status = dcChainBuildBufferList( + &pBufferListSrc, numBuffers, srcBufferSize, bufferMetaSize); + } + + /* copy source data into buffer */ + if (CPA_STATUS_SUCCESS == status) + { + pFlatBuffer = (CpaFlatBuffer *)(pBufferListSrc + 1); + memcpy(pFlatBuffer->pData, pSrcBuffer, srcBufferSize); + } + + /* Allocate destination buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = dcChainBuildBufferList( + &pBufferListDst, numBuffers, dstBufferSize, bufferMetaSize); + } + + /* Create an intermediate buffer to be used as an internal staging area + * for chain operations. The size of this buffer must match the size of + * the destination buffer used for the crypto part of the DC Chain. + */ + if (CPA_STATUS_SUCCESS == status) + { + status = dcChainBuildBufferList(&pBufferListIntermediate, + numBuffers, + intermediateBufferSize, + bufferMetaSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate memory for AAD. For GCM this memory will hold the + * additional authentication data and any padding to ensure total + * size is a multiple of the AES block size + */ + aadBuffSize = sizeof(sampleAddAuthData); + if (aadBuffSize % AES_BLOCK_SIZE) + { + aadBuffSize += AES_BLOCK_SIZE - (aadBuffSize % AES_BLOCK_SIZE); + } + status = PHYS_CONTIG_ALLOC(&pAadBuffer, aadBuffSize); + + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pAadBuffer, sampleAddAuthData, sizeof(sampleAddAuthData)); + } + } + + /* Create the key context buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pContextBuffer, sizeof(sampleKeyContext)); + + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pContextBuffer, &sampleKeyContext, sizeof(sampleKeyContext)); + } + } + + if (!useXstorExtensions) + { + /* Create the IV buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pIvBuffer, AES_BLOCK_SIZE); + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pIvBuffer, ctxSampleIv, sizeof(ctxSampleIv)); + } + } + } + + /* Create the E2E CRC data structure */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pCrcDataBuffer, sizeof(CpaCrcData)); + + if (CPA_STATUS_SUCCESS == status) + { + memset(pCrcDataBuffer, 0, sizeof(CpaCrcData)); + } + } + + // + if (CPA_STATUS_SUCCESS == status) + { + dcOpData2.dcOpData.flushFlag = CPA_DC_FLUSH_FINAL; + dcOpData2.dcOpData.compressAndVerify = CPA_TRUE; + dcOpData2.dcOpData.compressAndVerifyAndRecover = CPA_FALSE; + dcOpData2.dcOpData.integrityCrcCheck = CPA_TRUE; + dcOpData2.dcOpData.verifyHwIntegrityCrcs = CPA_FALSE; + dcOpData2.dcOpData.pCrcData = pCrcDataBuffer; + if (useXstorExtensions) + { + dcOpData2.appendCRC64 = CPA_TRUE; + } + else + { + dcOpData2.appendCRC64 = CPA_FALSE; + } + cySymOpData2.symOpData.packetType = CPA_CY_SYM_PACKET_TYPE_FULL; + cySymOpData2.symOpData.cryptoStartSrcOffsetInBytes = 0; + cySymOpData2.symOpData.messageLenToCipherInBytes = cipherSizeInBytes; + cySymOpData2.symOpData.pAdditionalAuthData = pAadBuffer; + cySymOpData2.symOpData.pDigestResult = pDigestBuffer; + if (useXstorExtensions) + { + cySymOpData2.symOpData.pIv = NULL; + cySymOpData2.symOpData.ivLenInBytes = 0; + cySymOpData2.deriveCtxData.pContext = pContextBuffer; + cySymOpData2.deriveCtxData.contextLen = sizeof(sampleKeyContext); + } + else + { + cySymOpData2.symOpData.pIv = pIvBuffer; + cySymOpData2.symOpData.ivLenInBytes = sizeof(ctxSampleIv); + cySymOpData2.deriveCtxData.pContext = NULL; + cySymOpData2.deriveCtxData.contextLen = 0; + } + + /* copy source into buffer */ + if (CPA_DC_CHAIN_COMPRESS_THEN_AEAD == operation) + { + /* Set chaining operation data */ + chainOpData[0].opType = CPA_DC_CHAIN_COMPRESS_DECOMPRESS; + chainOpData[0].pDcOp2 = &dcOpData2; + chainOpData[1].opType = CPA_DC_CHAIN_SYMMETRIC_CRYPTO; + chainOpData[1].pCySymOp2 = &cySymOpData2; + } + else + { + /* Set chaining operation data */ + chainOpData[0].opType = CPA_DC_CHAIN_SYMMETRIC_CRYPTO; + chainOpData[0].pCySymOp2 = &cySymOpData2; + chainOpData[1].opType = CPA_DC_CHAIN_COMPRESS_DECOMPRESS; + chainOpData[1].pDcOp2 = &dcOpData2; + } + + /* + * Now, we initialize the completion variable which is used by the + * callback function to indicate that the operation is complete. + * We then perform the operation. + */ + // + COMPLETION_INIT(&complete); + if (useXstorExtensions && testIntegrity) + { + dcChainOpData2.testIntegrity = CPA_TRUE; + } + else + { + dcChainOpData2.testIntegrity = CPA_FALSE; + } + + dcChainOpData2.operation = operation; + dcChainOpData2.numOpDatas = numSessions; + dcChainOpData2.pChainOpData = chainOpData; + status = cpaDcChainPerformOp2(dcInstHandle, + sessionHdl, + pBufferListSrc, + pBufferListDst, + pBufferListIntermediate, + dcChainOpData2, + &chainResult, + (void *)&complete); + // + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcChainPerformOp2 failed. (status = %d)\n", status); + } + + /* + * We now wait until the completion of the operation. This uses a macro + * which can be defined differently for different OSes. + */ + if (CPA_STATUS_SUCCESS == status) + { + if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) + { + PRINT_ERR("timeout or interruption in cpaDcChainPerformOp2\n"); + status = CPA_STATUS_FAIL; + } + } + } + + /* + * We now check the results + */ + if (CPA_STATUS_SUCCESS == status) + { + if (chainResult.chainStatus != CPA_DC_OK) + { + PRINT_ERR( + "Results chainStatus not as expected (chainStatus = %d)\n", + chainResult.chainStatus); + status = CPA_STATUS_FAIL; + } + else if (chainResult.chainRqResults.dcStatus != CPA_DC_OK) + { + PRINT_ERR("Results dcStatus not as expected (dcStatus = %d)\n", + chainResult.chainRqResults.dcStatus); + status = CPA_STATUS_FAIL; + } + else if (chainResult.chainRqResults.cyStatus != CPA_DC_OK) + { + PRINT_ERR("Results cyStatus not as expected (cyStatus = %d)\n", + chainResult.chainRqResults.cyStatus); + status = CPA_STATUS_FAIL; + } + else + { + PRINT_DBG("Data consumed %d\n", + chainResult.chainRqResults.consumed); + PRINT_DBG("Data produced %d\n", + chainResult.chainRqResults.produced); + PRINT_DBG("Adler32 checksum 0x%x\n", + chainResult.chainRqResults.adler32); + PRINT_DBG("Crc32 checksum 0x%x\n", + chainResult.chainRqResults.crc32); + + PRINT_DBG("pCrcDataBuffer->crc32 0x%x\n", pCrcDataBuffer->crc32); + PRINT_DBG("pCrcDataBuffer->adler32 0x%x\n", + pCrcDataBuffer->adler32); + PRINT_DBG("pCrcDataBuffer->integrityCrc64b.iCrc 0x%lx\n", + pCrcDataBuffer->integrityCrc64b.iCrc); + PRINT_DBG("pCrcDataBuffer->integrityCrc64b.oCrc 0x%lx\n", + pCrcDataBuffer->integrityCrc64b.oCrc); + + PRINT_DBG("chainResult.storedCrc64 0x%lx\n", + chainResult.storedCrc64); + PRINT_DBG("chainResult.iDcCrc64 0x%lx\n", chainResult.iDcCrc64); + PRINT_DBG("chainResult.oDcCrc64 0x%lx\n", chainResult.oDcCrc64); + PRINT_DBG("chainResult.ctxCrc64 0x%lx\n", chainResult.ctxCrc64); + } + } + + /* Use zlib to decompress and verify integrity */ + // + if (CPA_STATUS_SUCCESS == status) + { + Cpa32U srcBufferLength = 0; + Cpa32U dstBufferLength = 0; + + /* Allow for CRC64 if appended to the compressed data */ + if (dcOpData2.appendCRC64) + { + appendedCrc = CPA_TRUE; + dstBufferLength = chainResult.chainRqResults.produced + + DC_APPEND_CRC_SIZE_IN_BYTES; + } + else + { + dstBufferLength = chainResult.chainRqResults.produced; + } + + copyMultiFlatBufferToBuffer(pBufferListDst, pDstBuffer); + + /* Verify Key Context if provided */ + if ((NULL != cySymOpData2.deriveCtxData.pContext) && + (0 != cySymOpData2.deriveCtxData.contextLen)) + { + verifyKeyContext = CPA_TRUE; + } + + if (CPA_DC_CHAIN_COMPRESS_THEN_AEAD == operation) + { + srcBufferLength = pBufferListSrc->numBuffers * + pBufferListSrc->pBuffers->dataLenInBytes; + cipherSizeInBytes = dstBufferLength; + status = dcChainingVerify(pDstBuffer, + dstBufferLength, + pSrcBuffer, + srcBufferLength, + appendedCrc, + verifyKeyContext, + &chainResult, + &dcChainOpData2, + pCrcDataBuffer); + } + else if (CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS == operation) + { + status = dcChainingVerify(pDstBuffer, + dstBufferLength, + samplePayload, + sizeof(samplePayload), + appendedCrc, + verifyKeyContext, + &chainResult, + &dcChainOpData2, + pCrcDataBuffer); + } + } + // + + /* + * At this stage, the callback function has returned, so it is + * sure that the structures won't be needed any more. Free the + * memory! + */ + PHYS_CONTIG_FREE(pAadBuffer); + PHYS_CONTIG_FREE(pContextBuffer); + if (!useXstorExtensions) + { + PHYS_CONTIG_FREE(pIvBuffer); + } + PHYS_CONTIG_FREE(pCrcDataBuffer); + COMPLETION_DESTROY(&complete); + dcChainFreeBufferList(&pBufferListSrc); + dcChainFreeBufferList(&pBufferListDst); + dcChainFreeBufferList(&pBufferListIntermediate); + return status; +} + +/* + * This is the main entry point for the sample data dc chain code. + * demonstrates the sequence of calls to be made to the API in order + * to create a session, perform one or more hash plus compression operations, + * and + * then tear down the session. + */ +CpaStatus dcChainXstorSample(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceHandle dcInstHandle = NULL; + CpaDcSessionHandle sessionHdl = NULL; + CpaDcChainSessionSetupData chainSessionData[2] = { { 0 }, { 0 } }; + CpaDcSessionSetupData dcSessionData = { 0 }; + CpaCySymSessionSetupData cySessionData = { 0 }; + Cpa32U sess_size = 0; + CpaDcStats dcStats = { 0 }; + CpaDcInstanceCapabilities cap = { 0 }; + Cpa32U buffMetaSize = 0; + Cpa16U numInterBuffLists = 0; + CpaBufferList **bufferInterArray = NULL; + Cpa16U bufferNum = 0; + CpaStatus chainOperation = CPA_STATUS_FAIL; + void *pSrcBuffer = samplePayload; + Cpa32U srcBufferSize = sizeof(samplePayload); + void *pCompEncryptBuffer = NULL; + Cpa32U compEncryptBufferSize = 0; + void *pDecryptDecompBuffer = NULL; + Cpa32U decryptDecompBufferSize = 0; + cipherSizeInBytes = 0; + Cpa8U *pDigestBuffer = NULL; + + /* + * In this simplified version of instance discovery, we discover + * exactly one instance of a data compression service. + */ + sampleDcGetInstance(&dcInstHandle); + if (dcInstHandle == NULL) + { + PRINT_ERR("Get instance failed\n"); + return CPA_STATUS_FAIL; + } + + /* Query Capabilities */ + PRINT_DBG("cpaDcQueryCapabilities\n"); + // + status = cpaDcQueryCapabilities(dcInstHandle, &cap); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Query capabilities failed\n"); + return status; + } + + if (CPA_FALSE == CPA_BITMAP_BIT_TEST(cap.dcChainCapInfo, + CPA_DC_CHAIN_COMPRESS_THEN_AEAD)) + { + PRINT_ERR("Compress then Encrypt(AEAD) chained operation is not " + "supported on logical " + "instance: 0x%8x.\n", + cap.dcChainCapInfo[0]); + return CPA_STATUS_UNSUPPORTED; + } + + if (CPA_FALSE == CPA_BITMAP_BIT_TEST(cap.dcChainCapInfo, + CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS)) + { + PRINT_ERR("Decrypt(AEAD) then Decompress chained operation is not " + "supported on logical " + "instance: 0x%8x.\n", + cap.dcChainCapInfo[0]); + return CPA_STATUS_UNSUPPORTED; + } + + if (!cap.statelessDeflateCompression || !cap.dynamicHuffman) + { + PRINT_ERR("Error: Unsupported functionality\n"); + return CPA_STATUS_FAIL; + } + + /* Note : for QAT2.x, The below block won't get executed. + * For QAT2.x, intermediate buffers are not required, + * Hence cpaDcGetNumIntermediateBuffers() will return 0 */ + if (cap.dynamicHuffmanBufferReq) + { + status = cpaDcBufferListGetMetaSize(dcInstHandle, 1, &buffMetaSize); + + if (CPA_STATUS_SUCCESS == status) + { + status = cpaDcGetNumIntermediateBuffers(dcInstHandle, + &numInterBuffLists); + } + if (CPA_STATUS_SUCCESS == status && 0 != numInterBuffLists) + { + status = PHYS_CONTIG_ALLOC( + &bufferInterArray, numInterBuffLists * sizeof(CpaBufferList *)); + } + for (bufferNum = 0; bufferNum < numInterBuffLists; bufferNum++) + { + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&bufferInterArray[bufferNum], + sizeof(CpaBufferList)); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC( + &bufferInterArray[bufferNum]->pPrivateMetaData, + buffMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = + PHYS_CONTIG_ALLOC(&bufferInterArray[bufferNum]->pBuffers, + sizeof(CpaFlatBuffer)); + } + if (CPA_STATUS_SUCCESS == status) + { + /* Implementation requires an intermediate buffer approximately + twice the size of the output buffer */ + status = PHYS_CONTIG_ALLOC( + &bufferInterArray[bufferNum]->pBuffers->pData, + 2 * SAMPLE_MAX_BUFF); + bufferInterArray[bufferNum]->numBuffers = 1; + bufferInterArray[bufferNum]->pBuffers->dataLenInBytes = + 2 * SAMPLE_MAX_BUFF; + } + + } /* End numInterBuffLists */ + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Set the address translation function for the instance */ + status = cpaDcSetAddressTranslation(dcInstHandle, sampleVirtToPhys); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Start static data compression component */ + PRINT_DBG("cpaDcStartInstance\n"); + status = cpaDcStartInstance( + dcInstHandle, numInterBuffLists, bufferInterArray); + } + // + + if (CPA_STATUS_SUCCESS == status) + { + /* + * If the instance is polled start the polling thread. Note that + * how the polling is done is implementation-dependent. + */ + sampleDcStartPolling(dcInstHandle); + /* + * We now populate the fields of the session operational data and create + * the session. Note that the size required to store a session is + * implementation-dependent, so we query the API first to determine how + * much memory to allocate, and then allocate that memory. + */ + PRINT_DBG("DC Chain Operation: Compress(DEFLATE) then Encrypt (AES256 " + "GCM)\n"); + + // + /* Initialize compression session data */ + dcSessionData.compLevel = CPA_DC_L1; + dcSessionData.compType = CPA_DC_DEFLATE; + dcSessionData.huffType = CPA_DC_HT_FULL_DYNAMIC; + dcSessionData.autoSelectBestHuffmanTree = CPA_DC_ASB_DISABLED; + dcSessionData.sessDirection = CPA_DC_DIR_COMPRESS; + dcSessionData.sessState = CPA_DC_STATELESS; + dcSessionData.checksum = CPA_DC_CRC32; + + /* Initialize crypto session data */ + cySessionData.sessionPriority = CPA_CY_PRIORITY_NORMAL; + cySessionData.symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; + cySessionData.algChainOrder = + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH; + cySessionData.cipherSetupData.cipherAlgorithm = + CPA_CY_SYM_CIPHER_AES_GCM; + if (useXstorExtensions) + { + cySessionData.cipherSetupData.pCipherKey = NULL; + cySessionData.cipherSetupData.cipherKeyLenInBytes = 0; + } + else + { + cySessionData.cipherSetupData.pCipherKey = ctxSampleKey; + cySessionData.cipherSetupData.cipherKeyLenInBytes = + sizeof(ctxSampleKey); + } + cySessionData.cipherSetupData.cipherDirection = + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT; + + cySessionData.hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_AES_GCM; + cySessionData.hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_AUTH; + cySessionData.hashSetupData.digestResultLenInBytes = TAG_LENGTH; + /* For GCM authKey and authKeyLen are not required this information + is provided by the cipherKey in cipherSetupData */ + cySessionData.hashSetupData.authModeSetupData.aadLenInBytes = + sizeof(sampleAddAuthData); + cySessionData.digestIsAppended = CPA_FALSE; + /* digestVerify is not required to be set. For GCM authenticated + encryption this value is understood to be CPA_FALSE */ + + /* Initialize chaining session data - compress + encrypt + * chain operation */ + chainSessionData[0].sessType = CPA_DC_CHAIN_COMPRESS_DECOMPRESS; + chainSessionData[0].pDcSetupData = &dcSessionData; + chainSessionData[1].sessType = CPA_DC_CHAIN_SYMMETRIC_CRYPTO; + chainSessionData[1].pCySetupData = &cySessionData; + + /* Determine size of session context to allocate */ + PRINT_DBG("cpaDcChainGetSessionSize\n"); + status = cpaDcChainGetSessionSize(dcInstHandle, + CPA_DC_CHAIN_COMPRESS_THEN_AEAD, + NUM_SESSIONS_TWO, + chainSessionData, + &sess_size); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate session memory */ + status = PHYS_CONTIG_ALLOC(&sessionHdl, sess_size); + } + + /* Initialize the chaining session */ + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("cpaDcChainInitSession\n"); + status = cpaDcChainInitSession(dcInstHandle, + sessionHdl, + CPA_DC_CHAIN_COMPRESS_THEN_AEAD, + NUM_SESSIONS_TWO, + chainSessionData, + dcCallback); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Initialize the CRC parameters if using programmable CRC feature */ + if (!useHardCodedCrc) + { + status = cpaDcChainSetCrcControlData( + dcInstHandle, sessionHdl, &progCrcControlData); + } + } + // + + if (CPA_STATUS_SUCCESS == status) + { + compEncryptBufferSize = (4 * srcBufferSize); + status = PHYS_CONTIG_ALLOC(&pCompEncryptBuffer, compEncryptBufferSize); + + /* Allocate digest result buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pDigestBuffer, TAG_LENGTH); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Perform chaining operation */ + chainOperation = + dcChainingPerformOp(dcInstHandle, + sessionHdl, + CPA_DC_CHAIN_COMPRESS_THEN_AEAD, + pSrcBuffer, + srcBufferSize, + pCompEncryptBuffer, + compEncryptBufferSize, + compEncryptBufferSize, + pDigestBuffer, + CPA_FALSE); + } + + if (CPA_STATUS_SUCCESS != chainOperation) + { + PRINT_ERR("dcChainingPerformOp (CPA_DC_CHAIN_COMPRESS_THEN_AEAD) " + "failed\n"); + } + /* + * In a typical usage, the session might be used to compression + * multiple buffers. In this example however, we can now + * tear down the session. + */ + PRINT_DBG("cpaDcChainRemoveSession\n"); + // + status = cpaDcChainRemoveSession(dcInstHandle, sessionHdl); + // + + if (CPA_STATUS_SUCCESS != chainOperation) + { + status = chainOperation; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("DC Chain Operation: Decrypt (AES256 GCM) then " + "Decompress(DEFLATE decompress)\n"); + + /* Initialize compression session data */ + dcSessionData.compType = CPA_DC_DEFLATE; + dcSessionData.sessDirection = CPA_DC_DIR_DECOMPRESS; + dcSessionData.sessState = CPA_DC_STATELESS; + dcSessionData.checksum = CPA_DC_CRC32; + + /* Initialize crypto session data */ + cySessionData.sessionPriority = CPA_CY_PRIORITY_NORMAL; + cySessionData.symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; + cySessionData.algChainOrder = + CPA_CY_SYM_ALG_CHAIN_ORDER_HASH_THEN_CIPHER; + cySessionData.cipherSetupData.cipherAlgorithm = + CPA_CY_SYM_CIPHER_AES_GCM; + if (useXstorExtensions) + { + cySessionData.cipherSetupData.pCipherKey = NULL; + cySessionData.cipherSetupData.cipherKeyLenInBytes = 0; + } + else + { + cySessionData.cipherSetupData.pCipherKey = ctxSampleKey; + cySessionData.cipherSetupData.cipherKeyLenInBytes = + sizeof(ctxSampleKey); + } + cySessionData.cipherSetupData.cipherDirection = + CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT; + + cySessionData.hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_AES_GCM; + cySessionData.hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_AUTH; + cySessionData.hashSetupData.digestResultLenInBytes = TAG_LENGTH; + /* For GCM authKey and authKeyLen are not required this information + is provided by the cipherKey in cipherSetupData */ + cySessionData.hashSetupData.authModeSetupData.aadLenInBytes = + sizeof(sampleAddAuthData); + cySessionData.digestIsAppended = CPA_FALSE; + /* digestVerify is not required to be set. For GCM authenticated + encryption this value is understood to be CPA_FALSE */ + + /* Initialize chaining session data - decrypt + decompress + * chain operation */ + chainSessionData[0].sessType = CPA_DC_CHAIN_SYMMETRIC_CRYPTO; + chainSessionData[0].pCySetupData = &cySessionData; + chainSessionData[1].sessType = CPA_DC_CHAIN_COMPRESS_DECOMPRESS; + chainSessionData[1].pDcSetupData = &dcSessionData; + + /* Initialize the chaining session */ + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("cpaDcChainInitSession\n"); + status = cpaDcChainInitSession(dcInstHandle, + sessionHdl, + CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS, + NUM_SESSIONS_TWO, + chainSessionData, + dcCallback); + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Initialize the CRC parameters if using programmable CRC feature */ + if (!useHardCodedCrc) + { + status = cpaDcChainSetCrcControlData( + dcInstHandle, sessionHdl, &progCrcControlData); + } + } + + if (CPA_STATUS_SUCCESS == status) + { + decryptDecompBufferSize = (4 * srcBufferSize); + status = + PHYS_CONTIG_ALLOC(&pDecryptDecompBuffer, decryptDecompBufferSize); + + if (CPA_STATUS_SUCCESS == status) + { + /* Perform chaining operation */ + chainOperation = + dcChainingPerformOp(dcInstHandle, + sessionHdl, + CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS, + pCompEncryptBuffer, + compEncryptBufferSize, + pDecryptDecompBuffer, + decryptDecompBufferSize, + compEncryptBufferSize, + pDigestBuffer, + CPA_FALSE); + } + + if (CPA_STATUS_SUCCESS != chainOperation) + { + PRINT_ERR("dcChainingPerformOp (CPA_DC_CHAIN_AEAD_THEN_DECOMPRESS) " + "failed\n"); + } + /* + * In a typical usage, the session might be used to compression + * multiple buffers. In this example however, we can now + * tear down the session. + */ + PRINT_DBG("cpaDcChainRemoveSession\n"); + // + status = cpaDcChainRemoveSession(dcInstHandle, sessionHdl); + // + + if (CPA_STATUS_SUCCESS != chainOperation) + { + status = chainOperation; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* + * We can now query the statistics on the instance. + * + * Note that some implementations may also make the stats + * available through other mechanisms, e.g. in the /proc + * virtual filesystem. + */ + status = cpaDcGetStats(dcInstHandle, &dcStats); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcGetStats failed, status = %d\n", status); + } + else + { + PRINT_DBG("Number of compression operations completed: %llu\n", + (unsigned long long)dcStats.numCompCompleted); + } + } + + /* + * Free up memory, stop the instance, etc. + */ + + /* Stop the polling thread */ + sampleDcStopPolling(); + + PRINT_DBG("cpaDcStopInstance\n"); + cpaDcStopInstance(dcInstHandle); + + /* Free output buffers used */ + PHYS_CONTIG_FREE(pCompEncryptBuffer); + PHYS_CONTIG_FREE(pDigestBuffer); + PHYS_CONTIG_FREE(pDecryptDecompBuffer); + + /* Free session Context */ + PHYS_CONTIG_FREE(sessionHdl); + + /* Free intermediate buffers */ + if (bufferInterArray != NULL) + { + for (bufferNum = 0; bufferNum < numInterBuffLists; bufferNum++) + { + PHYS_CONTIG_FREE(bufferInterArray[bufferNum]->pBuffers->pData); + PHYS_CONTIG_FREE(bufferInterArray[bufferNum]->pBuffers); + PHYS_CONTIG_FREE(bufferInterArray[bufferNum]->pPrivateMetaData); + PHYS_CONTIG_FREE(bufferInterArray[bufferNum]); + } + PHYS_CONTIG_FREE(bufferInterArray); + } + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Sample code ran successfully\n"); + } + else + { + PRINT_ERR("Sample code failed with status of %d\n", status); + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c new file mode 100644 index 00000000..7a54ecd5 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_sample_user_dict.c @@ -0,0 +1,80 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file cpa_dc_sample_user_dict.c + * + * To run this sample code : "./dc_stateless_sample_dict" + *****************************************************************************/ +#include "cpa_sample_utils.h" +#include "icp_sal_user.h" + +#define FILE_NAME_LENGTH 100 +int gDebugParam = 1; +char *gInputFileName = NULL; +char *gDictFileName = NULL; + +extern CpaStatus dcStatelessSampleDict(); + +int main(int argc, char **argv) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaStatus processStatus = CPA_STATUS_SUCCESS; + char inputFile[FILE_NAME_LENGTH] = "paper4"; + char dictFile[FILE_NAME_LENGTH] = "paper4.dict"; + + if (argc > 1) + { + gDebugParam = atoi(argv[1]); + } + + PRINT("Starting Stateless Dictionary Compression Sample Code App ...\n"); + + gInputFileName = inputFile; + gDictFileName = dictFile; + + status = qaeMemInit(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to initialise memory driver\n"); + return (int)status; + } + + status = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to start user process SSL\n"); + qaeMemDestroy(); + return (int)status; + } + + status = dcStatelessSampleDict(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("\nStateless Dict Compression Sample Code App failed\n"); + } + else + { + PRINT("\nStateless Dict Compression Sample Code App finished " + "successfully\n"); + } + + processStatus = icp_sal_userStop(); + if (CPA_STATUS_SUCCESS != processStatus) + { + PRINT_ERR("Failed to stop user process SSL\n"); + status = processStatus; + } + + qaeMemDestroy(); + + return (int)status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c new file mode 100644 index 00000000..779e4c33 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/cpa_dc_stateless_sample_dict.c @@ -0,0 +1,654 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ + +/* + * This is sample code that demonstrates usage of the data compression API, + * and specifically using this API to statelessly compress an input buffer. It + * will compress the data using dictionary compression operations with an + * algorithm. + */ + +#include "cpa_sample_utils.h" + +extern int gDebugParam; +extern char *gInputFileName; +extern char *gDictFileName; + +#define TIMEOUT_MS 5000 /* 5 seconds */ +#define SINGLE_INTER_BUFFLIST 1 + +/* + ***************************************************************************** + * Forward declaration + ***************************************************************************** + */ +CpaStatus dcStatelessSampleDict(); + +/* + * Callback function + * + * This function is "called back" (invoked by the implementation of + * the API) when the asynchronous operation has completed. The + * context in which it is invoked depends on the implementation, but + * as described in the API it should not sleep (since it may be called + * in a context which does not permit sleeping, e.g. a Linux bottom + * half). + * + * This function can perform whatever processing is appropriate to the + * application. For example, it may free memory, continue processing + * of a packet, etc. In this example, the function only sets the + * complete variable to indicate it has been called. + */ +// +static void dcCallback(void *pCallbackTag, CpaStatus status) +{ + PRINT_DBG("Callback called with status = %d.\n", status); + + if (NULL != pCallbackTag) + { + /* Indicate that the function has been called */ + COMPLETE((struct COMPLETION_STRUCT *)pCallbackTag); + } +} +// + +/* + * This function performs a compression and decompress operation. + */ +static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, + CpaDcSessionHandle sessionHdl) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa8U *pBufferMetaSrc = NULL; + Cpa8U *pBufferMetaDst = NULL; + Cpa8U *pBufferMetaDst2 = NULL; + Cpa32U bufferSrcMetaSize = 0; + Cpa32U bufferDstMetaSize = 0; + Cpa32U bufferSrc2MetaSize = 0; + CpaBufferList *pBufferListSrc = NULL; + CpaBufferList *pBufferListDst = NULL; + CpaBufferList *pBufferListDst2 = NULL; + CpaBufferList *pBufferListDict = NULL; + CpaFlatBuffer *pFlatBuffer = NULL; + CpaDcOpData opDataComp = {}; + Cpa32U numBuffers = 1; /* only using 1 buffer in this case */ + /* allocate memory for bufferlist and array of flat buffers in a contiguous + * area and carve it up to reduce number of memory allocations required. */ + Cpa32U numDictBuffers = 1; /* only using 1 dict buffer in this case */ + Cpa32U bufferListMemSize = + sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer)); + Cpa32U bufferSize = 0; + Cpa32U dictBufferSize = 0; + Cpa8U *pSrcBuffer = NULL; + Cpa8U *pDstBuffer = NULL; + Cpa8U *pDst2Buffer = NULL; + Cpa8U *pDictBuffer = NULL; + CpaDcRqResults dcResultsComp = { 0 }; + CpaDcRqResults dcResultsDecomp = { 0 }; + file_data_t dictData = { 0 }; + file_data_t inputData = { 0 }; + CpaFlatBuffer inputBuffer = { 0 }; + CpaDcDictionaryData dictionaryOpData = { 0 }; + CpaFlatBuffer dictionaryBuffer = { 0 }; + CpaCrcData compCrcData = { 0 }; + char filePath[MAX_CORPUS_FILE_PATH_LEN]; + + struct COMPLETION_STRUCT complete; + /* Initialize opData */ + opDataComp.compressAndVerify = CPA_TRUE; + opDataComp.integrityCrcCheck = CPA_FALSE; + opDataComp.verifyHwIntegrityCrcs = CPA_FALSE; + opDataComp.pCrcData = &compCrcData; + /* CPA_DC_FLUSH_FINAL should be the only possible flush flag to be used */ + opDataComp.flushFlag = CPA_DC_FLUSH_FINAL; + + /* Get dictionary file path */ + status = sample_getPath(filePath, gDictFileName); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Cannot access file %s\n", gDictFileName); + return CPA_STATUS_FAIL; + } + + PRINT_DBG("Processing dictionary file %s\n", gDictFileName); + + /* Get dictionary file data */ + dictData.bufferSize = &dictionaryBuffer.dataLenInBytes; + dictData.pSrcData = &dictionaryBuffer.pData; + status = sample_getFile(filePath, &dictData); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("sample_getFile failed for dictionary\n"); + return status; + } + + dictBufferSize = dictionaryBuffer.dataLenInBytes; + + /* Get input file path */ + status = sample_getPath(filePath, gInputFileName); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Cannot access file %s\n", gInputFileName); + sample_freeFile(&dictData); + return CPA_STATUS_FAIL; + } + + PRINT_DBG("Processing input file %s\n", gInputFileName); + + /* Get input file data */ + inputData.bufferSize = &inputBuffer.dataLenInBytes; + inputData.pSrcData = &inputBuffer.pData; + status = sample_getFile(filePath, &inputData); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("sample_getFile failed for input\n"); + sample_freeFile(&dictData); + return status; + } + + bufferSize = inputBuffer.dataLenInBytes; + + PRINT_DBG("cpaDcGetMetaSizeForSrcBuffWithDict\n"); + + /* Below function is used to obtain the size (in bytes) required to + * allocate a buffer descriptor for the pPrivateMetaData member in the + * CpaBufferList structure of the source buffer list used in the API's + * cpaDcCompressDataWithDict() and cpaDcDecompressDataWithDict(). + * In contrast the size in bytes to allocate the descriptor of the + * destination buffer list must not use this API, and needs to be + * determined using the API cpaDcBufferListGetMetaSize */ + // + status = cpaDcGetMetaSizeForSrcBuffWithDict( + dcInstHandle, numDictBuffers, numBuffers, &bufferSrcMetaSize); + + /* Allocate dictionary buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListDict, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaSrc, bufferSrcMetaSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pDictBuffer, + dictBufferSize); /* save dict data */ + } + pBufferListDict->pPrivateMetaData = pBufferMetaSrc; + + + /* Allocate source buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaSrc, bufferSrcMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListSrc, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = + PHYS_CONTIG_ALLOC(&pSrcBuffer, bufferSize); /* save input data */ + } + + /* Allocate destination buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = cpaDcBufferListGetMetaSize(dcInstHandle, numBuffers, &bufferDstMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaDst, bufferDstMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListDst, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pDstBuffer, bufferSize); + } + // + + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pDictBuffer, dictionaryBuffer.pData, dictBufferSize); + memcpy(pSrcBuffer, inputBuffer.pData, bufferSize); + + /* Build dict bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListDict + 1); + + pBufferListDict->pBuffers = pFlatBuffer; + pBufferListDict->numBuffers = numDictBuffers; + + pFlatBuffer->dataLenInBytes = dictBufferSize; + pFlatBuffer->pData = pDictBuffer; + + /* Build source bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListSrc + 1); + + pBufferListSrc->pBuffers = pFlatBuffer; + pBufferListSrc->numBuffers = numBuffers; + pBufferListSrc->pPrivateMetaData = pBufferMetaSrc; + + pFlatBuffer->dataLenInBytes = bufferSize; + pFlatBuffer->pData = pSrcBuffer; + + /* Build destination bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListDst + 1); + + pBufferListDst->pBuffers = pFlatBuffer; + pBufferListDst->numBuffers = numBuffers; + pBufferListDst->pPrivateMetaData = pBufferMetaDst; + + pFlatBuffer->dataLenInBytes = bufferSize; + pFlatBuffer->pData = pDstBuffer; + + /* Initialize dictionary data */ + dictionaryOpData.pDictionaryBuff = pBufferListDict; + dictionaryOpData.dictionaryType = CPA_DC_UNCOMPRESSED_DICT; + /* + * Now, we initialize the completion variable which is used by the + * callback function to indicate that the operation is complete. + * We then perform the operation. + */ + PRINT_DBG("Calling cpaDcCompressDataWithDict\n"); + + // + COMPLETION_INIT(&complete); /* add a lock using semophore */ + + /* Execute compression operation with dictionary */ + status = cpaDcCompressDataWithDict( + dcInstHandle, + sessionHdl, + pBufferListSrc, /* source buffer list */ + pBufferListDst, /* destination buffer list */ + &dictionaryOpData, /* dictionary data */ + &opDataComp, /* operational data */ + &dcResultsComp, /* results structure */ + (void *)&complete); /* data sent as is to the callback function*/ + // + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcCompressDataWithDict failed. (status = %d)\n", + status); + } + + /* + * We now wait until the completion of the operation. This uses a macro + * which can be defined differently for different OSes. + */ + if (CPA_STATUS_SUCCESS == status) + { + if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) + { + PRINT_ERR( + "Timeout or interruption in cpaDcCompressDataWithDict\n"); + status = CPA_STATUS_FAIL; + } + } + + /* + * We now check the results + */ + if (CPA_STATUS_SUCCESS == status) + { + if (dcResultsComp.status != CPA_DC_OK) + { + PRINT_ERR("Results status not as expected (status = %d)\n", + dcResultsComp.status); + status = CPA_STATUS_FAIL; + } + else + { + PRINT_DBG("Data consumed %d\n", dcResultsComp.consumed); + PRINT_DBG("Data produced %d\n", dcResultsComp.produced); + PRINT_DBG("CRC32 checksum 0x%x\n", dcResultsComp.checksum); + } + } + } + /* + * We now ensure we can decompress to the original data. + */ + if (CPA_STATUS_SUCCESS == status) + { + /* Destination is now the source buffer - update the length with amount + * of compressed data added to the buffer */ + pBufferListDst->pBuffers->dataLenInBytes = dcResultsComp.produced; + + PHYS_CONTIG_FREE(pBufferMetaDst); + + PRINT_DBG("cpaDcGetMetaSizeForSrcBuffWithDict\n"); + + /* Below function is used to obtain the size (in bytes) required to + * allocate a buffer descriptor for the pPrivateMetaData member in + * the CpaBufferList structure of the source buffer list used in the + * API's cpaDcCompressDataWithDict() and cpaDcDecompressDataWithDict(). + * In contrast the size in bytes to allocate the descriptor of the + * destination buffer list must not use this API, and needs to be + * determined using the API cpaDcBufferListGetMetaSize */ + status = cpaDcGetMetaSizeForSrcBuffWithDict( + dcInstHandle, numDictBuffers, numBuffers, &bufferSrc2MetaSize); + + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaDst, bufferSrc2MetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaDst2, bufferDstMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListDst2, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pDst2Buffer, bufferSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Build destination 2 bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListDst2 + 1); + + pBufferListDst2->pBuffers = pFlatBuffer; + pBufferListDst2->numBuffers = numBuffers; + pBufferListDst2->pPrivateMetaData = pBufferMetaDst2; + + pFlatBuffer->dataLenInBytes = bufferSize; + pFlatBuffer->pData = pDst2Buffer; + + PRINT_DBG("Calling cpaDcDecompressDataWithDict\n"); + + /* Execute decompression operation with dictionary */ + // + status = cpaDcDecompressDataWithDict( + dcInstHandle, + sessionHdl, + pBufferListDst, /* source buffer list */ + pBufferListDst2, /* destination buffer list */ + &dictionaryOpData, /* dictionary data */ + &opDataComp, /* operational data */ + &dcResultsDecomp, /* results structure */ + (void + *)&complete); /* data sent as is to the callback function*/ + // + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcDeCompressDataWithDict failed. (status = %d)\n", + status); + } + + /* + * We now wait until the completion of the operation. This uses a + * macro which can be defined differently for different OSes. + */ + if (CPA_STATUS_SUCCESS == status) + { + if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) + { + PRINT_ERR("Timeout or interruption in " + "cpaDcDeCompressDataWithDict\n"); + status = CPA_STATUS_FAIL; + } + } + + /* + * We now check the results + */ + if (CPA_STATUS_SUCCESS == status) + { + if (dcResultsDecomp.status != CPA_DC_OK) + { + PRINT_ERR( + "Results status not as expected decomp (status = %d)\n", + dcResultsDecomp.status); + status = CPA_STATUS_FAIL; + } + else + { + PRINT_DBG("Data consumed %d\n", dcResultsDecomp.consumed); + PRINT_DBG("Data produced %d\n", dcResultsDecomp.produced); + PRINT_DBG("CRC32 checksum 0x%x\n", + dcResultsDecomp.checksum); + } + + /* Compare with original source buffer */ + if (0 == memcmp(pDst2Buffer, pSrcBuffer, bufferSize)) + { + PRINT_DBG("Uncompressed data matches with the input plain " + "text\n"); + } + else + { + PRINT_ERR("Output does not match expected output\n"); + status = CPA_STATUS_FAIL; + } + } + } + } + + /* + * At this stage, the callback function has returned, so it is + * sure that the structures will not be needed anymore. Free the + * memory. + */ + PHYS_CONTIG_FREE(pDictBuffer); + OS_FREE(pBufferListDict); + PHYS_CONTIG_FREE(pSrcBuffer); + OS_FREE(pBufferListSrc); + PHYS_CONTIG_FREE(pBufferMetaSrc); + PHYS_CONTIG_FREE(pDstBuffer); + OS_FREE(pBufferListDst); + PHYS_CONTIG_FREE(pBufferMetaDst); + PHYS_CONTIG_FREE(pDst2Buffer); + OS_FREE(pBufferListDst2); + PHYS_CONTIG_FREE(pBufferMetaDst2); + + COMPLETION_DESTROY(&complete); + sample_freeFile(&dictData); + sample_freeFile(&inputData); + return status; +} + +/* + * This is the main entry point for the sample data compression code. + * It demonstrates the sequence of calls to be made to the API in order + * to create a session, perform one or more stateless dictionary + * compression operations with an algorithm and then tear down the session. + */ +CpaStatus dcStatelessSampleDict() +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaStatus intStatus = CPA_STATUS_SUCCESS; + Cpa32U sess_size = 0; + Cpa32U ctx_size = 0; + CpaDcSessionHandle sessionHdl = NULL; + CpaInstanceHandle dcInstHandle = NULL; + CpaDcSessionSetupData sd = { 0 }; + CpaDcStats dcStats = { 0 }; + CpaDcCapabilityReq capReq = { 0 }; + CpaDcCapabilityResp capResp = { 0 }; + + /* + * In this simplified version of instance discovery, we discover + * exactly one instance of a data compression service. + */ + sampleDcGetInstance(&dcInstHandle); + if (dcInstHandle == NULL) + { + return CPA_STATUS_FAIL; + } + + /* Test algorithm dictionary capabilities as not all the + * products/algorithms support dictionaries. + * For now just test the compression direction support + * will be checked within the test. + */ + // + capReq.capId = CPA_DC_CAP_BOOL_UNCOMPRESSED_DICT; + capReq.algo = CPA_DC_DEFLATE; + capReq.dir = CPA_DC_DIR_COMPRESS; + status = cpaDcQueryCapabilityByType(dcInstHandle, capReq, &capResp); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get dc instance capabilities.\n"); + return status; + } + if (CPA_FALSE == capResp.boolStatus) + { + PRINT_DBG("Uncompressed Dictionaries not supported with current " + "algorithm\n"); + return CPA_STATUS_FAIL; + } + + /* + * Set the address translation function for the instance + */ + status = cpaDcSetAddressTranslation(dcInstHandle, sampleVirtToPhys); + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Calling cpaDcStartInstance\n"); + status = cpaDcStartInstance(dcInstHandle, 0, NULL); + } + // + + if (CPA_STATUS_SUCCESS == status) + { + /* + * If the instance is polled start the polling thread. Note that + * how the polling is done is implementation-dependant. + */ + sampleDcStartPolling(dcInstHandle); + /* + * We now populate the fields of the session operational data and create + * the session. Note that the size required to store a session is + * implementation-dependent, so we query the API first to determine how + * much memory to allocate, and then allocate that memory. + */ + // + sd.compLevel = CPA_DC_L1; + sd.compType = CPA_DC_DEFLATE; + sd.huffType = CPA_DC_HT_FULL_DYNAMIC; + sd.autoSelectBestHuffmanTree = CPA_DC_ASB_DISABLED; + sd.sessDirection = CPA_DC_DIR_COMBINED; + sd.sessState = CPA_DC_STATELESS; + sd.windowSize = CPA_DC_WINSIZE_64K; + sd.checksum = CPA_DC_CRC32; + + /* Determine size of session context to allocate */ + PRINT_DBG("Calling cpaDcGetSessionSize\n"); + status = cpaDcGetSessionSize(dcInstHandle, &sd, &sess_size, &ctx_size); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate session memory */ + status = PHYS_CONTIG_ALLOC(&sessionHdl, sess_size); + } + + /* Initialize the stateless session */ + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Calling cpaDcInitSession\n"); + status = cpaDcInitSession( + dcInstHandle, + sessionHdl, /* session memory */ + &sd, /* session setup data */ + NULL, /* pContexBuffer not required for stateless operations */ + dcCallback); /* callback function */ + } + // + + if (CPA_STATUS_SUCCESS == status) + { + CpaStatus sessionStatus = CPA_STATUS_SUCCESS; + + /* Perform compression operation */ + status = compPerformOp(dcInstHandle, sessionHdl); + + /* + * In a typical usage, the session might be used to compress + * multiple buffers. In this example however, we can now + * tear down the session. + */ + PRINT_DBG("Calling cpaDcRemoveSession\n"); + // + sessionStatus = cpaDcRemoveSession(dcInstHandle, sessionHdl); + // + + /* Maintain status of remove session only when status of all operations + * before it are successful. */ + if (CPA_STATUS_SUCCESS == status) + { + status = sessionStatus; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* + * We can now query the statistics on the instance. + * + * Note that some implementations may also make the stats + * available through other mechanisms, e.g. in the /proc + * virtual filesystem. + */ + status = cpaDcGetStats(dcInstHandle, &dcStats); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcGetStats failed, status = %d\n", status); + } + else + { + PRINT_DBG("Number of compression operations completed: %llu\n", + (unsigned long long)dcStats.numCompCompleted); + PRINT_DBG("Number of decompression operations completed: %llu\n", + (unsigned long long)dcStats.numDecompCompleted); + } + } + + /* + * Free up memory, stop the instance, etc. + */ + + /* Stop the polling thread */ + sampleDcStopPolling(); + + PRINT_DBG("Calling cpaDcStopInstance\n"); + intStatus = cpaDcStopInstance(dcInstHandle); + if (CPA_STATUS_SUCCESS != intStatus) + { + PRINT_ERR("cpaDcStopInstance failed, intStatus = %d\n", intStatus); + status = intStatus; + } + + /* Free session context */ + PHYS_CONTIG_FREE(sessionHdl); + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Dictionary Sample code ran successfully\n"); + } + else + { + PRINT_DBG("Dictionary Sample code failed with status of %d\n", status); + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 new file mode 100644 index 00000000..848991db --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4 @@ -0,0 +1,294 @@ +.EQ +delim $$ +.EN +.ls 1 +.ce +PROGRAMMING BY EXAMPLE REVISITED +.sp +.ce +by John G. Cleary +.ce +Man-Machine Systems Laboratory +.ce +University of Calgary. +.sp +.sh "Introduction" +.pp +Efforts to construct an artificial intelligence have relied on +ever more complex and carefully prepared programs. While useful in +themselves, these programs +are unlikely to be useful in situations where ephemeral and +low value knowledge must be acquired. For example a person (or robot) +working in a normal domestic environment knows a lot about which +cupboards have sticky doors and where the marmalade is kept. It seems +unlikely that it will ever be economic to program such knowledge +whether this be via a language or a discourse with an expert system. +.pp +It is my thesis, then, that any flexible robot system working in the +real world must contain a component of control intermediate +between hard wired 'reflex' responses and complex intellectual +reasoning. Such an intermediate system must be adaptive, be able +to carry out complex patterned responses and be fast in operation. +It need not, however, carry out complex forward planning or be capable +of introspection (in the sense that expert systems are able to explain +their actions). +.pp +In this talk I will examine a system that acquires knowledge by +constructing a model of its input behaviour and uses this to select its +actions. It can be viewed either as an automatic adaptive system or +as an instance of 'programming by example'. Other workers have +attempted to do this, by constructing compact models in some appropriate +programming language:e.g. finite state automata [Bierman, 1972], +[Bierman and Feldman, 1972]; LISP [Bierman and Krishnaswamy, 1976]; +finite non-deterministic +automata [Gaines,1976], [Gaines,1977], +[Witten,1980]; high level languages [Bauer, 1979], [Halbert, 1981]. +These efforts, however, suffer from +the flaw that for some inputs their computing time is +super-exponential in the number +of inputs seen. This makes them totally impractical in any system which +is continuously receiving inputs over a long period of time. +.pp +The system I will examine comprises one or more simple independent +models. Because of their simplicity and because no attempt is made to +construct models which are minimal, +the time taken to store new information and to make +predictions is constant and independent of the amount of information stored +[Cleary, 1980]. This leads to a very integrated and responsive environment. +All actions by the programmer are immediately incorporated into the program +model. The actions are also acted upon so that their consequences are +immediately apparent. +However, the amount of memory used could grow +linearly with time. [Witten, 1977] introduces a modelling system related +to the one here which does not continually grow and which can be updated +incrementally. +.pp +It remains to be shown that the very simple models used are capable +of generating any +interestingly complex behaviour. +In the rest of this +talk I will use the problem of executing a subroutine to illustrate +the potential of such systems. +The example will also illustrate some of the techniques which have been +developed for combining multiple models, [Cleary, 1980], [Andreae +and Cleary, 1976], [Andreae, 1977], [Witten,1981]. It has also been +shown in [Cleary, 1980] and in [Andreae,1977] that such systems can +simulate any Turing machine when supplied with a suitable external memory. +.sh "The modelling system" +.pp +Fig. 1 shows the general layout of the modeller. Following the flow +of information through the system it first receives a number of inputs +from the external world. These are then used to update the current +contexts of a number of Markov models. Note, that each Markov model +may use different inputs to form its current context, and that they +may be attempting to predict different inputs. A simple robot +which can hear and move an arm might have two models; one, say, in +which the last three sounds it heard are used to predict the next +word to be spoken, and another in which the last three sounds and the last +three arm movements are used to predict the next arm movement. +.pp +When the inputs are received each such context and its associated +prediction (usually +an action) are added to the Markov model. (No +counts or statistics are maintained \(em they are not necessary.) When the +context recurs later it will be retrieved along with all the predictions +which have been stored with it. +.pp +After the contexts have been stored they +are updated by shifting in the new inputs. These new contexts are then +matched against the model and all the associated predictions are retrieved. +These independent predictions from the individual Markov models +are then combined into a single composite +prediction. +(A general theory of how to do this has been +developed in [Cleary, 1980]). +.pp +The final step is to present this +composite prediction to a device I have called the 'choice oracle'. +This uses whatever information it sees fit to choose the next action. +There are many possibilities for such a device. One might be to choose +from amongst the predicted actions if reward is expected and to choose +some other random action if reward is not expected. The whole system then +looks like +a reward seeking homeostat. At the other extreme the oracle might be +a human programmer who chooses the next action according to his own +principles. The system then functions more like a programming by +example system \(em [Witten, 1981] and [Witten, 1982] give examples of such +systems. +[Andreae, 1977] gives an example of a 'teachable' system lying between +these two extremes. +.pp +After an action is chosen this is +transmitted to the external world and the resultant inputs are used +to start the whole cycle again. Note that the chosen action will +be an input on the next cycle. +.sh "Subroutines" +.pp +An important part of any programming language is the ability to write a +fragment of a program and then have it used many times without it having +to be reprogrammed each time. A crucial feature of such shared code is +that after it has been executed the program should be controlled by the +situation which held before the subroutine was called. A subroutine can be +visualised as a black box with an unknown and arbitrarily complex interior. +There are many paths into the box but after passing through each splits again +and goes its own way, independent of what happened inside the box. +.np +Also, if there are $p$ paths using the subroutine and $q$ different sequences +within it then the amount of programming needed should be proportional to +$p + q$ and not $p * q$. The example to follow possess both these properties +of a subroutine. +.rh "Modelling a Subroutine." +The actual model we will use is described in Fig. 2. There are two Markov +models (model-1 and model-2) each seeing and predicting different parts of +the inputs. The inputs are classified into four classes; ACTIONs that +move a robot (LEFT, RIGHT, FAST, SLOW), patterns that it 'sees' (danger, +moved, wall, stuck) and two types of special 'echo' actions, # actions +and * actions (*home, #turn). The # and * actions have no effect on the +environment, +their only purpose is to be inputs and act as place keepers for relevant +information. They may be viewed as comments which remind the system of +what it is doing. (The term echo was used in [Andreae,1977], where the +idea was first introduced, in analogy to spoken words of which one +hears an echo.) +.pp +Model-2 is a Markov model of order 2 and uses only # actions in its +context and seeks to predict only * actions. Model-1 is a Markov model +of order 3 and uses all four classes of inputs in its context. It +seeks to predict ACTIONs, # actions and * actions. However, * actions +are treated specially. Rather than attempt to predict the exact * action +it only stores * to indicate that some * action has occurred. This +special treatment is also reflected in the procedure for combining the +predictions of the two models. Then the prediction of model-2 is used, +only if model-1 predicts an *. That is, model-1 predicts that some +* action will occur and model-2 is used to select which one. If model-1 +does not predict an * then its prediction is used as the combined prediction +and that from model-2 is ignored. +.pp +The choice oracle that is used for this example has two modes. In +programmer mode a human programmer is allowed to select any action +she wishes or to acquiesce with the current prediction, in which case +one of the actions in the combined prediction is selected. In +execution mode one of the predicted actions is selected and the +programmer is not involved at all. +.pp +Before embarking on the actual example some points about the predictions +extracted from the individual Markov models should be noted. First, if +no context can be found stored in the memory which equals the current +context then it is shortened by one input and a search is made for any +recorded contexts which are equal over the reduced length. If necessary +this is repeated until the length is zero whereupon all possible +allowed actions are predicted. +.pp +Fig. 3 shows the problem to be programmed. If a robot sees danger it +is to turn and flee quickly. If it sees a wall it is to turn and return +slowly. The turning is to be done by a subroutine which, if it gets +stuck when turning left, turns right instead. +.pp +Fig. 4 shows the contexts and predictions stored when this is programmed. +This is done by two passes through the problem in 'program' mode: once +to program the fleeing and turning left; the other to program the wall +sequence and the turning right. Fig. 5 then shows how this programming +is used in 'execute' mode for one of the combinations which had not been +explicitly programmed earlier (a wall sequence with a turn left). The +figure shows the contexts and associated predictions for each step. +(Note that predictions are made and new contexts are stored in both +modes. They have been omitted from the diagrams to preserve clarity.) +.sh "Conclusion" +.pp +The type of simple modelling system presented above is of interest for a +number of reasons. Seen as a programing by example system, +it is very closely +integrated. Because it can update its models incrementally in real time +functions such as input/output, programming, compilation and execution +are subsumed into a single mechanism. Interactive languages such as LISP +or BASIC gain much of their immediacy and usefulness by being interpretive +and not requiring a separate compilation step when altering the source +program. By making execution integral with the process of program entry +(some of) the consequencs of new programming become immediately apparent. +.pp +Seen as an adaptive controller, the system has the advantage of being fast +and being able to encode any control strategy. Times to update the model +do not grow with memory size and so it can operate continuously in real time. +.pp +Seen as a paradigm for understanding natural control systems, it has the +advantage of having a very simple underlying storage mechanism. Also, +the ability to supply an arbitrary choice oracle allows for a wide +range of possible adaptive strategies. +.sh "References" +.in +4m +.sp +.ti -4m +ANDREAE, J.H. 1977 +Thinking with the Teachable Machine. Academic Press. +.sp +.ti -4m +ANDREAE, J.H. and CLEARY, J.G. 1976 +A New Mechanism for a Brain. Int. J. Man-Machine Studies +8(1):89-119. +.sp +.ti -4m +BAUER, M.A. 1979 Programming by examples. Artificial Intelligence 12:1-21. +.sp +.ti -4m +BIERMAN, A.W. 1972 +On the Inference of Turing Machines from Sample Computations. +Artificial Intelligence 3(3):181-198. +.sp +.ti -4m +BIERMAN, A.W. and FELDMAN, J.A. 1972 +On the Synthesis of Finite-State Machines from Samples of +their Behavior. IEEE Transactions on Computers C-21, June: +592-597. +.sp +.ti -4m +BIERMAN, A.W. and KRISHNASWAMY, R. 1976 Constructing programs from example +computations. IEEE transactions on Software Engineering SE-2:141-153. +.sp +.ti -4m +CLEARY, J.G. 1980 +An Associative and Impressible Computer. PhD thesis, University +of Canterbury, Christchurch, New Zealand. +.sp +.ti -4m +GAINES, B.R. 1976 +Behaviour/structure transformations under uncertainty. +Int. J. Man-Machine Studies 8:337-365. +.sp +.ti -4m +GAINES, B.R. 1977 +System identification, approximation and complexity. +Int. J. General Systems, 3:145-174. +.sp +.ti -4m +HALBERT, D.C. 1981 +An example of programming by example. Xerox Corporation, Palo Alto, +California. +.sp +.ti -4m +WITTEN, I.H. 1977 +An adaptive optimal controller for discrete-time Markov +environments. Information and Control, 34, August: 286-295. +.sp +.ti -4m +WITTEN, I.H. 1979 +Approximate, non-deterministic modelling of behaviour +sequences. Int. J. General Systems, 5, January: 1-12. +.sp +.ti -4m +WITTEN, I.H. 1980 +Probabilistic behaviour/structure transformations using +transitive Moore models. Int. J. General Systems, 6(3): +129-137. +.sp +.ti -4m +WITTEN, I.H. 1981 +Programming by example for the casual user: a case study. +Proc. Canadian Man-Computer Communication Conference, Waterloo, +Ontario, 105-113. +.sp +.ti -4m +WITTEN, I.H. 1982 +An interactive computer terminal interface which predicts user +entries. Proc. IEE Conference on Man-Machine Interaction, +Manchester, England. +.in -4m diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict new file mode 100644 index 00000000..c8196da0 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample_dict/paper4.dict @@ -0,0 +1,31 @@ +.EQ +delim $$ +.EN +.ls 1 +.ce +PROGRAMMING BY EXAMPLE REVISITED +.sp +.ce +by John G. Cleary +.ce +Man-Machine Systems Laboratory +.ce +University of Calgary. +.sp +.sh "Introduction" +.pp +Efforts to construct an artificial intelligence have relied on +ever more complex and carefully prepared programs. While useful in +themselves, these programs +are unlikely to be useful in situations where ephemeral and +low value knowledge must be acquired. For example a person (or robot) +working in a normal domestic environment knows a lot about which +cupboards have sticky doors and where the marmalade is kept. It seems +unlikely that it will ever be economic to program such knowledge +whether this be via a language or a discourse with an expert system. +.pp +It is my thesis, then, that any flexible robot system working in the +real world must contain a component of control intermediate +between hard wired 'reflex' responses and complex intellectual +reasoning. Such an intermediate system must be adaptive, be able +to carry out complex patt \ No newline at end of file diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c b/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c new file mode 100644 index 00000000..0ed6ed48 --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_sample_user.c @@ -0,0 +1,77 @@ +/****************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file cpa_decomp_sample_user.c + * + *****************************************************************************/ + +#include "cpa_sample_utils.h" +#include "icp_sal_user.h" + +#define FILE_NAME_LENGTH 100 +char *gFileNameComp = NULL; +char *gFileNameOut = NULL; + +extern CpaStatus dcStatelessDecompSample(void); + +int gDebugParam = 1; + +int main(int argc, const char **argv) +{ + CpaStatus stat = CPA_STATUS_SUCCESS; + char fileComp[FILE_NAME_LENGTH] = "paper4.gz"; + char fileRes[FILE_NAME_LENGTH] = "paper4_decompressed"; + + if (argc > 1) + { + gDebugParam = atoi(argv[1]); + } + + PRINT_DBG("Starting Stateless Decompression Sample Code App ...\n"); + + stat = qaeMemInit(); + if (CPA_STATUS_SUCCESS != stat) + { + PRINT_ERR("Failed to initialize memory driver\n"); + return (int)stat; + } + + stat = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); + if (CPA_STATUS_SUCCESS != stat) + { + PRINT_ERR("Failed to start user process SSL\n"); + qaeMemDestroy(); + return (int)stat; + } + + gFileNameComp = fileComp; + gFileNameOut = fileRes; + + stat = dcStatelessDecompSample(); + + if (CPA_STATUS_SUCCESS == stat) + { + PRINT_DBG("\nStateless Decompression Sample Code App finished\n"); + } + else + { + PRINT_ERR("\nStateless Decompression Sample Code App failed\n"); + } + + icp_sal_userStop(); + + qaeMemDestroy(); + gFileNameComp = NULL; + gFileNameOut = NULL; + + return (int)stat; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c new file mode 100644 index 00000000..5931c21d --- /dev/null +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/cpa_decomp_stateless_sample.c @@ -0,0 +1,472 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ + +/* + * This is sample code that demonstrates usage of the data decompression API, + * and specifically using this API to stateless decompress a gzip file. It + * will decompress the data using deflate with dynamic huffman trees. + */ + +#include "cpa.h" +#include "cpa_dc.h" + +#include "cpa_sample_utils.h" + +extern int gDebugParam; + +extern char *gFileNameComp; +extern char *gFileNameOut; + +#define SAMPLE_MAX_BUFF \ + 13286 /* 13KB - Sufficient for the decompressed data in this example */ +#define TIMEOUT_MS 5000 /* 5 seconds */ +#define GZIP_HEADER_SIZE 10 /* Standard gzip header size */ +#define GZIP_FOOTER_SIZE 8 /* Standard gzip footer size (CRC32 + ISIZE) */ +/* + ***************************************************************************** + * Forward declaration + ***************************************************************************** + */ +CpaStatus dcStatelessDecompSample(void); + +/* + * Callback function + * + * This function is "called back" (invoked by the implementation of + * the API) when the asynchronous operation has completed. The + * context in which it is invoked depends on the implementation, but + * as described in the API it should not sleep (since it may be called + * in a context which does not permit sleeping, e.g. a Linux bottom + * half). + * + * This function can perform whatever processing is appropriate to the + * application. For example, it may free memory, continue processing + * of a packet, etc. In this example, the function only sets the + * complete variable to indicate it has been called. + */ +// +static void dcCallback(void *pCallbackTag, CpaStatus status) +{ + PRINT_DBG("Callback called with status = %d.\n", status); + if (NULL != pCallbackTag) + { + /* indicate that the function has been called */ + COMPLETE((struct COMPLETION_STRUCT *)pCallbackTag); + } +} +// + +/* + * This function performs a stateless decompression operation. + */ +static CpaStatus decompPerformOp(CpaInstanceHandle dcInstHandle, + CpaDcSessionHandle sessionHdl) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa8U *pBufferMetaSrc = NULL; + Cpa8U *pBufferMetaDst = NULL; + Cpa32U bufferMetaSize = 0; + CpaBufferList *pBufferListSrc = NULL; + CpaBufferList *pBufferListDst = NULL; + CpaDcOpData opData = {}; + CpaFlatBuffer *pFlatBuffer = NULL; + Cpa32U numBuffers = 1; /* only using 1 buffer in this case */ + /* allocate memory for bufferlist and array of flat buffers in a contiguous + * area and carve it up to reduce number of memory allocations required. */ + Cpa32U bufferListMemSize = + sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer)); + Cpa8U *pSrcBuffer = NULL; + Cpa8U *pDstBuffer = NULL; + char filePath[MAX_CORPUS_FILE_PATH_LEN]; + FILE *dstFile = NULL; + Cpa32U srcBufferSize = 0; + Cpa32U totalBytesProduced = 0; + file_data_t inputData = { 0 }; + CpaFlatBuffer inputBuffer = { 0 }; + /* The following variables are allocated on the stack because we block + * until the callback comes back. If a non-blocking approach was to be + * used then these variables should be dynamically allocated */ + CpaDcRqResults dcResults; + struct COMPLETION_STRUCT complete; + INIT_OPDATA(&opData, CPA_DC_FLUSH_FINAL); + /* + * Initialize the completion variable which is used by the callback + * function */ + COMPLETION_INIT(&complete); + + /* Get input file path */ + status = sample_getPath(filePath, gFileNameComp); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Cannot access file %s\n", gFileNameComp); + return CPA_STATUS_FAIL; + } + + PRINT_DBG("Processing input file %s\n", gFileNameComp); + + /* Get input file data */ + inputData.bufferSize = &inputBuffer.dataLenInBytes; + inputData.pSrcData = &inputBuffer.pData; + status = sample_getFile(filePath, &inputData); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("sample_getFile failed for input\n"); + return status; + } + + srcBufferSize = inputBuffer.dataLenInBytes; + + /* Open decompressed output file */ + dstFile = fopen(gFileNameOut, "wb"); + if (NULL == dstFile) + { + PRINT_ERR("Cannot open file %s\n", gFileNameOut); + sample_freeFile(&inputData); + return CPA_STATUS_FAIL; + } + + PRINT_DBG("Compressed file size: %u bytes\n", srcBufferSize); + + /* + * Different implementations of the API require different + * amounts of space to store meta-data associated with buffer + * lists. We query the API to find out how much space the current + * implementation needs. + */ + // + status = + cpaDcBufferListGetMetaSize(dcInstHandle, numBuffers, &bufferMetaSize); + + /* Allocate source buffer */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaSrc, bufferMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListSrc, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pSrcBuffer, srcBufferSize); + } + + /* Allocate destination buffer - larger for decompression */ + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMetaDst, bufferMetaSize); + } + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferListDst, bufferListMemSize); + } + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate larger buffer for decompressed data */ + status = PHYS_CONTIG_ALLOC(&pDstBuffer, SAMPLE_MAX_BUFF); + } + // + + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pSrcBuffer, inputBuffer.pData, srcBufferSize); + + /* Build source bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListSrc + 1); + + pBufferListSrc->pBuffers = pFlatBuffer; + pBufferListSrc->numBuffers = 1; + pBufferListSrc->pPrivateMetaData = pBufferMetaSrc; + + /* Skip gzip header (10 bytes) and footer (8 bytes) */ + pFlatBuffer->dataLenInBytes = + srcBufferSize - GZIP_HEADER_SIZE - GZIP_FOOTER_SIZE; + pFlatBuffer->pData = pSrcBuffer + GZIP_HEADER_SIZE; + + /* Build destination bufferList */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferListDst + 1); + + pBufferListDst->pBuffers = pFlatBuffer; + pBufferListDst->numBuffers = 1; + pBufferListDst->pPrivateMetaData = pBufferMetaDst; + + pFlatBuffer->dataLenInBytes = SAMPLE_MAX_BUFF; + pFlatBuffer->pData = pDstBuffer; + + /* Perform stateless decompression */ + PRINT_DBG("cpaDcDecompressData2\n"); + + // + + status = cpaDcDecompressData2( + dcInstHandle, + sessionHdl, + pBufferListSrc, /* source buffer list */ + pBufferListDst, /* destination buffer list */ + &opData, /* Operational data */ + &dcResults, /* results structure */ + (void *)&complete); /* data sent as is to the callback function*/ + // + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcDecompressData2 failed. (status = %d)\n", status); + } + + /* + * We now wait until the completion of the operation. This uses a macro + * which can be defined differently for different OSes. + */ + if (CPA_STATUS_SUCCESS == status) + { + if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) + { + PRINT_ERR("timeout or interruption in cpaDcDecompressData2\n"); + } + } + if (CPA_STATUS_SUCCESS == status) + { + /* + * Check the results + */ + if (dcResults.status != CPA_DC_OK) + { + PRINT_ERR("Decompression result status not OK (status = %d)\n", + dcResults.status); + status = CPA_STATUS_FAIL; + } + else + { + PRINT_DBG("Data consumed: %u\n", dcResults.consumed); + PRINT_DBG("Data produced: %u\n", dcResults.produced); + PRINT_DBG("CRC32 checksum: 0x%x\n", dcResults.checksum); + + /* Write decompressed data to output file */ + totalBytesProduced = + fwrite(pDstBuffer, 1, dcResults.produced, dstFile); + if (totalBytesProduced != dcResults.produced) + { + PRINT_ERR("Error writing decompressed data\n"); + status = CPA_STATUS_FAIL; + } + else + { + PRINT_DBG( + "Successfully decompressed %u bytes to %u bytes\n", + dcResults.consumed, + dcResults.produced); + } + } + } + } + + /* Close files */ + if (NULL != dstFile) + { + fclose(dstFile); + } + + /* + * At this stage, the callback function has returned, so it is + * sure that the structures won't be needed any more. Free the + * memory! + */ + PHYS_CONTIG_FREE(pSrcBuffer); + OS_FREE(pBufferListSrc); + PHYS_CONTIG_FREE(pBufferMetaSrc); + PHYS_CONTIG_FREE(pDstBuffer); + OS_FREE(pBufferListDst); + PHYS_CONTIG_FREE(pBufferMetaDst); + COMPLETION_DESTROY(&complete); + sample_freeFile(&inputData); + + return status; +} + +/* + * This is the main entry point for the sample stateless decompression code. + * demonstrates the sequence of calls to be made to the API in order + * to create a session, perform one or more stateless decompression operation, + * and then tear down the session. + */ +CpaStatus dcStatelessDecompSample(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaDcInstanceCapabilities cap = { 0 }; + Cpa32U sess_size = 0; + Cpa32U ctx_size = 0; + CpaDcSessionHandle sessionHdl = NULL; + CpaInstanceHandle dcInstHandle = NULL; + CpaDcSessionSetupData sd = { 0 }; + CpaDcStats dcStats = { 0 }; + + /* + * In this simplified version of instance discovery, we discover + * exactly one instance of a data decompression service. + */ + sampleDecompGetInstance(&dcInstHandle); + + if (dcInstHandle == NULL) + { + PRINT_ERR("No decompression instance was found, skipping the test\n"); + return CPA_STATUS_SUCCESS; + } + + /* Query Capabilities */ + PRINT_DBG("cpaDcQueryCapabilities\n"); + // + status = cpaDcQueryCapabilities(dcInstHandle, &cap); + if (status != CPA_STATUS_SUCCESS) + { + return status; + } + + if (!cap.statelessDeflateDecompression || !cap.checksumCRC32) + { + PRINT_DBG("Error: %s is unsupported\n", + !cap.statelessDeflateDecompression + ? "Stateless deflate decompression" + : "Checksum CRC32"); + return CPA_STATUS_FAIL; + } + + if (CPA_STATUS_SUCCESS == status) + { + /* + * Set the address translation function for the instance + */ + status = cpaDcSetAddressTranslation(dcInstHandle, sampleVirtToPhys); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Start Data Decompression component */ + PRINT_DBG("cpaDcStartInstance\n"); + status = cpaDcStartInstance(dcInstHandle, 0, NULL); + } // + + if (CPA_STATUS_SUCCESS == status) + { + /* + * If the instance is polled start the polling thread. Note that + * how the polling is done is implementation-dependent. + */ + sampleDcStartPolling(dcInstHandle); + + /* + * We now populate the fields of the session operational data and create + * the session. Note that the size required to store a session is + * implementation-dependent, so we query the API first to determine how + * much memory to allocate, and then allocate that memory. + */ + // + sd.compLevel = CPA_DC_L1; + sd.compType = CPA_DC_DEFLATE; + sd.huffType = CPA_DC_HT_FULL_DYNAMIC; + sd.sessDirection = CPA_DC_DIR_DECOMPRESS; + sd.sessState = CPA_DC_STATELESS; + sd.checksum = CPA_DC_CRC32; + + /* Determine size of session context to allocate */ + PRINT_DBG("cpaDcGetSessionSize\n"); + status = cpaDcGetSessionSize(dcInstHandle, &sd, &sess_size, &ctx_size); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate session memory */ + status = PHYS_CONTIG_ALLOC(&sessionHdl, sess_size); + } + + /* Initialize the stateless session */ + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("cpaDcInitSession\n"); + status = cpaDcInitSession( + dcInstHandle, + sessionHdl, /* session memory */ + &sd, /* session setup data */ + NULL, /* pContexBuffer not required for stateless operations */ + dcCallback); /* callback function */ + } + // + + if (CPA_STATUS_SUCCESS == status) + { + CpaStatus sessionStatus = CPA_STATUS_SUCCESS; + + /* Perform Decompression operation */ + status = decompPerformOp(dcInstHandle, sessionHdl); + + /* + * In a typical usage, the session might be used to decompress + * multiple buffers. In this example however, we can now + * tear down the session. + */ + PRINT_DBG("cpaDcRemoveSession\n"); + // + sessionStatus = cpaDcRemoveSession(dcInstHandle, sessionHdl); + // + + /* Maintain status of remove session only when status of all operations + * before it are successful. */ + if (CPA_STATUS_SUCCESS == status) + { + status = sessionStatus; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* + * We can now query the statistics on the instance. + * + * Note that some implementations may also make the stats + * available through other mechanisms, e.g. in the /proc + * virtual filesystem. + */ + status = cpaDcGetStats(dcInstHandle, &dcStats); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcGetStats failed, status = %d\n", status); + } + else + { + PRINT_DBG("Number of decompression operations completed: %llu\n", + (unsigned long long)dcStats.numDecompCompleted); + } + } + + /* + * Free up memory, stop the instance, etc. + */ + + /* Stop the polling thread */ + sampleDcStopPolling(); + + PRINT_DBG("cpaDcStopInstance\n"); + cpaDcStopInstance(dcInstHandle); + + /* Free session Context */ + PHYS_CONTIG_FREE(sessionHdl); + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Sample code ran successfully\n"); + } + else + { + PRINT_DBG("Sample code failed with status of %d\n", status); + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/paper4.gz b/quickassist/lookaside/access_layer/src/sample_code/functional/decomp/decomp_stateless_sample/paper4.gz new file mode 100644 index 0000000000000000000000000000000000000000..8f73003455aedff9fec425cab3481bae5c92afb4 GIT binary patch literal 5603 zcmV<96&&gxiwFP!00000|BPE(cic9Te#fuC$@m;enHDE4#TO}0Ek(9FW7%Fwv!2BhA3#S2kfeH29#xNqXu(Z*;sxPB) z_6JdPow!=BosU6ACrf8T^zc$DE0vFCZAzmWX>8O@V>a5BTGr}8OAqJMm2_6<2km9+ zyoT9r*XVCBx00pudfhk8PIg{*@S}o1+{UXm6jFYvO`~NWa0o0eVhtzJ&4Ugz34aGY z3>Gj|_O>ziy4j(KtI0eG$LtlJB*<;8VWjSA-D(dagAk%|Tlt`xUdwyywvDbfTDETe2#mr8b^J!j=1JoIkm;*r=oe{bvtH&oI(-@@{hYjudGl-fQR z?`*4Wq+J4xX&fkU<@zYMwJB>+_T9=UUj^13&b!~i63z!w7RwF?m#xCpRi&i~@?Lkb zka8Ji(4ZeNs-ad<8d%*ljU@fUfixJ;wIES+S$i_{Wj#5&fQ=&T1q+yfa~_OBah2Wl z3f{w!m8?uCUGKpLTN7&pg8l|N0U-!*1z~0xQNVUb)-r50J7d9=-N`lJz^oe0Doj)5 zM3FFFcnyk#XHCUcfdfQEN=76(iz;<%dh8v8(6_oWDuRFLxYgRqT6xeP8d4qr;$YhY zz-EBiL9=o*DjCDNj6Lj%dxMoh7_k2>YDw9>4YJ4sTq@N?@T?jAfRhPOGl1NKoAq(n zq*D>ru)2CA1WZ~hSP4$&K$(Qu0<~y0NN!!6$=Yqvl(X-w3jVnT_{a_{g)*a|V8v2( zBnjxqpo&7L$*tufD;Qt{0Mdwb8^W|gO-t2B*D7?(Y_TjQC{6Gf10pG8GLYjSxk`)jt#+9Q4q&5Cv@Bv) zd-hy`)@{28n??uzOM=dD+TJnIY#=WmHV{t%TS(P`TXvq{JKZ(A-?=U}g?FpG-zl(ln9+>c^yllZGx7Tu6C*hO{Orw7uwHF8wQK;z&2Xq7f4@*Y z!WyQW;R^3nv(i4|gE#Z9g}5WW*BpcwQ8uY*Rt`!L8b)&WnH5kbnB>)A5z zOCZB#N+W_dfmq7e-t_^-dtGYtz*I-;J2(;r26zPiZ(N1oLqXZk?&<-jkGu?z1-8?$ z2K;g<)CPknh1DzFY50$gg3$(txX`8Q1EHHWLxUlZ#~ndomEKz?6P}67G3Z1$@z{)C zIwCO!!lPBqjO;;Lj-V?`t{PD+tG6H%*rz3iqwS(2jY`10t_-`eWQCy{MjA9ZNRnHs z*7f{rx+3jUiQhRXA`t!bHCqmzL5u}ylmvb6h|s~g(O;DvC>c3n615AlXqrrW=*zJl z(vKFc2In$u3JZt@TRPu4UKVz6(+O;aLZUtMlDL3sg2M+erSI?K#R<(nM`asr#o9xKU%Ic`)v?aTIV z5VZ-4kmTVhMLHt_kTMlUMCD+XbumMqJcV{fW%HQC)O}acLZCaZQRz5#$Rywquu4eT zT>u8KgLc@E3GNAybWr7o04ULsH`-EM#V})cf?_#lXm-==hCn*Rnt~&nMoc8cnINW7 zt`9mJ7Pe?{jQ*y}J_WMSue`$_8pVbQkS8D{$Td0_6W_Qs=U^%B659>AChbGW80Ryw zB^QXgtgQiHWGAHbaRpo@Dr8wmB`RV=INu6<6C`Wtj|s zPu3o2<*jR=h@hZCA;@jTBSMNb;9yhJ`{Xu|nXioxF@*v0Esi*Hh&Te{8ciAwL76a7 z83sheHzw7L_UMui(Uh|HNC-&P5vB)RcDlv2^7rmR4iVua;Bl7nKv3-7d(kSQ4p|wD zw}9ImvjEq4OgK)+JIb`;>{6_E_65Txz--T!Q-Wys-!s?e=Geae7;QWNAimgbF zlnlZShr>c}B?gXa8gS)dABdlYvMDYd(Tb|7SR~wO3JWmO;YSAu>rr@2xF8{=+>k{< z#>QezSMq-kbxSay7Z?yM$Qc6m9gd{T2gzu~Q$TqMnu^*FRqP5+7roJVJVkjDdwbI) z8qQ}4;t?07oPfuh$YEu%j#TGrIXKCa2_!Q&7&ty*^bfUJ6M~IR_Sp`&WzWPUXIKkc^E{H5tiVHbU zfv5!sYdEKL!Nk3!tPqEbfe>M~!yxHO0X+i>j zz$4LeViaYRM3Stqfq@!r$##RxyJ3^bgR*w`#(7m@r6wr%qr!0ujHDm5-(zTi7^L^0 zHxsGHRXZ2-#P?`VQo7d(+ja*rJOr~cjfqAFE;-QOvRqgnTAiqArN@Pt*daNyn-Hha z)m7RmNV5iOQ$=qARp$KGR+D8o4VU@aXm7S)^+d7LL9_tqVft0yQVF8T= zNdq7cvO!E$LK1u`^18Q4SFQ7!M3+i-d$qdAc~qK6JT%E~-^@7=nLaxCDmUg~NWsF8 zpot+vdz1vxc<@l0=in424&jDV)6a4b@PSAkhcT*ukcr?a7EJcW6SQr<4*50X$2PL_$IqfN5oU zUFqy-Qd%ZuTDLX2Dbv=qfpS>bllcgspULT{awAV2l8&>zS5P6w@>k_(jtile%K7 zLZZDwE~YOqQG&(AgTbI~PzNwn$yKAud%1GoQs{)-(PB5wlH!zK8Gx2IlX?ik0yZQ3 zQ}$D_4r6tTYp(jNfDWPpZ(R=+jFO|D6+fV*q~b0%=NDT&R;(sK+zh2RD-O(5@tm+=NrQ3gQo4{@ zM)HvUJ)YBf`0taWWL2$61X~U9*={DzFCy}zsVl#$8?0kbwa4_RZgmmX?J z;}@5A%TFHzk&(b8SgLeuaQNZs?cGe?EZ@Dqo5{C}TlnwohfiOQW(WafM4p8vJ-`ru zAP*}b7wu=XP&EVGH4PLAu`lnBm_D{n#$A_~ztiOV2O22&AcyCf{7e3mfc#_rB@chZ zXbJCuDeO@?=wIaiAmS$Lu%oHVfjh;d<3#;41C^QuSL}M1SwF)n9f1Y(1}>~Ov(d#OV2hcl_hZFbZzq!J6`SrwQJP&O#( z1eR(XZ(-Zwh~mmMgA&D4d$}%7g(V=Oo{ZNAq}RcQl6*dhl(N$>On!1QilF8xgAL*I z*U2TG?kI*WPsc4Wzn{XI+m>WV-ac0h)Iu+2CQv?_$5Q}wC3OX=)O{7%n@FM- z*}CF3I$%7n7!FJfOD877Jlbt?Sv3H;kjr6nG4x8)CL{#MAp}P^9wo1+ z0v&Rw;Km_DN+ctd8WT~>#yT{}P<-uGN<1g8kBX;^GlwfQX;w7qd1=LvGRi`1gubFbb|j<6CpajCxj5CIZ2tcvnEF*w#Z$fpuv_pV?m8x{U`cCnOG3Q z=F*DPxOJ9~F@@`q*=W0oH5zd}HkAay)&$JznfoAzGYw7T3Hb8g+B*(Rbm4*o%_V)KMMiA4 zx$+Yv6l1ISbkZu$_W&HE2SijXTuxc2(ZD$fXbSHIF@uI|fm8!5sO2BMDesA1(&;gLPx6ATpbx zxTzLoaS8PkqG6s=tgGC>v&n<8*VwY+HvS!9|a*im{2gb?~RS6)L0xP|0e zSrgg<;v*;pneahRzS_tegtf@BN!G z#h`>Ugh{0@0Ui)b4k;SD^-=bgYZX$Ip+39#FcsPY9)S ztHv7`Eab2q=GIAJ_@x->iGL~}MD!1BsTrm0F0U#1&UgcX;SO*U9$gdi{a)or-*hog z`bgnEn15@sS#TMo*pgr~Oul8ABJ zhI!TA*|}jS)!vOit;vm5WEi#CgD&-l#G@V}-4^f21gYb-dz1%L_-EP!UWJlXcx73L zoFYuV9%B_l%9@&LDj|8TXq`4>KTN4vZd3;7Z7dY#pi&UfLt z;R|kFz+k!e332Qz>_ELaoFARPIXj-u&-S;ySp4JaW+tzT1?_PrKTo}3U_~I##rU!C za{96G{N#Lod@_Hu?DFd7dhu~47sVG^_(XiNq?e^l%0*+`_2l(Q+Q3ocmU;M+zV=dF z9E(5O{q*qk=zRWWemp;W^PC9u4c*m;U+Kwj#bRHm+nwdlTv4dE^vT@uZB$WzSG3#? z18%&~2x^BP5-hK-uH+qd_H)wdY&rxsbuK|iGx=L@^|^R?c5?jk?Dc<=_wP5$+xH(A zw_g_50D~I_fxMi4h?ux5iI+o|D5tt($>Jl)ZrwU=F@9Xxjj@{P_x9@e|Xigh5TIqI($Ste!DK{+jTIdU-fvecv*WBVp#+C z*E7QT{{Sb!s{3-hTP#0b-Ol7ik@O)h@)tjUW3^y*M28*vW`RjY_5c`gDr$zZSR5^aelALwG7KZ6RcM_s#I`q!~0wqraKy&hMbQLjJtXym<<$ ze|bEA{qz2|?-w5~u5RvT^4H>$bU#PkXIs0q?7r)=h5V-mDdc7PmW?F)tQrTT8Xe>} zm#Q(qAl9h;{k|;k?ydlb%Yoe%lVIoIpLS$@2zo?A_)R%fGWr;UNbWvQI-&tRWNc+J z!SNC^dHOS;zTfmAp39RruZ~a7UOq3 #include #include +#include +#include +#include +#include + /* Performance sample code mem utils */ #include "qae_mem.h" @@ -538,6 +544,8 @@ void symSessionWaitForInflightReq(CpaCySymSessionCtx pSessionCtx); void sampleDcGetInstance(CpaInstanceHandle *pDcInstHandle); +void sampleDecompGetInstance(CpaInstanceHandle *pDecompInstHandle); + void sampleDcStartPolling(CpaInstanceHandle dcInstHandle); void sampleDcStopPolling(void); @@ -571,4 +579,22 @@ void hexLog(Cpa8U *pData, Cpa32U numBytes, const char *caption); CpaPhysicalAddr virtAddrToDevAddr(void *pVirtAddr, CpaInstanceHandle instance, CpaAccelerationServiceType type); + +typedef struct file_data_s +{ + Cpa8U **pSrcData; + Cpa32U *bufferSize; +} file_data_t; + +#ifdef USER_SPACE +#define MAX_CORPUS_FILE_PATH_LEN (100) +#ifndef SAMPLE_CODE_CORPUS_PATH +#define SAMPLE_CODE_CORPUS_PATH "" +#endif + +CpaStatus sample_getFile(const char *filename, file_data_t *file_data); +CpaStatus sample_freeFile(file_data_t *file_data); +CpaStatus sample_getPath(char *filePath, char *fileName); +#endif + #endif diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_file_sample/cpa_hash_file_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_file_sample/cpa_hash_file_sample.c index 9dbd8904..1952fbb2 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_file_sample/cpa_hash_file_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_file_sample/cpa_hash_file_sample.c @@ -20,6 +20,8 @@ #include "cpa_cy_sym.h" #include "cpa_sample_utils.h" #include +#include +#include #include extern int gDebugParam; @@ -33,70 +35,6 @@ extern int gDebugParam; extern char *gFileName; -typedef struct file_data_s -{ - Cpa8U **pSrcData; - Cpa32U *bufferSize; -} file_data_t; - -/* - * This function copies a file to memory - */ -CpaStatus sample_getFile(const char *filename, file_data_t *file_data) -{ - FILE *srcFile = NULL; - Cpa8U *pBuff = NULL; - struct stat st = { 0 }; - long file_size = 0; - - /* Get filesize */ - if (0 != stat(filename, &st)) - { - PRINT_ERR("Could not get the file %s size\n", filename); - return CPA_STATUS_FAIL; - } - file_size = st.st_size; - - /* Allocate memory for the file */ - pBuff = (Cpa8U *)qaeMemAlloc(file_size); - if (NULL == pBuff) - { - PRINT_ERR("Could not allocate memory for the file copy\n"); - return CPA_STATUS_FAIL; - } - - memset(pBuff, 0, file_size); - /* Open the file */ - srcFile = fopen((const char *)filename, "r"); - if (NULL == (srcFile)) - { - PRINT_ERR("Could not open source file %s\n", filename); - qaeMemFree((void **)&pBuff); - return CPA_STATUS_FAIL; - } - - /* Read the file */ - *(file_data->bufferSize) = fread(pBuff, 1, file_size, srcFile); - if (*(file_data->bufferSize) != file_size) - { - PRINT_ERR("Filesize doesn't match\n"); - qaeMemFree((void **)&pBuff); - fclose(srcFile); - return CPA_STATUS_FAIL; - } - - fclose(srcFile); - *(file_data->pSrcData) = pBuff; - return CPA_STATUS_SUCCESS; -} - -/* Free the memory after getting the file and copying the data */ -CpaStatus sample_freeFile(file_data_t *file_data) -{ - qaeMemFree((void **)(file_data->pSrcData)); - return CPA_STATUS_SUCCESS; -} - /* Forward declaration */ CpaStatus hashFileSample(void); @@ -156,6 +94,8 @@ static CpaStatus hashPerformOp(CpaInstanceHandle cyInstHandle, CpaCySymCapabilitiesInfo symCapInfo = { 0 }; file_data_t inputData = { 0 }; CpaFlatBuffer inputBuffer = { 0 }; + struct stat st = { 0 }; + int fd = -1; /* The following variables are allocated on the stack because we block * until the callback comes back. If a non-blocking approach was to be @@ -192,16 +132,42 @@ static CpaStatus hashPerformOp(CpaInstanceHandle cyInstHandle, PRINT_DBG( "Partial packets are not supported, using full packets instead.\n"); - inputData.bufferSize = &inputBuffer.dataLenInBytes; - inputData.pSrcData = &inputBuffer.pData; - status = sample_getFile(gFileName, &inputData); + fd = fileno(srcFile); + if (fd < 0 || fstat(fd, &st) != 0) + { + PRINT_ERR("Could not get file size\n"); + fclose(srcFile); + return CPA_STATUS_FAIL; + } + /* Validate file size is non-negative */ + if (st.st_size <= 0) + { + PRINT_ERR("Invalid file size\n"); + fclose(srcFile); + return CPA_STATUS_FAIL; + } + /* Allocate memory for the entire file */ + inputBuffer.pData = (Cpa8U *)qaeMemAlloc(st.st_size); + if (NULL == inputBuffer.pData) + { + PRINT_ERR("Could not allocate memory for the file copy\n"); + fclose(srcFile); + return CPA_STATUS_FAIL; + } - if (status != CPA_STATUS_SUCCESS) + /* Read the entire file using the already-opened handle */ + inputBuffer.dataLenInBytes = + fread(inputBuffer.pData, 1, st.st_size, srcFile); + if (inputBuffer.dataLenInBytes != st.st_size) { - PRINT_ERR("sample_getFile failed\n"); + PRINT_ERR("Failed to read complete file\n"); + qaeMemFree((void **)&inputBuffer.pData); fclose(srcFile); - return status; + return CPA_STATUS_FAIL; } + + inputData.bufferSize = &inputBuffer.dataLenInBytes; + inputData.pSrcData = &inputBuffer.pData; bufferSize = inputBuffer.dataLenInBytes; } diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample.c similarity index 81% rename from quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample.c rename to quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample.c index 61117677..ecafab48 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample.c @@ -1,448 +1,433 @@ -/*************************************************************************** - * +/*************************************************************************** + * * SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2007-2026 Intel Corporation * * These contents may have been developed with support from one or more * Intel-operated generative artificial intelligence solutions. - * - ***************************************************************************/ -/* - * This is sample code that demonstrates usage of the symmetric API, and - * specifically using this API to perform a ZUC operation. For more information - * on ZUC please reference The ZUC-256 Stream Cipher " - * http://www.is.cas.cn/ztzl2016/zouchongzhi/201801/W020180126529970733243.pdf" - */ - -#include "cpa.h" -#include "cpa_cy_im.h" -#include "cpa_cy_sym.h" - -#include "cpa_sample_utils.h" - -#define DIGEST_LENGTH 16 -#define TIMEOUT_MS 5000 /* 5 seconds*/ - -extern int gDebugParam; -/* ZUC cipher key, 256 bits long */ -static Cpa8U sampleCipherKey[] = { - 0x7A, 0x8A, 0x5C, 0x43, 0x35, 0x87, 0x48, 0xE8, 0x3C, 0xFC, 0x05, 0x5B, - 0xA7, 0xC1, 0x32, 0x72, 0xA1, 0x0A, 0xAE, 0x97, 0x92, 0x46, 0x62, 0xB9, - 0x2C, 0xDF, 0xE4, 0x26, 0xAA, 0xD6, 0x09, 0x24}; -/* Initialization vector */ -static Cpa8U sampleCipherIv[] = { - 0x24, 0xF0, 0x41, 0x1D, 0x2E, 0xA4, 0xAC, 0x7F, 0x63, 0x3E, 0xB7, 0x9F, - 0xC3, 0x1C, 0xD1, 0x8D, 0xAF, 0xDD, 0x20, 0x80, 0xAE, 0x96, 0xAD, 0xFF}; -/* ZUC authentication key, 256 bits long */ -static Cpa8U sampleAuthKey[] = { - 0xBF, 0xC1, 0xC4, 0x0F, 0x56, 0xE8, 0xC6, 0x53, 0x19, 0xA6, 0xBB, 0xEE, - 0xF2, 0x96, 0x0A, 0xFD, 0x4C, 0xF6, 0x64, 0xA3, 0xFE, 0x0A, 0x2A, 0x8A, - 0x14, 0x79, 0x67, 0xC0, 0xD3, 0xEC, 0xA4, 0x92}; - -/* Source data to encrypt */ -static Cpa8U samplePayload[] = { - 0x44, 0x09, 0xB5, 0xC3, 0xDD, 0x3E, 0x3D, 0x29, 0x09, 0xEF, 0x0E, 0x9F, - 0xA6, 0xED, 0x0C, 0x92, 0xFD, 0xFD, 0xAD, 0x06, 0x88, 0x03, 0xE6, 0x98, - 0x47, 0xD8, 0x5D, 0x9F, 0x34, 0x81, 0x0F, 0x79, 0x8B, 0xC5, 0x3C, 0x68, - 0x03, 0x79, 0x91, 0x0C, 0x68, 0xA0, 0xAB, 0x0F, 0x8D, 0xB7, 0xA1, 0x8A, - 0xB4, 0x4E, 0x90, 0x3D, 0x52, 0x77, 0xD5, 0x99, 0x4F, 0x32, 0x38, 0x84, - 0xB3, 0x47, 0xFD, 0x3E, 0x0C, 0x39, 0xA6, 0x0F, 0xB3, 0x38, 0x1C, 0x1B, - 0xD8, 0xC7, 0x2A, 0x65, 0x7F, 0xCC, 0xF0, 0x33, 0x1A, 0x80, 0x70, 0x6C, - 0xF7, 0x45, 0x05, 0x47, 0x77, 0x3D, 0xCB, 0x2B, 0x85, 0xC8, 0x69, 0x91, - 0x01, 0x10, 0xA1, 0xB4, 0x48, 0xBD, 0xD0, 0x20, 0x84, 0xFA, 0x85, 0x03, - 0xC6, 0x75, 0x37, 0xE1, 0xF6, 0xA7, 0x4D, 0xED, 0xED, 0x53, 0x34, 0x64, - 0x90, 0xFF, 0x8F, 0x15, 0xC7, 0xF9, 0xA7, 0xC9}; - -/* Expected output of the operation */ -static Cpa8U expectedOutput[] = { - 0x09, 0x5F, 0x1C, 0xF7, 0x08, 0x29, 0xC8, 0xED, 0x67, 0xF1, 0xAC, 0x29, - 0xE1, 0x02, 0x2F, 0xA0, 0x1A, 0xC4, 0x8B, 0x72, 0x9B, 0xE9, 0xF0, 0xFD, - 0x50, 0xE9, 0xBB, 0x73, 0x5B, 0xBA, 0x5C, 0x26, 0x32, 0xE8, 0x92, 0x98, - 0xEC, 0xCB, 0x14, 0x85, 0x23, 0xF3, 0x5C, 0x5A, 0x4B, 0x79, 0xED, 0xD2, - 0x57, 0xF8, 0xD6, 0xB3, 0x82, 0x1F, 0x44, 0x84, 0x9E, 0x7C, 0x09, 0xC7, - 0xAC, 0x4D, 0x48, 0x62, 0xA6, 0xDB, 0x23, 0x14, 0x61, 0x2F, 0xB3, 0x17, - 0x87, 0x21, 0x51, 0xD3, 0x63, 0x66, 0x22, 0xC9, 0x0F, 0xC9, 0x8F, 0xE4, - 0x6B, 0x99, 0x63, 0x61, 0x57, 0xD5, 0x5D, 0xEE, 0xF7, 0x19, 0x8E, 0xCD, - 0x45, 0xB5, 0xB3, 0x38, 0x81, 0x18, 0xE8, 0xA5, 0x45, 0xA1, 0x54, 0xF1, - 0x47, 0x3D, 0xDE, 0x1A, 0x6A, 0x43, 0x78, 0x68, 0x30, 0x03, 0xF6, 0xF8, - 0x46, 0x28, 0xC4, 0xC7, 0xE7, 0x1D, 0x64, 0xA4, 0xC3, 0xEE, 0xD1, 0x53, - 0xD2, 0x17, 0x97, 0x3E, 0x9E, 0x3A, 0x58, 0x0C, 0x09, 0xE9, 0x82, 0xB5}; -/* Association data */ -static Cpa8U sampleAssocData[] = { - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, - 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}; -CpaStatus algChainSample(void); - -/* - * Callback function - * - * This function is "called back" (invoked by the implementation of - * the API) when the asynchronous operation has completed. The - * context in which it is invoked depends on the implementation, but - * as described in the API it should not sleep (since it may be called - * in a context which does not permit sleeping, e.g. a Linux bottom - * half). - * - * This function can perform whatever processing is appropriate to the - * application. For example, it may free memory, continue processing - * of a decrypted packet, etc. In this example, the function only - * sets the complete variable to indicate it has been called. - */ -static void symCallback(void *pCallbackTag, - CpaStatus status, - const CpaCySymOp operationType, - void *pOpData, - CpaBufferList *pDstBuffer, - CpaBoolean verifyResult) -{ - PRINT_DBG("Callback called with status = %d.\n", status); - - if (NULL != pCallbackTag) - { - /** indicate that the function has been called */ - COMPLETE((struct COMPLETION_STRUCT *)pCallbackTag); - } -} - -/* - * Perform an algorithm chaining operation (cipher + hash) - */ -static CpaStatus algChainPerformOpZUC(CpaInstanceHandle cyInstHandle, - CpaCySymSessionCtx sessionCtx) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - Cpa8U *pBufferMeta = NULL; - Cpa32U bufferMetaSize = 0; - CpaBufferList *pBufferList = NULL; - CpaFlatBuffer *pFlatBuffer = NULL; - CpaCySymOpData *pOpData = NULL; - Cpa32U bufferSize = sizeof(samplePayload) + DIGEST_LENGTH; - Cpa32U aadBuffSize = sizeof(sampleAssocData); - Cpa32U numBuffers = 1; /* only using 1 buffer in this case */ - /* allocate memory for bufferlist and array of flat buffers in a contiguous - * area and carve it up to reduce number of memory allocations required. */ - Cpa32U bufferListMemSize = - sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer)); - Cpa8U *pSrcBuffer = NULL; - Cpa8U *pIvBuffer = NULL; - Cpa8U *pAadBuffer = NULL; - CpaInstanceInfo2 instanceInfo2; - - /* The following variables are allocated on the stack because we block - * until the callback comes back. If a non-blocking approach was to be - * used then these variables should be dynamically allocated */ - struct COMPLETION_STRUCT complete; - - COMPLETION_INIT(&complete); // Initialize the completion variable - - /* get meta information size */ - PRINT_DBG("cpaCyBufferListGetMetaSize\n"); - status = - cpaCyBufferListGetMetaSize(cyInstHandle, numBuffers, &bufferMetaSize); - - if (CPA_STATUS_SUCCESS == status) - { - status = PHYS_CONTIG_ALLOC(&pBufferMeta, bufferMetaSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - status = OS_MALLOC(&pBufferList, bufferListMemSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - status = PHYS_CONTIG_ALLOC(&pSrcBuffer, bufferSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - status = PHYS_CONTIG_ALLOC(&pIvBuffer, sizeof(sampleCipherIv)); - } - - if (CPA_STATUS_SUCCESS == status) - { - /* copy source into buffer */ - memcpy(pSrcBuffer, samplePayload, sizeof(samplePayload)); - - /* copy IV into buffer */ - memcpy(pIvBuffer, sampleCipherIv, sizeof(sampleCipherIv)); - - /* increment by sizeof(CpaBufferList) to get at the - * array of flatbuffers */ - pFlatBuffer = (CpaFlatBuffer *)(pBufferList + 1); - - pBufferList->pBuffers = pFlatBuffer; - pBufferList->numBuffers = 1; - pBufferList->pPrivateMetaData = pBufferMeta; - - pFlatBuffer->dataLenInBytes = bufferSize; - pFlatBuffer->pData = pSrcBuffer; - - status = OS_MALLOC(&pOpData, sizeof(CpaCySymOpData)); - } - - if (CPA_STATUS_SUCCESS == status) - { - aadBuffSize = sizeof(sampleAssocData); - status = PHYS_CONTIG_ALLOC(&pAadBuffer, aadBuffSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - memcpy(pAadBuffer, sampleAssocData, sizeof(sampleAssocData)); - } - - if (CPA_STATUS_SUCCESS == status) - { - status = cpaCyInstanceGetInfo2(cyInstHandle, &instanceInfo2); - } - - if (CPA_STATUS_SUCCESS != status) - { - PRINT_DBG("sampleCodeCyGetNode error, status: %d\n", status); - status = CPA_STATUS_FAIL; - } - - if (CPA_STATUS_SUCCESS == status) - { - // - /** Populate the structure containing the operational data that is - * needed to run the algorithm - */ - pOpData->sessionCtx = sessionCtx; - pOpData->packetType = CPA_CY_SYM_PACKET_TYPE_FULL; - pOpData->pIv = pIvBuffer; - pOpData->ivLenInBytes = sizeof(sampleCipherIv); - pOpData->cryptoStartSrcOffsetInBytes = 0; - pOpData->hashStartSrcOffsetInBytes = 0; - pOpData->messageLenToCipherInBytes = sizeof(samplePayload); - pOpData->messageLenToHashInBytes = sizeof(samplePayload); - pOpData->pAdditionalAuthData = pAadBuffer; - // - /* pDigestResult does need need to be set as digestIsAppended - was set at sessionInit */ - } - - if (CPA_STATUS_SUCCESS == status) - { - PRINT_DBG("cpaCySymPerformOp\n"); - - /** Perform symmetric operation */ - status = cpaCySymPerformOp( - cyInstHandle, - (void *)&complete, /* data sent as is to the callback function*/ - pOpData, /* operational data struct */ - pBufferList, /* source buffer list */ - pBufferList, /* same src & dst for an in-place operation*/ - NULL); - - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("cpaCySymPerformOp failed. (status = %d)\n", status); - } - - if (CPA_STATUS_SUCCESS == status) - { - /** wait until the completion of the operation*/ - if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) - { - PRINT_ERR("timeout or interruption in cpaCySymPerformOp\n"); - status = CPA_STATUS_FAIL; - } - } - - if (CPA_STATUS_SUCCESS == status) - { - if (0 == memcmp(pSrcBuffer, expectedOutput, bufferSize)) - { - PRINT_DBG("Output matches expected output\n"); - } - else - { - PRINT_DBG("Output does not match expected output\n"); - status = CPA_STATUS_FAIL; - } - } - } - - /* at this stage, the callback function has returned, so it is sure that - * the structures won't be needed any more*/ - PHYS_CONTIG_FREE(pSrcBuffer); - PHYS_CONTIG_FREE(pIvBuffer); - PHYS_CONTIG_FREE(pAadBuffer); - OS_FREE(pBufferList); - PHYS_CONTIG_FREE(pBufferMeta); - OS_FREE(pOpData); - - COMPLETION_DESTROY(&complete); - - return status; -} - -CpaStatus algChainSample(void) -{ - CpaStatus status = CPA_STATUS_FAIL; - CpaCySymSessionCtx sessionCtx = NULL; - Cpa32U sessionCtxSize = 0; - CpaInstanceHandle cyInstHandle = NULL; - CpaCySymSessionSetupData sessionSetupData; - CpaCySymStats64 symStats; - CpaCySymCapabilitiesInfo symCapInfo = { { 0 } }; - memset(&sessionSetupData, 0, sizeof(CpaCySymSessionSetupData)); - memset(&symStats, 0, sizeof(CpaCySymStats64)); - - /* - * In this simplified version of instance discovery, we discover - * exactly one instance of a crypto service. - */ - sampleSymGetInstance(&cyInstHandle); - if (cyInstHandle == NULL) - { - return CPA_STATUS_FAIL; - } - - status = cpaCySymQueryCapabilities(cyInstHandle, &symCapInfo); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Failed to query capabilities, status = %d\n", status); - return status; - } - /* Check capabilities before running the test */ - if ((!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, - CPA_CY_SYM_CIPHER_ZUC_EEA3)) || - (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, CPA_CY_SYM_HASH_ZUC_EIA3))) - { - PRINT("ZUC algorithm chaining not supported on Instance\n"); - return CPA_STATUS_UNSUPPORTED; - } - - /* Start Cryptographic component */ - PRINT_DBG("cpaCyStartInstance\n"); - status = cpaCyStartInstance(cyInstHandle); - - if (CPA_STATUS_SUCCESS == status) - { - /* - * Set the address translation function for the instance - */ - status = cpaCySetAddressTranslation(cyInstHandle, sampleVirtToPhys); - } - - if (CPA_STATUS_SUCCESS == status) - { - /* - * If the instance is polled start the polling thread. Note that - * how the polling is done is implementation-dependent. - */ - sampleCyStartPolling(cyInstHandle); - - /* populate symmetric session data structure */ - sessionSetupData.sessionPriority = CPA_CY_PRIORITY_NORMAL; - // - sessionSetupData.symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; - sessionSetupData.algChainOrder = - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH; - - sessionSetupData.cipherSetupData.cipherAlgorithm = - CPA_CY_SYM_CIPHER_ZUC_EEA3; - sessionSetupData.cipherSetupData.pCipherKey = sampleCipherKey; - sessionSetupData.cipherSetupData.cipherKeyLenInBytes = - sizeof(sampleCipherKey); - sessionSetupData.cipherSetupData.cipherDirection = - CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT; - - sessionSetupData.hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_ZUC_EIA3; - sessionSetupData.hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_AUTH; - sessionSetupData.hashSetupData.digestResultLenInBytes = DIGEST_LENGTH; - sessionSetupData.hashSetupData.authModeSetupData.authKey = - sampleAuthKey; - sessionSetupData.hashSetupData.authModeSetupData.authKeyLenInBytes = - sizeof(sampleAuthKey); - sessionSetupData.hashSetupData.authModeSetupData.aadLenInBytes = 24; - - /* The resulting MAC is to be placed immediately after the ciphertext */ - sessionSetupData.digestIsAppended = CPA_TRUE; - sessionSetupData.verifyDigest = CPA_FALSE; - // - - /* Determine size of session context to allocate */ - PRINT_DBG("cpaCySymSessionCtxGetSize\n"); - status = cpaCySymSessionCtxGetSize( - cyInstHandle, &sessionSetupData, &sessionCtxSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - /* Allocate session context */ - status = PHYS_CONTIG_ALLOC(&sessionCtx, sessionCtxSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - /* Initialize the session */ - PRINT_DBG("cpaCySymInitSession\n"); - status = cpaCySymInitSession( - cyInstHandle, symCallback, &sessionSetupData, sessionCtx); - } - - if (CPA_STATUS_SUCCESS == status) - { - CpaStatus sessionStatus = CPA_STATUS_SUCCESS; - - /* Perform algchaining operation */ - status = algChainPerformOpZUC(cyInstHandle, sessionCtx); - - /* Wait for inflight requests before removing session */ - symSessionWaitForInflightReq(sessionCtx); - - /* Remove the session - session init has already succeeded */ - PRINT_DBG("cpaCySymRemoveSession\n"); - sessionStatus = cpaCySymRemoveSession(cyInstHandle, sessionCtx); - - /* maintain status of remove session only when status of all operations - * before it are successful. */ - if (CPA_STATUS_SUCCESS == status) - { - status = sessionStatus; - } - } - - if (CPA_STATUS_SUCCESS == status) - { - /* Query symmetric statistics */ - status = cpaCySymQueryStats64(cyInstHandle, &symStats); - - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("cpaCySymQueryStats failed, status = %d\n", status); - } - else - { - PRINT_DBG("Number of symmetric operation completed: %llu\n", - (long long unsigned int)symStats.numSymOpCompleted); - } - } - - /* Clean up */ - - /* Free session Context */ - PHYS_CONTIG_FREE(sessionCtx); - - /* Stop the polling thread */ - sampleCyStopPolling(); - - PRINT_DBG("cpaCyStopInstance\n"); - cpaCyStopInstance(cyInstHandle); - - if (CPA_STATUS_SUCCESS == status) - { - PRINT_DBG("Sample code ran successfully\n"); - } - else - { - PRINT_DBG("Sample code failed with status of %d\n", status); - } - - return status; -} + * + ***************************************************************************/ +/* + * This is sample code that demonstrates usage of the symmetric API, and + * specifically using this API to perform a ZUC-128 operation. + */ + +#include "cpa.h" +#include "cpa_cy_im.h" +#include "cpa_cy_sym.h" + +#include "cpa_sample_utils.h" + +#define DIGEST_LENGTH 4 +#define TIMEOUT_MS 5000 /* 5 seconds*/ + +extern int gDebugParam; +/* ZUC cipher key, 256 bits long */ +static Cpa8U sampleCipherKey[] = { + 0x9F, 0x0E, 0xD2, 0xF0, 0x83, 0x39, 0x12, 0x28, 0xB7, 0x03, 0xA9, 0x4B, + 0xF6, 0x75, 0x73, 0x48}; +/* Initialization vector */ +static Cpa8U sampleCipherIv[] = { + 0x70, 0xB3, 0xFB, 0xE9, 0x91, 0xCB, 0x49, 0x10, 0xDC, 0x81, 0x27, 0x1D, + 0x60, 0xB5, 0x10, 0x4A}; +/* ZUC authentication key, 256 bits long */ +static Cpa8U sampleAuthKey[] = { + 0xCB, 0xB6, 0xE5, 0x0E, 0xD0, 0x65, 0xF3, 0x55, 0x62, 0xED, 0x2B, 0x6B, + 0xD7, 0x6A, 0xC8, 0xFB}; + +/* Source data to encrypt */ +static Cpa8U samplePayload[] = { + 0x65, 0x49, 0xC3, 0xD3, 0x10, 0x73, 0x95, 0xEE, 0x0F, 0x54, 0xA1, 0x83, + 0x24, 0xD9, 0xAB, 0xB1, 0x67, 0x8B, 0xA8, 0xBE, 0x4D, 0xE2, 0x62, 0x7A, + 0x21, 0x37, 0x99, 0x61, 0xAE, 0xBF, 0x7E, 0x82, 0x58, 0x88, 0xA6, 0x2A, + 0xA3, 0x59, 0x9E, 0x42, 0x59, 0x11, 0xCF, 0x8D, 0x91, 0xAE, 0x27, 0xA8, + 0x7A, 0xB2, 0x05, 0x9A, 0x41, 0xC0, 0x83, 0x15, 0xBA, 0xE8, 0x91, 0x5B, + 0x01, 0xEE, 0x5D, 0x36}; + +/* Expected output of the operation */ +static Cpa8U expectedOutput[] = { + 0x94, 0xC0, 0x31, 0x5D, 0x2E, 0x0F, 0xCC, 0x1C, 0x94, 0x6A, 0x18, 0xE6, + 0x12, 0xCD, 0x6F, 0x14, 0x05, 0xC7, 0x2C, 0x2E, 0xE0, 0x50, 0xD2, 0xF4, + 0x5E, 0x23, 0x1F, 0x92, 0x6E, 0x48, 0xD7, 0x90, 0xC4, 0xF9, 0xE3, 0xF0, + 0x97, 0x18, 0x21, 0xE9, 0x19, 0x2E, 0xBA, 0x79, 0x12, 0x55, 0x65, 0xD8, + 0x6E, 0xD1, 0xD7, 0x85, 0x45, 0xE6, 0xC9, 0xB0, 0x0E, 0x82, 0x04, 0xCE, + 0x16, 0xBB, 0x89, 0xC9, 0xE6, 0x57, 0xD1, 0x4C}; +/* Association data */ +static Cpa8U sampleAssocData[] = { + 0xA5, 0x19, 0x66, 0x4D, 0x66, 0x38, 0x27, 0x9B, 0xB3, 0x76, 0xCA, 0xE1, + 0x0F, 0xAE, 0x67, 0xBE}; +CpaStatus algChainSample(void); + +/* + * Callback function + * + * This function is "called back" (invoked by the implementation of + * the API) when the asynchronous operation has completed. The + * context in which it is invoked depends on the implementation, but + * as described in the API it should not sleep (since it may be called + * in a context which does not permit sleeping, e.g. a Linux bottom + * half). + * + * This function can perform whatever processing is appropriate to the + * application. For example, it may free memory, continue processing + * of a decrypted packet, etc. In this example, the function only + * sets the complete variable to indicate it has been called. + */ +static void symCallback(void *pCallbackTag, + CpaStatus status, + const CpaCySymOp operationType, + void *pOpData, + CpaBufferList *pDstBuffer, + CpaBoolean verifyResult) +{ + PRINT_DBG("Callback called with status = %d.\n", status); + + if (NULL != pCallbackTag) + { + /** indicate that the function has been called */ + COMPLETE((struct COMPLETION_STRUCT *)pCallbackTag); + } +} + +/* + * Perform an algorithm chaining operation (cipher + hash) + */ +static CpaStatus algChainPerformOpZUC(CpaInstanceHandle cyInstHandle, + CpaCySymSessionCtx sessionCtx) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa8U *pBufferMeta = NULL; + Cpa32U bufferMetaSize = 0; + CpaBufferList *pBufferList = NULL; + CpaFlatBuffer *pFlatBuffer = NULL; + CpaCySymOpData *pOpData = NULL; + Cpa32U bufferSize = sizeof(samplePayload) + DIGEST_LENGTH; + Cpa32U aadBuffSize = sizeof(sampleAssocData); + Cpa32U numBuffers = 1; /* only using 1 buffer in this case */ + /* allocate memory for bufferlist and array of flat buffers in a contiguous + * area and carve it up to reduce number of memory allocations required. */ + Cpa32U bufferListMemSize = + sizeof(CpaBufferList) + (numBuffers * sizeof(CpaFlatBuffer)); + Cpa8U *pSrcBuffer = NULL; + Cpa8U *pIvBuffer = NULL; + Cpa8U *pAadBuffer = NULL; + CpaInstanceInfo2 instanceInfo2; + + /* The following variables are allocated on the stack because we block + * until the callback comes back. If a non-blocking approach was to be + * used then these variables should be dynamically allocated */ + struct COMPLETION_STRUCT complete; + + COMPLETION_INIT(&complete); // Initialize the completion variable + + /* get meta information size */ + PRINT_DBG("cpaCyBufferListGetMetaSize\n"); + status = + cpaCyBufferListGetMetaSize(cyInstHandle, numBuffers, &bufferMetaSize); + + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pBufferMeta, bufferMetaSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = OS_MALLOC(&pBufferList, bufferListMemSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pSrcBuffer, bufferSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = PHYS_CONTIG_ALLOC(&pIvBuffer, sizeof(sampleCipherIv)); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* copy source into buffer */ + memcpy(pSrcBuffer, samplePayload, sizeof(samplePayload)); + + /* copy IV into buffer */ + memcpy(pIvBuffer, sampleCipherIv, sizeof(sampleCipherIv)); + + /* increment by sizeof(CpaBufferList) to get at the + * array of flatbuffers */ + pFlatBuffer = (CpaFlatBuffer *)(pBufferList + 1); + + pBufferList->pBuffers = pFlatBuffer; + pBufferList->numBuffers = 1; + pBufferList->pPrivateMetaData = pBufferMeta; + + pFlatBuffer->dataLenInBytes = bufferSize; + pFlatBuffer->pData = pSrcBuffer; + + status = OS_MALLOC(&pOpData, sizeof(CpaCySymOpData)); + } + + if (CPA_STATUS_SUCCESS == status) + { + aadBuffSize = sizeof(sampleAssocData); + status = PHYS_CONTIG_ALLOC(&pAadBuffer, aadBuffSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + memcpy(pAadBuffer, sampleAssocData, sizeof(sampleAssocData)); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = cpaCyInstanceGetInfo2(cyInstHandle, &instanceInfo2); + } + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_DBG("sampleCodeCyGetNode error, status: %d\n", status); + status = CPA_STATUS_FAIL; + } + + if (CPA_STATUS_SUCCESS == status) + { + // + /** Populate the structure containing the operational data that is + * needed to run the algorithm + */ + pOpData->sessionCtx = sessionCtx; + pOpData->packetType = CPA_CY_SYM_PACKET_TYPE_FULL; + pOpData->pIv = pIvBuffer; + pOpData->ivLenInBytes = sizeof(sampleCipherIv); + pOpData->cryptoStartSrcOffsetInBytes = 0; + pOpData->hashStartSrcOffsetInBytes = 0; + pOpData->messageLenToCipherInBytes = sizeof(samplePayload); + pOpData->messageLenToHashInBytes = sizeof(samplePayload); + pOpData->pAdditionalAuthData = pAadBuffer; + // + /* pDigestResult does need need to be set as digestIsAppended + was set at sessionInit */ + } + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("cpaCySymPerformOp\n"); + + /** Perform symmetric operation */ + status = cpaCySymPerformOp( + cyInstHandle, + (void *)&complete, /* data sent as is to the callback function*/ + pOpData, /* operational data struct */ + pBufferList, /* source buffer list */ + pBufferList, /* same src & dst for an in-place operation*/ + NULL); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCySymPerformOp failed. (status = %d)\n", status); + } + + if (CPA_STATUS_SUCCESS == status) + { + /** wait until the completion of the operation*/ + if (!COMPLETION_WAIT(&complete, TIMEOUT_MS)) + { + PRINT_ERR("timeout or interruption in cpaCySymPerformOp\n"); + status = CPA_STATUS_FAIL; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + if (0 == memcmp(pSrcBuffer, expectedOutput, bufferSize)) + { + PRINT_DBG("Output matches expected output\n"); + } + else + { + PRINT_DBG("Output does not match expected output\n"); + status = CPA_STATUS_FAIL; + } + } + } + + /* at this stage, the callback function has returned, so it is sure that + * the structures won't be needed any more*/ + PHYS_CONTIG_FREE(pSrcBuffer); + PHYS_CONTIG_FREE(pIvBuffer); + PHYS_CONTIG_FREE(pAadBuffer); + OS_FREE(pBufferList); + PHYS_CONTIG_FREE(pBufferMeta); + OS_FREE(pOpData); + + COMPLETION_DESTROY(&complete); + + return status; +} + +CpaStatus algChainSample(void) +{ + CpaStatus status = CPA_STATUS_FAIL; + CpaCySymSessionCtx sessionCtx = NULL; + Cpa32U sessionCtxSize = 0; + CpaInstanceHandle cyInstHandle = NULL; + CpaCySymSessionSetupData sessionSetupData; + CpaCySymStats64 symStats; + CpaCySymCapabilitiesInfo symCapInfo = { { 0 } }; + memset(&sessionSetupData, 0, sizeof(CpaCySymSessionSetupData)); + memset(&symStats, 0, sizeof(CpaCySymStats64)); + + /* + * In this simplified version of instance discovery, we discover + * exactly one instance of a crypto service. + */ + sampleSymGetInstance(&cyInstHandle); + if (cyInstHandle == NULL) + { + return CPA_STATUS_FAIL; + } + + status = cpaCySymQueryCapabilities(cyInstHandle, &symCapInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to query capabilities, status = %d\n", status); + return status; + } + /* Check capabilities before running the test */ + if ((!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, + CPA_CY_SYM_CIPHER_ZUC_EEA3)) || + (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, CPA_CY_SYM_HASH_ZUC_EIA3))) + { + PRINT("ZUC algorithm chaining not supported on Instance\n"); + return CPA_STATUS_UNSUPPORTED; + } + + /* Start Cryptographic component */ + PRINT_DBG("cpaCyStartInstance\n"); + status = cpaCyStartInstance(cyInstHandle); + + if (CPA_STATUS_SUCCESS == status) + { + /* + * Set the address translation function for the instance + */ + status = cpaCySetAddressTranslation(cyInstHandle, sampleVirtToPhys); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* + * If the instance is polled start the polling thread. Note that + * how the polling is done is implementation-dependent. + */ + sampleCyStartPolling(cyInstHandle); + + /* populate symmetric session data structure */ + sessionSetupData.sessionPriority = CPA_CY_PRIORITY_NORMAL; + // + sessionSetupData.symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; + sessionSetupData.algChainOrder = + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH; + + sessionSetupData.cipherSetupData.cipherAlgorithm = + CPA_CY_SYM_CIPHER_ZUC_EEA3; + sessionSetupData.cipherSetupData.pCipherKey = sampleCipherKey; + sessionSetupData.cipherSetupData.cipherKeyLenInBytes = + sizeof(sampleCipherKey); + sessionSetupData.cipherSetupData.cipherDirection = + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT; + + sessionSetupData.hashSetupData.hashAlgorithm = CPA_CY_SYM_HASH_ZUC_EIA3; + sessionSetupData.hashSetupData.hashMode = CPA_CY_SYM_HASH_MODE_AUTH; + sessionSetupData.hashSetupData.digestResultLenInBytes = DIGEST_LENGTH; + sessionSetupData.hashSetupData.authModeSetupData.authKey = + sampleAuthKey; + sessionSetupData.hashSetupData.authModeSetupData.authKeyLenInBytes = + sizeof(sampleAuthKey); + sessionSetupData.hashSetupData.authModeSetupData.aadLenInBytes = 16; + + /* The resulting MAC is to be placed immediately after the ciphertext */ + sessionSetupData.digestIsAppended = CPA_TRUE; + sessionSetupData.verifyDigest = CPA_FALSE; + // + + /* Determine size of session context to allocate */ + PRINT_DBG("cpaCySymSessionCtxGetSize\n"); + status = cpaCySymSessionCtxGetSize( + cyInstHandle, &sessionSetupData, &sessionCtxSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Allocate session context */ + status = PHYS_CONTIG_ALLOC(&sessionCtx, sessionCtxSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Initialize the session */ + PRINT_DBG("cpaCySymInitSession\n"); + status = cpaCySymInitSession( + cyInstHandle, symCallback, &sessionSetupData, sessionCtx); + } + + if (CPA_STATUS_SUCCESS == status) + { + CpaStatus sessionStatus = CPA_STATUS_SUCCESS; + + /* Perform algchaining operation */ + status = algChainPerformOpZUC(cyInstHandle, sessionCtx); + + /* Wait for inflight requests before removing session */ + symSessionWaitForInflightReq(sessionCtx); + + /* Remove the session - session init has already succeeded */ + PRINT_DBG("cpaCySymRemoveSession\n"); + sessionStatus = cpaCySymRemoveSession(cyInstHandle, sessionCtx); + + /* maintain status of remove session only when status of all operations + * before it are successful. */ + if (CPA_STATUS_SUCCESS == status) + { + status = sessionStatus; + } + } + + if (CPA_STATUS_SUCCESS == status) + { + /* Query symmetric statistics */ + status = cpaCySymQueryStats64(cyInstHandle, &symStats); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCySymQueryStats failed, status = %d\n", status); + } + else + { + PRINT_DBG("Number of symmetric operation completed: %llu\n", + (long long unsigned int)symStats.numSymOpCompleted); + } + } + + /* Clean up */ + + /* Free session Context */ + PHYS_CONTIG_FREE(sessionCtx); + + /* Stop the polling thread */ + sampleCyStopPolling(); + + PRINT_DBG("cpaCyStopInstance\n"); + cpaCyStopInstance(cyInstHandle); + + if (CPA_STATUS_SUCCESS == status) + { + PRINT_DBG("Sample code ran successfully\n"); + } + else + { + PRINT_DBG("Sample code failed with status of %d\n", status); + } + + return status; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample_user.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample_user.c similarity index 84% rename from quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample_user.c rename to quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample_user.c index e8f80655..a62745db 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/cpa_zuc_sample_user.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/zuc_sample/zuc128_sample/cpa_zuc128_sample_user.c @@ -1,64 +1,64 @@ -/****************************************************************************** - * +/****************************************************************************** + * * SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2007-2026 Intel Corporation * * These contents may have been developed with support from one or more * Intel-operated generative artificial intelligence solutions. - * - *****************************************************************************/ - -/** - ****************************************************************************** - * @file cpa_zuc_sample_user.c - * - *****************************************************************************/ -#include "cpa_sample_utils.h" -#include "icp_sal_user.h" - -extern CpaStatus algChainSample(void); - -int gDebugParam = 1; - -int main(int argc, const char **argv) -{ - CpaStatus stat = CPA_STATUS_SUCCESS; - - if (argc > 1) - { - gDebugParam = atoi(argv[1]); - } - - PRINT_DBG("Starting ZUC Sample Code App ...\n"); - - stat = qaeMemInit(); - if (CPA_STATUS_SUCCESS != stat) - { - PRINT_ERR("Failed to initialize memory driver\n"); - return (int)stat; - } - - stat = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); - if (CPA_STATUS_SUCCESS != stat) - { - PRINT_ERR("Failed to start user process SSL\n"); - qaeMemDestroy(); - return (int)stat; - } - - stat = algChainSample(); - if ((CPA_STATUS_SUCCESS != stat) && (CPA_STATUS_UNSUPPORTED != stat)) - { - PRINT_ERR("\nZUC Sample Code App failed\n"); - } - else - { - PRINT_DBG("\nZUC Sample Code App finished\n"); - } - - icp_sal_userStop(); - - qaeMemDestroy(); - - return (int)stat; -} + * + *****************************************************************************/ + +/** + ****************************************************************************** + * @file cpa_zuc128_sample_user.c + * + *****************************************************************************/ +#include "cpa_sample_utils.h" +#include "icp_sal_user.h" + +extern CpaStatus algChainSample(void); + +int gDebugParam = 1; + +int main(int argc, const char **argv) +{ + CpaStatus stat = CPA_STATUS_SUCCESS; + + if (argc > 1) + { + gDebugParam = atoi(argv[1]); + } + + PRINT_DBG("Starting ZUC-128 Sample Code App ...\n"); + + stat = qaeMemInit(); + if (CPA_STATUS_SUCCESS != stat) + { + PRINT_ERR("Failed to initialize memory driver\n"); + return (int)stat; + } + + stat = icp_sal_userStartMultiProcess("SSL", CPA_FALSE); + if (CPA_STATUS_SUCCESS != stat) + { + PRINT_ERR("Failed to start user process SSL\n"); + qaeMemDestroy(); + return (int)stat; + } + + stat = algChainSample(); + if ((CPA_STATUS_SUCCESS != stat) && (CPA_STATUS_UNSUPPORTED != stat)) + { + PRINT_ERR("\nZUC-128 Sample Code App failed\n"); + } + else + { + PRINT_DBG("\nZUC-128 Sample Code App finished\n"); + } + + icp_sal_userStop(); + + qaeMemDestroy(); + + return (int)stat; +} diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.c index 1d57199a..da9722da 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_buffer_utils.c @@ -176,11 +176,14 @@ CpaStatus qatFreeFlatBuffersInList(CpaBufferList *list) allocationStatus = CPA_STATUS_FAIL; } } - qaeMemFreeNUMA((void **)&(list->pBuffers)); if (NULL != list->pBuffers) { - PRINT("could not free pBuffers\n"); - allocationStatus = CPA_STATUS_FAIL; + qaeMemFreeNUMA((void **)&(list->pBuffers)); + if (NULL != list->pBuffers) + { + PRINT("could not free pBuffers\n"); + allocationStatus = CPA_STATUS_FAIL; + } } if (NULL != list->pPrivateMetaData) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_dp.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_dp.c index a5dd2742..90994cd3 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_dp.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_dp.c @@ -38,6 +38,7 @@ #include "busy_loop.h" #include "qat_perf_cycles.h" #include "qat_perf_buffer_utils.h" +#include "qat_compression_zlib.h" extern int latency_single_buffer_mode; /* set to 1 for single buffer processing */ extern char *cpaStatusToString(CpaStatus status); /* for more readable debug */ @@ -358,6 +359,204 @@ static void freeBuffersDp(CpaPhysFlatBuffer ***pFlatBuffArray, qaeMemFreeNUMA((void **)&pFlatBuffArray); } +/** + ***************************************************************************** + * @ingroup sampleCompressionDpPerf + * + * @description + * Allocate memory for CpaFlatBuffers + ******************************************************************************/ +static CpaStatus AllocateBuffers(Cpa32U buffSize, + Cpa32U numLists, + CpaBufferList **pBuffListArray, + Cpa32U nodeId, + Cpa32U bufferMetaSize) +{ + Cpa32U i = 0; + + for (i = 0; i < numLists; i++) + { + pBuffListArray[i] = qaeMemAlloc(sizeof(CpaBufferList)); + if (NULL == pBuffListArray[i]) + { + PRINT_ERR(" Unable to allocate CpaBufferList\n"); + return CPA_STATUS_FAIL; + } + + pBuffListArray[i]->pPrivateMetaData = + qaeMemAllocNUMA(bufferMetaSize, nodeId, BYTE_ALIGNMENT_64); + + if (NULL == pBuffListArray[i]->pPrivateMetaData) + { + PRINT_ERR(" Unable to allocate pPrivateMetaData\n"); + return CPA_STATUS_FAIL; + } + + pBuffListArray[i]->numBuffers = ONE_BUFFER_DC; + pBuffListArray[i]->pBuffers = qaeMemAlloc(sizeof(CpaFlatBuffer)); + + if (NULL == pBuffListArray[i]->pBuffers) + { + PRINT_ERR(" Unable to allocate pBuffers\n"); + return CPA_STATUS_FAIL; + } + + pBuffListArray[i]->pBuffers->pData = + qaeMemAllocNUMA(buffSize, nodeId, BYTE_ALIGNMENT_64); + + if (NULL == pBuffListArray[i]->pBuffers->pData) + { + PRINT_ERR(" Unable to allocate pData\n"); + return CPA_STATUS_FAIL; + } + + pBuffListArray[i]->pBuffers->dataLenInBytes = buffSize; + } + return CPA_STATUS_SUCCESS; +} + +/** + ***************************************************************************** + * @ingroup sampleCompressionDpPerf + * + * @description + * Data compression using ZLIB SW library + ******************************************************************************/ +static CpaStatus qatDpSwZlibCompress(compression_test_params_t *setup, + CpaBufferList *srcBuffListArray, + CpaBufferList *dstBuffListArray, + CpaDcRqResults *cmpResults) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + struct z_stream_s stream = { 0 }; + int zlibFlushflag; + + /* call the compress api */ + memset(&stream, 0, sizeof(struct z_stream_s)); + deflate_init(&stream); + + zlibFlushflag = Z_FINISH; + + status = deflate_compress(&stream, + srcBuffListArray->pBuffers->pData, + srcBuffListArray->pBuffers->dataLenInBytes, + dstBuffListArray->pBuffers->pData, + dstBuffListArray->pBuffers->dataLenInBytes, + zlibFlushflag); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("SW Compression failed. srcLen: %d, destLen: %d \n", + srcBuffListArray->pBuffers->dataLenInBytes, + dstBuffListArray->pBuffers->dataLenInBytes); + + deflate_destroy(&stream); + return CPA_STATUS_FAIL; + } + + cmpResults->consumed = stream.total_in; + cmpResults->produced = stream.total_out; + + deflate_destroy(&stream); + return status; +} +/** + ***************************************************************************** + * @ingroup sampleCompressionDpPerf + * + * @description + * Data compression using SW libraries + ******************************************************************************/ +static CpaStatus qatDpSwCompress(compression_test_params_t *setup, + CpaBufferList *srcBuffListArray, + CpaBufferList *dstBuffListArray, + CpaDcRqResults *cmpResults) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(srcBuffListArray, status); + QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(dstBuffListArray, status); + QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(cmpResults, status); + QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(setup, status); + + if (CPA_STATUS_SUCCESS == status) + { + if (setup->setupData.compType == CPA_DC_DEFLATE) + { + status = qatDpSwZlibCompress( + setup, srcBuffListArray, dstBuffListArray, cmpResults); + } +#ifdef USER_SPACE +#endif + else + { + PRINT_ERR("Unsupported Compression type %d\n", + setup->setupData.compType); + status = CPA_STATUS_FAIL; + } + } + return status; +} + +/** + ***************************************************************************** + * @ingroup sampleCompressionDpPerf + * + * @description + * Compress the corpus using SW lib before we do decompression + ******************************************************************************/ +static CpaStatus swCompressPreDecomp(compression_test_params_t *setup, + CpaBufferList ***srcBuffListArray, + CpaBufferList ***dstBuffListArray, + CpaDcDpOpData ***compressionOpData, + CpaPhysFlatBuffer ***dstFlatBuffArray) +{ + /* Local Variable Declaration */ + Cpa32U i = 0, j = 0; + Cpa32U numFiles = getNumFilesInCorpus(setup->corpus); + CpaStatus status = CPA_STATUS_SUCCESS; + CpaDcRqResults *cmpResults = NULL; + + for (i = 0; i < numFiles; i++) + { + cmpResults = + qaeMemAlloc(sizeof(CpaDcRqResults) * setup->numberOfBuffers[i]); + + if (NULL == cmpResults) + { + PRINT_ERR("Could not allocate cmpResults\n"); + return CPA_STATUS_FAIL; + } + + for (j = 0; j < setup->numberOfBuffers[i]; j++) + { + memset(cmpResults, + 0, + sizeof(CpaDcRqResults) * setup->numberOfBuffers[i]); + + status = qatDpSwCompress(setup, + srcBuffListArray[i][j], + dstBuffListArray[i][j], + &cmpResults[j]); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Could not compress using SW\n"); + qaeMemFree((void **)&cmpResults); + return status; + } + + compressionOpData[i][j]->results.consumed = cmpResults[j].consumed; + compressionOpData[i][j]->results.produced = cmpResults[j].produced; + dstFlatBuffArray[i][j]->dataLenInBytes = cmpResults[j].produced; + } + + qaeMemFree((void **)&cmpResults); + } + + return status; +} + /** ***************************************************************************** * @ingroup sampleCompressionDpPerf @@ -1992,12 +2191,23 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) CpaPhysFlatBuffer ***cmpFlatBuffArray = NULL; Cpa32U numFiles = 0; const corpus_file_t *fileArray = NULL; + /* Declare src and dst buffers for SW compression */ + CpaBufferList ***srcBuffListArray = NULL; + CpaBufferList ***dstBuffListArray = NULL; + Cpa32U numBuffsInList = ONE_BUFFER_DC; + Cpa32U metaSize = 0; + CpaBoolean useDecompService = CPA_FALSE; if (NULL == setup) { PRINT_ERR("Test Setup Pointer is NULL\n"); return CPA_STATUS_FAIL; } + + if (setup->dcSessDir == CPA_DC_DIR_DECOMPRESS && setup->useDecompService) + { + useDecompService = CPA_TRUE; + } numFiles = getNumFilesInCorpus(setup->corpus); fileArray = getFilesInCorpus(setup->corpus); @@ -2067,6 +2277,35 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) PRINT_ERR("unable to allocate decompressionOpData \n"); return CPA_STATUS_FAIL; } + if (useDecompService) + { + srcBuffListArray = qaeMemAlloc(numFiles * sizeof(CpaBufferList **)); + /* Check for NULL */ + if (NULL == srcBuffListArray) + { + qaeMemFreeNUMA((void **)&srcFlatBuffArray); + qaeMemFreeNUMA((void **)&dstFlatBuffArray); + qaeMemFreeNUMA((void **)&cmpFlatBuffArray); + qaeMemFreeNUMA((void **)&compressionOpData); + qaeMemFreeNUMA((void **)&decompressionOpData); + PRINT_ERR("unable to allocate srcBuffListArray\n"); + return CPA_STATUS_FAIL; + } + + dstBuffListArray = qaeMemAlloc(numFiles * sizeof(CpaBufferList **)); + /* Check for NULL */ + if (NULL == dstBuffListArray) + { + qaeMemFreeNUMA((void **)&srcFlatBuffArray); + qaeMemFreeNUMA((void **)&dstFlatBuffArray); + qaeMemFreeNUMA((void **)&cmpFlatBuffArray); + qaeMemFreeNUMA((void **)&compressionOpData); + qaeMemFreeNUMA((void **)&decompressionOpData); + qaeMemFree((void **)&srcBuffListArray); + PRINT_ERR("unable to allocate dstBuffListArray\n"); + return CPA_STATUS_FAIL; + } + } /* populate the flat buffer array with number of buffers required * for each file and allocate the memory */ @@ -2093,6 +2332,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } @@ -2109,6 +2353,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } @@ -2125,6 +2374,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } @@ -2141,6 +2395,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } @@ -2157,9 +2416,55 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } + if (useDecompService) + { + srcBuffListArray[i] = qaeMemAlloc(setup->numberOfBuffers[i] * + (sizeof(CpaBufferList *))); + /* Check for NULL */ + if (NULL == srcBuffListArray[i]) + { + PRINT_ERR("Unable to allocate Memory for srcBuffListArray\n "); + freeBuffersDp(srcFlatBuffArray, i, setup); + freeBuffersDp(dstFlatBuffArray, i, setup); + freeBuffersDp(cmpFlatBuffArray, i, setup); + freeOpDataDp(compressionOpData, i, setup); + freeOpDataDp(decompressionOpData, i, setup); + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + return CPA_STATUS_FAIL; + } + + dstBuffListArray[i] = qaeMemAlloc(setup->numberOfBuffers[i] * + (sizeof(CpaBufferList *))); + /* Check for NULL */ + if (NULL == dstBuffListArray[i]) + { + PRINT_ERR("Unable to allocate Memory for dstBuffListArray\n "); + freeBuffersDp(srcFlatBuffArray, i, setup); + freeBuffersDp(dstFlatBuffArray, i, setup); + freeBuffersDp(cmpFlatBuffArray, i, setup); + freeOpDataDp(compressionOpData, i, setup); + freeOpDataDp(decompressionOpData, i, setup); + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + return CPA_STATUS_FAIL; + } + } } + if (CPA_DC_DIR_DECOMPRESS == setup->dcSessDir) + { + /* For decompression using decomp service set destination buffer size + * to 2 times the buffer size */ + destBufferSize = bufferSize * 2; + } + else { /* For compression,the destination buffer size is obtained using * Compress Bound API.*/ @@ -2208,6 +2513,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } @@ -2222,6 +2532,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } @@ -2238,6 +2553,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } if (setup->disableAdditionalCmpbufferSize == CPA_FALSE) @@ -2270,6 +2590,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } @@ -2284,8 +2609,72 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } + if (useDecompService) + { + status = cpaDcBufferListGetMetaSize( + setup->dcInstanceHandle, numBuffsInList, &metaSize); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get meta size\n"); + freeBuffersDp(srcFlatBuffArray, numFiles, setup); + freeBuffersDp(dstFlatBuffArray, numFiles, setup); + freeBuffersDp(cmpFlatBuffArray, numFiles, setup); + freeOpDataDp(compressionOpData, numFiles, setup); + freeOpDataDp(decompressionOpData, numFiles, setup); + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + + return CPA_STATUS_FAIL; + } + + status = AllocateBuffers(bufferSize, + setup->numberOfBuffers[i], + srcBuffListArray[i], + nodeId, + metaSize); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to crete buffers for srcBuffListArray\n"); + freeBuffersDp(srcFlatBuffArray, numFiles, setup); + freeBuffersDp(dstFlatBuffArray, numFiles, setup); + freeBuffersDp(cmpFlatBuffArray, numFiles, setup); + freeOpDataDp(compressionOpData, numFiles, setup); + freeOpDataDp(decompressionOpData, numFiles, setup); + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + + return CPA_STATUS_FAIL; + } + + status = AllocateBuffers(destBufferSize, + setup->numberOfBuffers[i], + dstBuffListArray[i], + nodeId, + metaSize); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to crete buffers for dstBuffListArray\n"); + freeBuffersDp(srcFlatBuffArray, numFiles, setup); + freeBuffersDp(dstFlatBuffArray, numFiles, setup); + freeBuffersDp(cmpFlatBuffArray, numFiles, setup); + freeOpDataDp(compressionOpData, numFiles, setup); + freeOpDataDp(decompressionOpData, numFiles, setup); + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + + return CPA_STATUS_FAIL; + } + } } /* Copy data into Flat Buffers from the corpus structure */ @@ -2300,6 +2689,14 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) memcpy(((void *)(uintptr_t)srcFlatBuffArray[i][j]->bufferPhysAddr), fileDataPtr, bufferSize); + if (useDecompService) + { + /* For decompression using decomp service copy data into buffers + * used for SW compression */ + memcpy(srcBuffListArray[i][j]->pBuffers->pData, + fileDataPtr, + bufferSize); + } fileDataPtr += bufferSize; } @@ -2308,11 +2705,16 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) { /*LZ4S doesn't support COMBINED sessDirection*/ if ((setup->setupData.compType != CPA_DC_LZ4S) + && !(useDecompService) ) { setup->setupData.sessDirection = CPA_DC_DIR_COMBINED; } + if (useDecompService) + { + setup->setupData.autoSelectBestHuffmanTree = CPA_DC_ASB_DISABLED; + } /* Get Size for DC Session */ status = cpaDcDpGetSessionSize( @@ -2334,6 +2736,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } /* Setup and init Session */ @@ -2354,6 +2761,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, numFiles, setup); freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } } @@ -2435,6 +2847,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); + } return CPA_STATUS_FAIL; } compressionOpData[i][j]->pSetupData->compLevel = @@ -2469,6 +2886,18 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) else if (CPA_DC_DIR_DECOMPRESS == dcSessDirReq) { perfData->numOperations = totalBuffs; + if (useDecompService) + { + /* Compress the corpus using SW lib before we can decompress it + * using decomp service + */ + status = swCompressPreDecomp(setup, + srcBuffListArray, + dstBuffListArray, + compressionOpData, + dstFlatBuffArray); + } + else { /* Compress the corpus so we can de-compress it */ status = @@ -2493,6 +2922,25 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) decompressionOpData[i][j]->dcInstance = setup->dcInstanceHandle; decompressionOpData[i][j]->pSessionHandle = pSessionHandle; + if (useDecompService) + { + CpaInstanceInfo2 info2 = { 0 }; + cpaDcInstanceGetInfo2(setup->dcInstanceHandle, &info2); + if (!info2.requiresPhysicallyContiguousMemory) + { + /* SVM enabled: device expects virtual addresses */ + decompressionOpData[i][j]->srcBuffer = + (CpaPhysicalAddr)(uintptr_t)dstBuffListArray[i][j] + ->pBuffers->pData; + } + else + { + decompressionOpData[i][j]->srcBuffer = + (CpaPhysicalAddr)qaeVirtToPhysNUMA( + dstBuffListArray[i][j]->pBuffers->pData); + } + } + else { decompressionOpData[i][j]->srcBuffer = (CpaPhysicalAddr)virtAddrToDevAddr( @@ -2551,6 +2999,11 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) freeBuffersDp(cmpFlatBuffArray, i, setup); freeOpDataDp(compressionOpData, i, setup); freeOpDataDp(decompressionOpData, i, setup); + if (useDecompService) + { + freeBuffers(srcBuffListArray, i, setup); + freeBuffers(dstBuffListArray, i, setup); + } return CPA_STATUS_FAIL; } decompressionOpData[i][j]->pSetupData->compLevel = @@ -2624,6 +3077,9 @@ static CpaStatus dcDpPerform(compression_test_params_t *setup) /* Free OpData structures */ freeOpDataDp(compressionOpData, numFiles, setup); freeOpDataDp(decompressionOpData, numFiles, setup); + /* Free src and dst buffers used for SW compression */ + freeBuffers(srcBuffListArray, numFiles, setup); + freeBuffers(dstBuffListArray, numFiles, setup); return status; } @@ -2644,6 +3100,7 @@ void dcDpPerformance(single_thread_test_data_t *testSetup) CpaInstanceHandle *instances = NULL; CpaStatus status = CPA_STATUS_FAIL; CpaDcInstanceCapabilities *capabilities = NULL; + CpaBoolean useDecompService = CPA_FALSE; CpaInstanceInfo2 *instanceInfo = NULL; #if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) @@ -2674,11 +3131,15 @@ void dcDpPerformance(single_thread_test_data_t *testSetup) dcSetup.isUseSGL = tmpSetup->isUseSGL; dcSetup.numFlatsPerSGL = tmpSetup->numFlatsPerSGL; dcSetup.bufferSize = tmpSetup->bufferSize; + /* Latch the decomp-service decision from the per-test setup struct + * (populated once in setupDcDpTest()) so this worker thread reads its + * own flag instead of the racy global decompServiceRequest_g. */ + dcSetup.useDecompService = tmpSetup->useDecompService; /*initialize number of buffers with NULL*/ dcSetup.numberOfBuffers = NULL; dcSetup.numberOfSGLs = NULL; status = calculateRequireBuffers(&dcSetup); - + useDecompService = dcSetup.useDecompService; /*this barrier is to halt this thread when run in user space context, the * startThreads function releases this barrier, in kernel space is does * nothing, but kernel space threads do not start @@ -2713,32 +3174,26 @@ void dcDpPerformance(single_thread_test_data_t *testSetup) */ testSetup->statsPrintFunc = NULL; - /* Get the number of instances */ + /*get the instance handles so that we can start + * our thread on the selected instance + */ + if (useDecompService) { - status = cpaDcGetNumInstances(&numInstances); + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &instances, &numInstances); if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR(" Unable to get number of DC instances\n"); - goto exit; - } - if (0 == numInstances) - { - PRINT_ERR(" DC Instances are not present\n"); - goto exit; - } - instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); - if (NULL == instances) - { - PRINT_ERR("Unable to allocate Memory for Instances\n"); + PRINT_ERR("dcGetInstances failed\n"); goto exit; } - /*get the instance handles so that we can start - * our thread on the selected instance - */ - status = cpaDcGetInstances(numInstances, instances); + } + else + { + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &instances, &numInstances); if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR("get instances failed"); + PRINT_ERR("dcGetInstances failed\n"); goto exit; } } @@ -2896,27 +3351,9 @@ static CpaStatus checkDcNonPollingInstance(CpaBoolean *polled) CpaInstanceInfo2 instanceInfo = {0}; int i = 0; - /* Get the number of instances */ - status = cpaDcGetNumInstances(&numInstances); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Unable to get number of DC instances\n"); - return CPA_STATUS_FAIL; - } - if (0 == numInstances) - { - PRINT_ERR("DC Instances are not present\n"); - return CPA_STATUS_FAIL; - } - instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); - if (NULL == instances) - { - PRINT_ERR("Unable to allocate Memory for Instances\n"); - return CPA_STATUS_FAIL; - } - /*get the instance handles - */ - status = cpaDcGetInstances(numInstances, instances); + /*get the instance handles*/ + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &instances, &numInstances); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("get instances failed"); @@ -2953,6 +3390,44 @@ static CpaStatus checkDcNonPollingInstance(CpaBoolean *polled) * @description * Check for Non Polling Decomp Instance. ******************************************************************************/ +static CpaStatus checkDecompNonPollingInstance(CpaBoolean *polled) +{ + Cpa16U numInstances = 0; + CpaInstanceHandle *instances = NULL; + CpaStatus status = CPA_STATUS_FAIL; + CpaInstanceInfo2 instanceInfo = { 0 }; + int i = 0; + + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &instances, &numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("dcGetInstances failed"); + goto exit; + } + for (i = 0; i < numInstances; i++) + { + status = cpaDcInstanceGetInfo2(instances[i], &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcInstanceGetInfo2 failed"); + status = CPA_STATUS_FAIL; + goto exit; + } + if (CPA_FALSE == instanceInfo.isPolled) + { + *polled = CPA_FALSE; + status = CPA_STATUS_SUCCESS; + goto exit; + } + } +exit: + if (NULL != instances) + { + qaeMemFree((void **)&instances); + } + return status; +} /** ***************************************************************************** @@ -2990,6 +3465,7 @@ CpaStatus setupDcDpTest(CpaDcCompType algorithm, Cpa32U numFiles = getNumFilesInCorpus(corpusType); const corpus_file_t *const fileArray = getFilesInCorpus(corpusType); CpaBoolean polled = CPA_TRUE; + CpaBoolean useDecompService = CPA_FALSE; /* Ensure that the number of threads created do not exceed the amount of * threads supported by the sample code framework. @@ -3001,7 +3477,19 @@ CpaStatus setupDcDpTest(CpaDcCompType algorithm, PRINT_ERR(" Max is %d\n", MAX_THREAD_VARIATION); return CPA_STATUS_FAIL; } + getDecompNumInstances(); + useDecompService = + (CPA_DC_DIR_DECOMPRESS == direction && numDecompInstances_g > 0) + ? CPA_TRUE + : CPA_FALSE; + if (useDecompService) { + setDecompServiceRequest(1); + status = checkDecompNonPollingInstance(&polled); + } + else + { + setDecompServiceRequest(0); status = checkDcNonPollingInstance(&polled); } if (CPA_STATUS_SUCCESS != status) @@ -3023,6 +3511,23 @@ CpaStatus setupDcDpTest(CpaDcCompType algorithm, PRINT_ERR("Unable to Populate corpus file\n"); return CPA_STATUS_FAIL; } + if (useDecompService) + { + /* + * Create Decomp instances handles, allocate temporary memory for + * dynamic compression and create polling threads(if enabled in + * configuration) + * */ + status = startServices(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + DYNAMIC_BUFFER_AREA, + TEMP_NUM_BUFFS); + if (CPA_STATUS_SUCCESS != status) + { + PRINT("Error in Starting Decomp Services\n"); + return CPA_STATUS_FAIL; + } + } + else { /* * Create DC instances handles, allocate temporary memory for dynamic @@ -3063,6 +3568,13 @@ CpaStatus setupDcDpTest(CpaDcCompType algorithm, /* Data compression setup data */ dcSetup->setupData.compLevel = compLevel; dcSetup->setupData.compType = algorithm; + + dcSetup->useDecompService = useDecompService; + if (dcSetup->useDecompService) + { + dcSetup->setupData.sessDirection = CPA_DC_DIR_DECOMPRESS; + } + else { dcSetup->setupData.sessDirection = CPA_DC_DIR_COMPRESS; } diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_perf.h b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_perf.h index 9953f54d..b133e7a1 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_perf.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_perf.h @@ -27,9 +27,7 @@ #include "cpa.h" #include "cpa_dc.h" -#ifdef SC_CHAINING_ENABLED #include "cpa_dc_chain.h" -#endif #include "cpa_cy_sym.h" #include "cpa_sample_code_framework.h" #include "../common/qat_perf_utils.h" @@ -278,7 +276,6 @@ typedef struct compression_test_params_s * buffer. */ CpaBoolean induceOverflow; -#if defined(SC_CHAINING_ENABLED) || defined(SC_CHAINING_EXT_ENABLED) CpaDcChainOperations chainOperation; CpaBoolean legacyChainRequest; CpaBoolean appendCRC; @@ -287,7 +284,6 @@ typedef struct compression_test_params_s Cpa32U symIvLength; Cpa8U numSessions; CpaBoolean keyDerive; -#endif /*the logicalQaInstance for the cipher to use*/ Cpa32U logicalQaInstance; #if defined(SC_WITH_QAT20) || defined(SC_WITH_QAT20_UPSTREAM) @@ -321,6 +317,15 @@ typedef struct compression_test_params_s Cpa32U dcDestBufferSize; CpaBoolean isUseSGL; Cpa32U numFlatsPerSGL; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /**< Current CpaInstanceResponseMode for the DC instance in use */ + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + /* Per-thread flag: when CPA_TRUE this test variation must use the + * DATA_DECOMPRESSION service path (decomp-only instances available, + * no DC instances). */ + CpaBoolean useDecompService; } compression_test_params_t; /** @@ -808,6 +813,26 @@ void dcChainOpDataMemFree(CpaDcChainOpData *pOpdata, Cpa32U numSessions); #endif +/** + * ***************************************************************************** + * @ingroup compressionThreads + * free callback Structures + * + * @description + * this API frees all the chain operation structures + * + * @threadSafe + * No + * + * @param[in] pOpData array of CpaDcChainOpData structure. + * @param[in] numLists number of buffer list. + * @param[in] numSessions number of session in chaining operation. + * + ******************************************************************************/ +void dcExtChainOpDataMemFree(CpaDcChainSubOpData2 *pOpdata, + Cpa32U numLists, + Cpa32U numSessions); + /** * ***************************************************************************** * @ingroup compressionThreads diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.c index acaee5cd..7e82fcba 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.c @@ -68,6 +68,31 @@ EXPORT_SYMBOL(dcPollingThreadsInterval_g); CpaBoolean disableAdditionalCmpbufferSize_g = CPA_FALSE; EXPORT_SYMBOL(disableAdditionalCmpbufferSize_g); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/**< Global mask to track which instances should use which response mode (up to + * 64 instances) */ +static Cpa64U dcInstanceResponseModeMask_g = 0; +/**< Response mode to apply when explicitly configured */ +static CpaInstanceResponseMode dcConfiguredResponseMode_g = + CPA_INST_RX_NOTIFY_NONE; +/**< Flag to track if response mode has been explicitly configured */ +static CpaBoolean dcResponseModeConfigured_g = CPA_FALSE; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +/**< Global mask to track which DC instances should have the coalescing timer + * applied (up to 64 instances) */ +static Cpa64U dcInstanceCoalescingTimerMask_g = 0; +/**< Coalescing timer value (in nanoseconds) to apply when explicitly + * configured */ +static Cpa32U dcConfiguredCoalescingTimerNs_g = 0; +/**< Flag to track if the coalescing timer has been explicitly configured */ +static CpaBoolean dcCoalescingTimerConfigured_g = CPA_FALSE; +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ + #if DC_API_VERSION_AT_LEAST(3, 1) CpaStatus setLZ4BlockIndependence(CpaBoolean val); #endif @@ -133,10 +158,1138 @@ EXPORT_SYMBOL(setTestOverFlow); void setDcPollingThreadsInterval(long interval) { - dcPollingThreadsInterval_g = interval; + dcPollingThreadsInterval_g = interval; +} +EXPORT_SYMBOL(setDcPollingThreadsInterval); + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/** + ***************************************************************************** + * @ingroup compressionThreads + * mapUserResponseModeToEnum + * + * @description + * Maps user input values (0|1) to actual CpaInstanceResponseMode enum + * values (1|2). This is needed because the enum values are + * CPA_INST_RX_NOTIFY_NONE=1 and CPA_INST_RX_NOTIFY_BY_EVENT=2, but users + * typically specify 0 for polling and 1 for event notification. + * + * @param[in] userMode User input mode (0 for polling, 1 for event) + * + * @retval CpaInstanceResponseMode The corresponding enum value + * + *****************************************************************************/ +static CpaInstanceResponseMode mapUserResponseModeToEnum(Cpa32U userMode) +{ + switch (userMode) + { + case 0: + return CPA_INST_RX_NOTIFY_NONE; /* Maps 0 -> 1 (polling) */ + case 1: + return CPA_INST_RX_NOTIFY_BY_EVENT; /* Maps 1 -> 2 (event) */ + default: + PRINT_ERR("Invalid response mode %d, defaulting to polling mode\n", + userMode); + return CPA_INST_RX_NOTIFY_NONE; + } +} + +CpaStatus setDcInstanceResponseMode(CpaInstanceResponseMode responseMode) +{ + dcConfiguredResponseMode_g = responseMode; + dcResponseModeConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceResponseMode); + +CpaStatus setDcInstanceResponseModeWithMask(Cpa32U userMode, Cpa64U mask) +{ + CpaInstanceResponseMode enumMode = mapUserResponseModeToEnum(userMode); + + /* Set both the response mode and the mask */ + setDcInstanceResponseMode(enumMode); + setDcInstanceResponseModeMask(mask); + + PRINT("Set DC response mode %d (enum %d) for instances with mask 0x%llx\n", + userMode, + enumMode, + (unsigned long long)mask); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceResponseModeWithMask); + +CpaStatus setDcInstanceResponseModeForRange(Cpa32U userMode, + Cpa16U startInst, + Cpa16U endInst) +{ + Cpa64U mask = 0; + Cpa16U i; + + /* Validate range */ + if (startInst > endInst || endInst >= 64) + { + PRINT_ERR("Invalid instance range %d-%d (must be 0-63)\n", + startInst, + endInst); + return CPA_STATUS_FAIL; + } + + /* Build mask for the range */ + for (i = startInst; i <= endInst; i++) + { + mask |= (1ULL << i); + } + + /* Use the combined function */ + setDcInstanceResponseModeWithMask(userMode, mask); + PRINT("Configured instances %d-%d with response mode %d\n", + startInst, + endInst, + userMode); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceResponseModeForRange); + +CpaInstanceResponseMode getDcInstanceResponseMode(void) +{ + return dcConfiguredResponseMode_g; +} +EXPORT_SYMBOL(getDcInstanceResponseMode); + +void setDcInstanceResponseModeMask(Cpa64U mask) +{ + dcInstanceResponseModeMask_g = mask; +} +EXPORT_SYMBOL(setDcInstanceResponseModeMask); + +Cpa64U getDcInstanceResponseModeMask(void) +{ + return dcInstanceResponseModeMask_g; +} +EXPORT_SYMBOL(getDcInstanceResponseModeMask); + +CpaStatus configureDcInstanceResponseModeForAll( + CpaInstanceResponseMode responseMode) +{ + Cpa16U numInstances = 0; + Cpa16U numDecompInst = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + /* Get the number of DC (compression) instances */ + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &numDecompInst); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Decomp instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0 && numDecompInst == 0) + { + /* No DC instances in the active config (e.g. an SSL/CY-only + * section). Nothing to configure; not a fatal condition. */ + PRINT("No DC and Decomp instances available - skipping DC and Decomp " + "response mode configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + /* Set mask for all instances (up to 64 instances supported) */ + Cpa64U allInstancesMask; + Cpa16U totalInstances = numInstances + numDecompInst; + + if (totalInstances >= 64) + { + allInstancesMask = 0xFFFFFFFFFFFFFFFFULL; /* All 64 bits set */ + } + else + { + allInstancesMask = (1ULL << totalInstances) - + 1; /* Set bits 0 to totalInstances-1 */ + } + + setDcInstanceResponseMode(responseMode); + setDcInstanceResponseModeMask(allInstancesMask); + + PRINT("Explicitly configured response mode %d for %d instances " + "(%d comp + %d decomp, mask: 0x%llx)\n", + responseMode, + totalInstances, + numInstances, + numDecompInst, + (unsigned long long)allInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureDcInstanceResponseModeForAll); + +CpaStatus configureDcInstanceResponseModeForHalf( + CpaInstanceResponseMode responseMode) +{ + Cpa16U numInstances = 0; + Cpa16U numDecompInst = 0; + Cpa16U half_numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + /* Get the number of DC instances */ + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &numDecompInst); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Decomp instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0 && numDecompInst == 0) + { + /* No DC instances in the active config (e.g. an SSL/CY-only + * section). Nothing to configure; not a fatal condition. */ + PRINT("No DC and Decomp instances available - skipping DC and Decomp " + "response mode configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + Cpa16U totalInstances = numInstances + numDecompInst; + Cpa16U halfComp = numInstances / 2; + Cpa16U halfDecomp = numDecompInst / 2; + Cpa64U halfInstancesMask = 0; + Cpa16U b; + + half_numInstances = halfComp + halfDecomp; + + /* Lower half of comp bits (0..halfComp-1) */ + for (b = 0; b < halfComp && b < 64; b++) + { + halfInstancesMask |= (1ULL << b); + } + /* Lower half of decomp bits, placed after all comp bits */ + for (b = 0; b < halfDecomp && (numInstances + b) < 64; b++) + { + halfInstancesMask |= (1ULL << (numInstances + b)); + } + + setDcInstanceResponseMode(responseMode); + setDcInstanceResponseModeMask(halfInstancesMask); + + PRINT("Explicitly configured response mode %d for HALF (%d of %d) " + "instances (%d/%d comp + %d/%d decomp, mask: 0x%llx)\n", + responseMode, + half_numInstances, + totalInstances, + halfComp, + numInstances, + halfDecomp, + numDecompInst, + (unsigned long long)halfInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureDcInstanceResponseModeForHalf); + +CpaStatus setDcInstanceResponseModeByValue(Cpa32U userMode) +{ + CpaInstanceResponseMode enumMode = mapUserResponseModeToEnum(userMode); + configureDcInstanceResponseModeForAll(enumMode); + + PRINT("Configured all DC instances: user input %d -> enum value %d\n", + userMode, + enumMode); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceResponseModeByValue); + +CpaBoolean isDcInstanceResponseModeConfigured(void) +{ + return dcResponseModeConfigured_g; +} +EXPORT_SYMBOL(isDcInstanceResponseModeConfigured); + +CpaStatus clearDcInstanceResponseModeConfiguration(void) +{ + dcResponseModeConfigured_g = CPA_FALSE; + /* Reset to a neutral value - actual library default will be queried + * per-thread */ + dcConfiguredResponseMode_g = CPA_INST_RX_NOTIFY_NONE; + dcInstanceResponseModeMask_g = 0; + + PRINT("Cleared DC instance response mode configuration\n"); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(clearDcInstanceResponseModeConfiguration); + +CpaStatus applyDcInstanceResponseModeConfiguration(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa16U numInstances = 0; + Cpa16U numDecompInstances = 0; + CpaInstanceHandle *instances = NULL; + Cpa64U instanceMask; + Cpa16U i = 0; + + if (!isDcInstanceResponseModeConfigured()) + { + /* No explicit configuration - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + instanceMask = getDcInstanceResponseModeMask(); + if (instanceMask == 0) + { + /* Empty mask - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + /* Get the number of DC (compression) instances */ + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count: %d\n", status); + return status; + } + + /* Also query pure decompression instances (cfg_services=decomp). + * Mirrors applyDcInstanceCoalescingTimerConfiguration(). */ + { + CpaStatus dstatus = cpaGetNumInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &numDecompInstances); + if (CPA_STATUS_SUCCESS != dstatus) + { + numDecompInstances = 0; + } + } + + if (numInstances == 0 && numDecompInstances == 0) + { + PRINT_ERR("No DC or decompression instances available to apply " + "response mode\n"); + return CPA_STATUS_FAIL; + } + + if (numInstances > 0) + { + /* Allocate memory for instance handles */ + instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); + if (NULL == instances) + { + PRINT_ERR("Unable to allocate memory for DC instances\n"); + return CPA_STATUS_FAIL; + } + + /* Get the instance handles */ + status = cpaDcGetInstances(numInstances, instances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get DC instances: %d\n", status); + qaeMemFree((void **)&instances); + return status; + } + } + + /* Apply response mode to compression instances specified in the mask */ + CpaInstanceResponseMode responseMode = getDcInstanceResponseMode(); + CpaInstanceResponseMode testMode = CPA_INST_RX_NOTIFY_NONE; + + for (i = 0; i < numInstances && i < 64; i++) + { + if (instanceMask & (1ULL << i)) + { + status = cpaInstanceSetResponseMode( + instances[i], CPA_ACC_SVC_TYPE_DATA_COMPRESSION, responseMode); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "Failed to set response mode %d for DC instance %d: %d\n", + responseMode, + i, + status); + /* Continue with other instances rather than failing completely + */ + } + else + { + status = cpaInstanceGetResponseMode( + instances[i], CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &testMode); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "Failed to get response mode for DC instance %d: %d\n", + i, + status); + qaeMemFree((void **)&instances); + return status; + } + else if (testMode != responseMode) + { + PRINT_ERR("Mismatch verifying response mode for DC " + "instance %d: set %d, got %d\n", + i, + responseMode, + testMode); + qaeMemFree((void **)&instances); + return CPA_STATUS_FAIL; + } + else + { + PRINT("Verified response mode %d for DC instance %d\n", + testMode, + i); + } + // PRINT("Set response mode %d for DC instance %d\n", + // responseMode, i); + } + } + } + + if (instances != NULL) + { + qaeMemFree((void **)&instances); + instances = NULL; + } + + /* Now apply response mode to decompression instances (numDecompInstances + * was queried earlier, mirroring + * applyDcInstanceCoalescingTimerConfiguration()). */ + if (numDecompInstances > 0) + { + CpaInstanceHandle *decompInstances = NULL; + + decompInstances = + qaeMemAlloc(sizeof(CpaInstanceHandle) * numDecompInstances); + if (NULL == decompInstances) + { + PRINT_ERR("Unable to allocate memory for Decomp instances\n"); + return CPA_STATUS_FAIL; + } + status = cpaGetInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + numDecompInstances, + decompInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get Decomp instances: %d\n", status); + qaeMemFree((void **)&decompInstances); + return status; + } + + for (i = 0; i < numDecompInstances && i < 64; i++) + { + if (instanceMask & (1ULL << i)) + { + status = cpaInstanceSetResponseMode( + decompInstances[i], + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + responseMode); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set response mode %d for Decomp " + "instance %d: %d\n", + responseMode, + i, + status); + } + else + { + status = cpaInstanceGetResponseMode( + decompInstances[i], + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &testMode); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get response mode for Decomp " + "instance %d: %d\n", + i, + status); + qaeMemFree((void **)&decompInstances); + return status; + } + else if (testMode != responseMode) + { + PRINT_ERR("Mismatch verifying response mode for " + "Decomp instance %d: set %d, got %d\n", + i, + responseMode, + testMode); + qaeMemFree((void **)&decompInstances); + return CPA_STATUS_FAIL; + } + else + { + PRINT("Verified response mode %d for Decomp " + "instance %d\n", + testMode, + i); + } + } + } + } + qaeMemFree((void **)&decompInstances); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(applyDcInstanceResponseModeConfiguration); + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +CpaStatus setDcInstanceCoalescingTimer(Cpa32U coalescingTimerInNs) +{ + dcConfiguredCoalescingTimerNs_g = coalescingTimerInNs; + dcCoalescingTimerConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceCoalescingTimer); + +Cpa32U getDcInstanceCoalescingTimer(void) +{ + return dcConfiguredCoalescingTimerNs_g; +} +EXPORT_SYMBOL(getDcInstanceCoalescingTimer); + +void setDcInstanceCoalescingTimerMask(Cpa64U mask) +{ + dcInstanceCoalescingTimerMask_g = mask; +} +EXPORT_SYMBOL(setDcInstanceCoalescingTimerMask); + +Cpa64U getDcInstanceCoalescingTimerMask(void) +{ + return dcInstanceCoalescingTimerMask_g; +} +EXPORT_SYMBOL(getDcInstanceCoalescingTimerMask); + +CpaBoolean isDcInstanceCoalescingTimerConfigured(void) +{ + return dcCoalescingTimerConfigured_g; +} +EXPORT_SYMBOL(isDcInstanceCoalescingTimerConfigured); + +CpaStatus clearDcInstanceCoalescingTimerConfiguration(void) +{ + dcCoalescingTimerConfigured_g = CPA_FALSE; + dcConfiguredCoalescingTimerNs_g = 0; + dcInstanceCoalescingTimerMask_g = 0; + + PRINT("Cleared DC instance coalescing timer configuration\n"); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(clearDcInstanceCoalescingTimerConfiguration); + +CpaStatus setDcInstanceCoalescingTimerWithMask(Cpa32U coalescingTimerInNs, + Cpa64U mask) +{ + setDcInstanceCoalescingTimer(coalescingTimerInNs); + setDcInstanceCoalescingTimerMask(mask); + + PRINT("Set DC coalescing timer %u ns for instances with mask 0x%llx\n", + coalescingTimerInNs, + (unsigned long long)mask); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceCoalescingTimerWithMask); + +CpaStatus setDcInstanceCoalescingTimerForRange(Cpa32U coalescingTimerInNs, + Cpa16U startInst, + Cpa16U endInst) +{ + Cpa64U mask = 0; + Cpa16U i; + + if (startInst > endInst || endInst >= 64) + { + PRINT_ERR("Invalid instance range %d-%d (must be 0-63)\n", + startInst, + endInst); + return CPA_STATUS_FAIL; + } + + for (i = startInst; i <= endInst; i++) + { + mask |= (1ULL << i); + } + + setDcInstanceCoalescingTimerWithMask(coalescingTimerInNs, mask); + PRINT("Configured instances %d-%d with coalescing timer %u ns\n", + startInst, + endInst, + coalescingTimerInNs); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcInstanceCoalescingTimerForRange); + +CpaStatus configureDcInstanceCoalescingTimerForAll(Cpa32U coalescingTimerInNs) +{ + Cpa16U numInstances = 0; + Cpa16U numDecompInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &numDecompInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Decomp instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0 && numDecompInstances == 0) + { + /* No DC instances in the active config (e.g. an SSL/CY-only + * section). Nothing to configure; not a fatal condition. */ + PRINT("No DC and Decomp instances available - skipping DC and Decomp " + "coalescing timer " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + Cpa64U allInstancesMask; + Cpa16U totalInstances = numInstances + numDecompInstances; + + if (totalInstances >= 64) + { + allInstancesMask = 0xFFFFFFFFFFFFFFFFULL; + } + else + { + allInstancesMask = (1ULL << totalInstances) - 1; + } + + setDcInstanceCoalescingTimer(coalescingTimerInNs); + setDcInstanceCoalescingTimerMask(allInstancesMask); + + PRINT("Explicitly configured coalescing timer %u ns for %d " + "instances (%d comp + %d decomp, mask: 0x%llx)\n", + coalescingTimerInNs, + totalInstances, + numInstances, + numDecompInstances, + (unsigned long long)allInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureDcInstanceCoalescingTimerForAll); + +CpaStatus configureDcInstanceCoalescingTimerForHalf(Cpa32U coalescingTimerInNs) +{ + Cpa16U numInstances = 0; + Cpa16U numDecompInstances = 0; + Cpa16U half_numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &numDecompInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Decomp instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0 && numDecompInstances == 0) + { + PRINT("No DC and Decomp instances available - skipping DC and Decomp " + "coalescing timer " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + Cpa16U totalInstances = numInstances + numDecompInstances; + Cpa16U halfComp = numInstances / 2; + Cpa16U halfDecomp = numDecompInstances / 2; + Cpa64U halfInstancesMask = 0; + Cpa16U b; + + half_numInstances = halfComp + halfDecomp; + + /* Lower half of comp bits (0..halfComp-1) */ + for (b = 0; b < halfComp && b < 64; b++) + { + halfInstancesMask |= (1ULL << b); + } + /* Lower half of decomp bits, placed after all comp bits */ + for (b = 0; b < halfDecomp && (numInstances + b) < 64; b++) + { + halfInstancesMask |= (1ULL << (numInstances + b)); + } + + setDcInstanceCoalescingTimer(coalescingTimerInNs); + setDcInstanceCoalescingTimerMask(halfInstancesMask); + + PRINT("Explicitly configured coalescing timer %u ns for HALF (%d of " + "%d) instances (%d/%d comp + %d/%d decomp, mask: 0x%llx)\n", + coalescingTimerInNs, + half_numInstances, + totalInstances, + halfComp, + numInstances, + halfDecomp, + numDecompInstances, + (unsigned long long)halfInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureDcInstanceCoalescingTimerForHalf); + +CpaStatus getDcInstanceRxInterruptMetaData( + CpaInstanceHandle instanceHandle, + CpaRxInterruptMetaData *pInterruptData) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaAccelerationServiceType svcType = CPA_ACC_SVC_TYPE_DATA_COMPRESSION; + + if (NULL == pInterruptData) + { + PRINT_ERR("Invalid parameter: pInterruptData is NULL\n"); + return CPA_STATUS_FAIL; + } + + status = cpaDcInstanceGetInfo2(instanceHandle, &instanceInfo); + if (CPA_STATUS_SUCCESS == status) + { + if (CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION == + instanceInfo.accelerationServiceType) + { + svcType = CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION; + } + } + + return cpaInstanceGetRxInterruptMetaData( + instanceHandle, svcType, pInterruptData); +} +EXPORT_SYMBOL(getDcInstanceRxInterruptMetaData); + +CpaStatus applyDcInstanceCoalescingTimerConfiguration(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa16U numInstances = 0; + Cpa16U numDecompInstances = 0; + CpaInstanceHandle *instances = NULL; + CpaInstanceHandle *decompInstances = NULL; + Cpa64U instanceMask; + Cpa32U coalescingTimerInNs; + CpaRxInterruptMetaData interruptData = { 0 }; + Cpa16U i = 0; + Cpa16U applied = 0; + Cpa16U appliedDecomp = 0; + + if (!isDcInstanceCoalescingTimerConfigured()) + { + /* No explicit configuration - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + instanceMask = getDcInstanceCoalescingTimerMask(); + if (instanceMask == 0) + { + /* Empty mask - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + coalescingTimerInNs = getDcInstanceCoalescingTimer(); + + /* Get the number of DC (DATA_COMPRESSION) instances */ + status = cpaDcGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC instances count: %d\n", status); + return status; + } + + /* Also query pure decompression instances (cfg_services=decomp). */ + { + CpaStatus dstatus = cpaGetNumInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &numDecompInstances); + if (CPA_STATUS_SUCCESS != dstatus) + { + numDecompInstances = 0; + } + } + + if (numInstances == 0 && numDecompInstances == 0) + { + PRINT_ERR("No DC or decompression instances available to apply " + "coalescing timer\n"); + return CPA_STATUS_FAIL; + } + + if (numInstances > 0) + { + /* Allocate memory for instance handles */ + instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); + if (NULL == instances) + { + PRINT_ERR("Unable to allocate memory for DC instances\n"); + return CPA_STATUS_FAIL; + } + + /* Get the instance handles */ + status = cpaDcGetInstances(numInstances, instances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get DC instances: %d\n", status); + qaeMemFree((void **)&instances); + return status; + } + } + + /* Apply coalescing timer to instances specified in the mask */ + for (i = 0; i < numInstances && i < 64; i++) + { + if (instanceMask & (1ULL << i)) + { + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaAccelerationServiceType svcType = + CPA_ACC_SVC_TYPE_DATA_COMPRESSION; + + /* Pick the correct acceleration service type for this instance. + * A pure decompression instance is reported as + * CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION. */ + status = cpaDcInstanceGetInfo2(instances[i], &instanceInfo); + if (CPA_STATUS_SUCCESS == status && + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION == + instanceInfo.accelerationServiceType) + { + svcType = CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION; + } + + status = cpaInstanceSetIntCoalescingTimer( + instances[i], svcType, coalescingTimerInNs); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set coalescing timer %u ns for DC " + "instance %d (svcType %d): %d\n", + coalescingTimerInNs, + i, + svcType, + status); + /* Continue with other instances rather than failing + * completely */ + } + else + { + memset(&interruptData, 0, sizeof(interruptData)); + status = cpaInstanceGetRxInterruptMetaData( + instances[i], svcType, &interruptData); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get RX interrupt metadata for DC " + "instance %d: %d\n", + i, + status); + qaeMemFree((void **)&instances); + return status; + } + else if (interruptData.coalescingTimerInNs != + coalescingTimerInNs) + { + /* Hardware may round to nearest supported granularity. + * Treat large differences as a failure, otherwise warn. */ + Cpa32U granularity = + interruptData.coalescingTimerGranularityInNs; + Cpa32U diff = (interruptData.coalescingTimerInNs > + coalescingTimerInNs) + ? (interruptData.coalescingTimerInNs - + coalescingTimerInNs) + : (coalescingTimerInNs - + interruptData.coalescingTimerInNs); + + if (granularity > 0 && diff <= granularity) + { + PRINT("Coalescing timer for DC instance %d rounded: " + "requested %u ns, actual %u ns (granularity " + "%u ns)\n", + i, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + granularity); + applied++; + } + else + { + PRINT_ERR("Mismatch verifying coalescing timer for DC " + "instance %d: set %u ns, got %u ns " + "(max %u ns, granularity %u ns)\n", + i, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + interruptData.coalescingTimerMaxInNs, + granularity); + qaeMemFree((void **)&instances); + return CPA_STATUS_FAIL; + } + } + else + { + PRINT("Verified coalescing timer %u ns for DC instance " + "%d (max %u ns, granularity %u ns)\n", + interruptData.coalescingTimerInNs, + i, + interruptData.coalescingTimerMaxInNs, + interruptData.coalescingTimerGranularityInNs); + applied++; + } + } + } + } + + if (instances != NULL) + { + qaeMemFree((void **)&instances); + instances = NULL; + } + + PRINT("Coalescing timer %u ns applied to %u DC instance(s)\n", + coalescingTimerInNs, + applied); + + if (numDecompInstances > 0) + { + Cpa16U j; + + decompInstances = + qaeMemAlloc(sizeof(CpaInstanceHandle) * numDecompInstances); + if (NULL == decompInstances) + { + PRINT_ERR("Unable to allocate memory for Decomp instances\n"); + return CPA_STATUS_FAIL; + } + + status = cpaGetInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + numDecompInstances, + decompInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get Decomp instances: %d\n", status); + qaeMemFree((void **)&decompInstances); + return status; + } + + for (j = 0; j < numDecompInstances; j++) + { + Cpa16U bit = numInstances + j; + + if (bit >= 64) + { + break; + } + if (!(instanceMask & (1ULL << bit))) + { + continue; + } + + status = cpaInstanceSetIntCoalescingTimer( + decompInstances[j], + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + coalescingTimerInNs); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set coalescing timer %u ns for Decomp " + "instance %d: %d\n", + coalescingTimerInNs, + j, + status); + continue; + } + + memset(&interruptData, 0, sizeof(interruptData)); + status = cpaInstanceGetRxInterruptMetaData( + decompInstances[j], + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &interruptData); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get RX interrupt metadata for Decomp " + "instance %d: %d\n", + j, + status); + qaeMemFree((void **)&decompInstances); + return status; + } + if (interruptData.coalescingTimerInNs != coalescingTimerInNs) + { + Cpa16U granularity = + interruptData.coalescingTimerGranularityInNs; + Cpa32U diff = + (interruptData.coalescingTimerInNs > coalescingTimerInNs) + ? (interruptData.coalescingTimerInNs - + coalescingTimerInNs) + : (coalescingTimerInNs - + interruptData.coalescingTimerInNs); + + if (granularity > 0 && diff <= (Cpa32U)granularity) + { + PRINT("Coalescing timer for Decomp instance %d rounded: " + "requested %u ns, actual %u ns (granularity " + "%u ns)\n", + j, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + granularity); + appliedDecomp++; + } + else + { + PRINT_ERR("Mismatch verifying coalescing timer for " + "Decomp instance %d: set %u ns, got %u ns " + "(max %u ns, granularity %u ns)\n", + j, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + interruptData.coalescingTimerMaxInNs, + granularity); + qaeMemFree((void **)&decompInstances); + return CPA_STATUS_FAIL; + } + } + else + { + PRINT("Verified coalescing timer %u ns for Decomp instance " + "%d (max %u ns, granularity %u ns)\n", + interruptData.coalescingTimerInNs, + j, + interruptData.coalescingTimerMaxInNs, + interruptData.coalescingTimerGranularityInNs); + appliedDecomp++; + } + } + qaeMemFree((void **)&decompInstances); + + PRINT("Coalescing timer %u ns applied to %u Decomp instance(s)\n", + coalescingTimerInNs, + appliedDecomp); + } + + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(applyDcInstanceCoalescingTimerConfiguration); +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ + +CpaStatus setDcResponseModeIterationCount(Cpa32U count) +{ + dcResponseModeIterationCount_g = count; + PRINT("Set DC response mode iteration count to %d\n", count); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setDcResponseModeIterationCount); + +CpaStatus getDcResponseModeIterationCount(Cpa32U *count) +{ + if (count == NULL) + { + PRINT_ERR("Invalid parameter: count pointer is NULL\n"); + return CPA_STATUS_FAIL; + } + + *count = dcResponseModeIterationCount_g; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(getDcResponseModeIterationCount); + +CpaInstanceResponseMode getDcResponseModeWithIteration( + compression_test_params_t *testParams) +{ + CpaInstanceResponseMode currentMode; + CpaInstanceResponseMode alternateMode; + Cpa32U i; + + /* If iteration count is 1 or less, return currentResponseMode (default + * behavior) */ + if (dcResponseModeIterationCount_g <= 1) + { + return (testParams != NULL) ? testParams->currentResponseMode + : CPA_INST_RX_NOTIFY_NONE; + } + + /* If testParams is NULL, cannot perform iteration */ + if (testParams == NULL) + { + PRINT_ERR( + "Cannot perform response mode iteration without test parameters\n"); + return CPA_INST_RX_NOTIFY_NONE; + } + /* Use currentResponseMode from test parameters as the starting point */ + currentMode = testParams->currentResponseMode; + + /* Determine alternate mode - opposite of current mode */ + if (currentMode == CPA_INST_RX_NOTIFY_NONE) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + + /* Perform iterations with alternation starting from currentResponseMode */ + for (i = 0; i < dcResponseModeIterationCount_g; i++) + { + if (i % 2 == 0) + { + /* Even iterations (0, 2, 4...): use initial mode from test params + */ + currentMode = testParams->currentResponseMode; + } + else + { + /* Odd iterations (1, 3, 5...): use alternate mode */ + currentMode = alternateMode; + } + } + + return currentMode; +} +EXPORT_SYMBOL(getDcResponseModeWithIteration); + +CpaStatus enableDcResponseModeIteration(Cpa32U count) +{ + CpaStatus status; + + if (count < 1) + { + PRINT_ERR("Invalid iteration count %d, using default (1)\n", count); + count = 1; + } + + status = setDcResponseModeIterationCount(count); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set DC response mode iteration count\n"); + return CPA_STATUS_FAIL; + } + PRINT("DC response mode iteration %s with count=%d " + "(applies to both compression and decompression)\n", + (count > 1) ? "ENABLED" : "DISABLED", + count); + return CPA_STATUS_SUCCESS; } -EXPORT_SYMBOL(setDcPollingThreadsInterval); +EXPORT_SYMBOL(enableDcResponseModeIteration); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ /*********** Call Back Function **************/ void dcPerformCallback(void *pCallbackTag, CpaStatus status) @@ -242,6 +1395,12 @@ volatile CpaBoolean dc_service_started_g = CPA_FALSE; /* Flag to indicate if the DC polling threads have been created */ volatile CpaBoolean dc_polling_started_g = CPA_FALSE; +static volatile CpaBoolean decomp_service_started_g = CPA_FALSE; +static CpaInstanceHandle *decompInstances_g = NULL; +static volatile CpaBoolean decomp_polling_started_g = CPA_FALSE; +static sample_code_thread_t *decompPollingThread_g = NULL; +static Cpa32U numDecompPolledInstances_g = 0; + /* flag to define weather to use zlib to compress data before decompression*/ CpaBoolean useZlib_g = CPA_FALSE; EXPORT_SYMBOL(useZlib_g); @@ -606,6 +1765,60 @@ void setSetupCnVRequestFlag(Cpa32U flag) } EXPORT_SYMBOL(setSetupCnVRequestFlag); +void getDecompNumInstances(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &numDecompInstances_g); + if (CPA_STATUS_SUCCESS != status) + { + numDecompInstances_g = 0; + } +} +EXPORT_SYMBOL(getDecompNumInstances); + +CpaStatus dcGetInstances(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle **pInstHandle, + Cpa16U *numInstances) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + + if (NULL == pInstHandle || NULL == numInstances) + { + PRINT_ERR("pInstHandle or numInstances is NULL\n"); + return CPA_STATUS_FAIL; + } + + status = cpaGetNumInstances(accelSrvType, numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR(" Unable to get number of DC instances\n"); + return CPA_STATUS_FAIL; + } + + if (0 == *numInstances) + { + PRINT_ERR(" DC Instances are not present\n"); + return CPA_STATUS_FAIL; + } + *pInstHandle = qaeMemAlloc(sizeof(CpaInstanceHandle) * *numInstances); + if (NULL == *pInstHandle) + { + PRINT_ERR("Unable to allocate Memory for Instances\n"); + return CPA_STATUS_FAIL; + } + status = cpaGetInstances(accelSrvType, *numInstances, *pInstHandle); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR(" Unable to get DC instances\n"); + qaeMemFree((void **)pInstHandle); + return CPA_STATUS_FAIL; + } + + return status; +} +EXPORT_SYMBOL(dcGetInstances); + CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) { @@ -616,44 +1829,291 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) Cpa32U nProcessorsOnline = 0; Cpa16U numBuffers = 0; CpaBufferList **tempBufferList = NULL; - + + /*if the service started flag is false*/ + if (dc_service_started_g == CPA_FALSE) + { + /* Get the number of DC Instances */ + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, + &numDcInstances_g); + /* Check the status */ + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to Get Number of DC instances\n"); + return CPA_STATUS_FAIL; + } + /* Check if at least one DC instance are present */ + if (0 == numDcInstances_g) + { + PRINT_ERR(" DC Instances are not present\n"); + return CPA_STATUS_FAIL; + } + /* Allocate memory for all the instances */ + dcInstances_g = + qaeMemAlloc(sizeof(CpaInstanceHandle) * numDcInstances_g); + /* Check For NULL */ + if (NULL == dcInstances_g) + { + PRINT_ERR(" Unable to allocate memory for Instances \n"); + return CPA_STATUS_FAIL; + } + + /* Get DC Instances */ + status = cpaGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, numDcInstances_g, dcInstances_g); + /* Check Status */ + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to Get DC instances\n"); + qaeMemFree((void **)&dcInstances_g); + return CPA_STATUS_FAIL; + } + + /* Allocate the buffer list pointers to the number of Instances + * this buffer list list is used only in case of dynamic + * compression + */ + pInterBuffList_g = (CpaBufferList ***)qaeMemAlloc( + numDcInstances_g * sizeof(CpaBufferList **)); + /* Check For NULL */ + if (NULL == pInterBuffList_g) + { + PRINT_ERR("Unable to allocate dynamic buffer List\n"); + qaeMemFree((void **)&dcInstances_g); + return CPA_STATUS_FAIL; + } + + /* Initialize memory for buffer lists */ + memset( + pInterBuffList_g, 0, numDcInstances_g * sizeof(CpaBufferList **)); + + /* Start the Loop to create Buffer List for each instance*/ + for (i = 0; i < numDcInstances_g; i++) + { + /* get the Node ID for each instance Handle */ + status = sampleCodeDcGetNode(dcInstances_g[i], &nodeId); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get NodeId\n"); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + status = + cpaDcGetNumIntermediateBuffers(dcInstances_g[i], &numBuffers); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to allocate Memory for Dynamic Buffer\n"); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + if (numBuffers > 0) + { + /* allocate the buffer list memory for the dynamic Buffers + * only applicable for CPM prior to gen4 as it is done in HW */ + pInterBuffList_g[i] = + qaeMemAllocNUMA(sizeof(CpaBufferList *) * numBuffers, + nodeId, + BYTE_ALIGNMENT_64); + if (NULL == pInterBuffList_g[i]) + { + PRINT_ERR("Unable to allocate Memory for Dynamic Buffer\n"); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + + /* get the size of the Private meta data + * needed to create Buffer List + */ + status = cpaDcBufferListGetMetaSize( + dcInstances_g[i], numBuffers, &size); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Get Meta Size Data Failed\n"); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + } + tempBufferList = pInterBuffList_g[i]; + for (k = 0; k < numBuffers; k++) + { + tempBufferList[k] = (CpaBufferList *)qaeMemAllocNUMA( + sizeof(CpaBufferList), nodeId, BYTE_ALIGNMENT_64); + if (NULL == tempBufferList[k]) + { + PRINT(" %s:: Unable to allocate memory for " + "tempBufferList\n", + __FUNCTION__); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(tempBufferList, k + 1); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + tempBufferList[k]->pPrivateMetaData = + qaeMemAllocNUMA(size, nodeId, BYTE_ALIGNMENT_64); + if (NULL == tempBufferList[k]->pPrivateMetaData) + { + PRINT(" %s:: Unable to allocate memory for " + "pPrivateMetaData\n", + __FUNCTION__); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(tempBufferList, k + 1); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + tempBufferList[k]->numBuffers = ONE_BUFFER_DC; + /* allocate flat buffers */ + tempBufferList[k]->pBuffers = qaeMemAllocNUMA( + (sizeof(CpaFlatBuffer)), nodeId, BYTE_ALIGNMENT_64); + if (NULL == tempBufferList[k]->pBuffers) + { + PRINT_ERR("Unable to allocate memory for pBuffers\n"); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(tempBufferList, k + 1); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + + tempBufferList[k]->pBuffers[0].pData = qaeMemAllocNUMA( + (size_t)expansionFactor_g * EXTRA_BUFFER * buffSize, + nodeId, + BYTE_ALIGNMENT_64); + if (NULL == tempBufferList[k]->pBuffers[0].pData) + { + PRINT_ERR("Unable to allocate Memory for pBuffers\n"); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(tempBufferList, k + 1); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + tempBufferList[k]->pBuffers[0].dataLenInBytes = + expansionFactor_g * EXTRA_BUFFER * buffSize; + } + + /* When starting the DC Instance, the API expects that the + * private meta data should be greater than the dataLength + */ + /* Configure memory Configuration Function */ + status = cpaDcSetAddressTranslation( + dcInstances_g[i], (CpaVirtualToPhysical)qaeVirtToPhysNUMA); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error setting memory config for instance\n"); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(pInterBuffList_g[i], numBuffers); + qaeMemFreeNUMA((void **)&pInterBuffList_g[i]); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + /* Start DC Instance */ + status = cpaDcStartInstance( + dcInstances_g[i], numBuffers, pInterBuffList_g[i]); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to start DC Instance\n"); + qaeMemFree((void **)&dcInstances_g); + freeDcBufferList(pInterBuffList_g[i], numBuffers); + qaeMemFreeNUMA((void **)&pInterBuffList_g[i]); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + } + /*set the started flag to true*/ + dc_service_started_g = CPA_TRUE; + } + + /*determine number of cores on system and limit the number of cores to be + * used to be the smaller of the numberOf Instances or the number of cores*/ + nProcessorsOnline = sampleCodeGetNumberOfCpus(); + if (nProcessorsOnline > numDcInstances_g) + { + setCoreLimit(numDcInstances_g); + } + return status; +} +EXPORT_SYMBOL(startDcServices); + +CpaStatus startServices(const CpaAccelerationServiceType serviceType, + Cpa32U buffSize, + Cpa32U numBuffs) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U size = 0; + Cpa32U i = 0, k = 0; + Cpa32U nodeId = 0; + Cpa32U nProcessorsOnline = 0; + Cpa16U numBuffers = 0; + CpaBufferList **tempBufferList = NULL; +#ifdef SC_DEV_INFO_ENABLED + CpaBoolean intermediateBuffersRequired = CPA_TRUE; +#endif /*if the service started flag is false*/ - if (dc_service_started_g == CPA_FALSE) + if (serviceType == CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION) { - /* Get the number of DC Instances */ - status = cpaDcGetNumInstances(&numDcInstances_g); - /* Check the status */ - if (CPA_STATUS_SUCCESS != status) + if (decomp_service_started_g == CPA_TRUE) { - PRINT_ERR("Unable to Get Number of DC instances\n"); - return CPA_STATUS_FAIL; + return CPA_STATUS_SUCCESS; } - /* Check if at least one DC instance are present */ - if (0 == numDcInstances_g) + + status = dcGetInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &decompInstances_g, + &numDecompInstances_g); + if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR(" DC Instances are not present\n"); + PRINT_ERR("Unable to get DECOMP instances\n"); return CPA_STATUS_FAIL; } - /* Allocate memory for all the instances */ - dcInstances_g = - qaeMemAlloc(sizeof(CpaInstanceHandle) * numDcInstances_g); - /* Check For NULL */ - if (NULL == dcInstances_g) + + for (i = 0; i < numDecompInstances_g; i++) { - PRINT_ERR(" Unable to allocate memory for Instances \n"); - return CPA_STATUS_FAIL; + status = cpaDcSetAddressTranslation( + decompInstances_g[i], (CpaVirtualToPhysical)qaeVirtToPhysNUMA); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error setting address translation for DECOMP " + "instance %d\n", + i); + qaeMemFree((void **)&decompInstances_g); + numDecompInstances_g = 0; + return CPA_STATUS_FAIL; + } + + status = cpaDcStartInstance(decompInstances_g[i], 0, NULL); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to start DECOMP instance %d\n", i); + qaeMemFree((void **)&decompInstances_g); + numDecompInstances_g = 0; + return CPA_STATUS_FAIL; + } } - /* Get DC Instances */ - status = cpaDcGetInstances(numDcInstances_g, dcInstances_g); - /* Check Status */ - if (CPA_STATUS_SUCCESS != status) + decomp_service_started_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; + } + + if (dc_service_started_g == CPA_FALSE) + { + if (serviceType == CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION) { - PRINT_ERR("Unable to Get DC instances\n"); - qaeMemFree((void **)&dcInstances_g); + status = dcGetInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &dcInstances_g, + &numDcInstances_g); + } + else + { + status = dcGetInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, + &dcInstances_g, + &numDcInstances_g); + } + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Unable to get instances\n"); return CPA_STATUS_FAIL; } - /* Allocate the buffer list pointers to the number of Instances * this buffer list list is used only in case of dynamic * compression @@ -693,6 +2153,28 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) qaeMemFree((void **)&pInterBuffList_g); return CPA_STATUS_FAIL; } +#ifdef SC_DEV_INFO_ENABLED + status = getIntermediateBuffersRequired( + dcInstances_g[i], &intermediateBuffersRequired); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("getIntermediateBuffersRequired failed\n"); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } + + if (intermediateBuffersRequired == CPA_FALSE && numBuffers != 0) + { + PRINT_ERR( + "cpaDcGetNumIntermediateBuffers returned an unexpected " + "non-zero(%d) value for this device generation\n", + numBuffers); + qaeMemFree((void **)&dcInstances_g); + qaeMemFree((void **)&pInterBuffList_g); + return CPA_STATUS_FAIL; + } +#endif if (numBuffers > 0) { /* allocate the buffer list memory for the dynamic Buffers @@ -761,7 +2243,6 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) qaeMemFree((void **)&pInterBuffList_g); return CPA_STATUS_FAIL; } - tempBufferList[k]->pBuffers[0].pData = qaeMemAllocNUMA( (size_t)expansionFactor_g * EXTRA_BUFFER * buffSize, nodeId, @@ -778,7 +2259,7 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) expansionFactor_g * EXTRA_BUFFER * buffSize; } - /* When starting the DC Instance, the API expects that the + /* When starting the Instance, the API expects that the * private meta data should be greater than the dataLength */ /* Configure memory Configuration Function */ @@ -793,12 +2274,12 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) qaeMemFree((void **)&pInterBuffList_g); return CPA_STATUS_FAIL; } - /* Start DC Instance */ + /* Start Instance */ status = cpaDcStartInstance( dcInstances_g[i], numBuffers, pInterBuffList_g[i]); if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR("Unable to start DC Instance\n"); + PRINT_ERR("Unable to start Instance\n"); qaeMemFree((void **)&dcInstances_g); freeDcBufferList(pInterBuffList_g[i], numBuffers); qaeMemFreeNUMA((void **)&pInterBuffList_g[i]); @@ -809,7 +2290,6 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) /*set the started flag to true*/ dc_service_started_g = CPA_TRUE; } - /*determine number of cores on system and limit the number of cores to be * used to be the smaller of the numberOf Instances or the number of cores*/ nProcessorsOnline = sampleCodeGetNumberOfCpus(); @@ -819,7 +2299,7 @@ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs) } return status; } -EXPORT_SYMBOL(startDcServices); +EXPORT_SYMBOL(startServices); void freeCorpus(void) { @@ -860,6 +2340,37 @@ CpaStatus stopDcServices(void) CpaBufferList **tempBufferList = NULL; Cpa16U numBuffers = 0; + setDecompServiceRequest(0); + + if (decomp_service_started_g == CPA_TRUE) + { + decomp_service_started_g = CPA_FALSE; + } + if (decomp_polling_started_g == CPA_TRUE) + { + decomp_polling_started_g = CPA_FALSE; + for (i = 0; i < numDecompPolledInstances_g; i++) + { + sampleCodeThreadJoin(&decompPollingThread_g[i]); + } + if (numDecompPolledInstances_g > 0) + { + qaeMemFree((void **)&decompPollingThread_g); + numDecompPolledInstances_g = 0; + } + } + + if (decompInstances_g != NULL) + { + for (i = 0; i < numDecompInstances_g; i++) + { + cpaDcStopInstance(decompInstances_g[i]); + } + qaeMemFree((void **)&decompInstances_g); + decompInstances_g = NULL; + numDecompInstances_g = 0; + } + /*stop only if the services is in a started state*/ if (dc_service_started_g == CPA_TRUE) { @@ -913,6 +2424,7 @@ CpaStatus stopDcServices(void) { qaeMemFree((void **)&dcInstances_g); dcInstances_g = NULL; + numDcInstances_g = 0; } return status; } @@ -957,44 +2469,8 @@ CpaStatus calculateRequireBuffers(compression_test_params_t *dcSetup) } EXPORT_SYMBOL(calculateRequireBuffers); - -static CpaStatus trySetupDynamicPoll(CpaInstanceHandle instanceHandle, - performance_func_t *pollFn) -{ #if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) - /* Dynamic polling not available in this configuration */ - return CPA_STATUS_UNSUPPORTED; #endif /* USER_SPACE && !SC_EPOLL_DISABLED */ - /* Event-based polling not applicable in this configuration */ - return CPA_STATUS_UNSUPPORTED; -} - - -static CpaStatus trySetupLegacyEventPoll(CpaInstanceHandle instanceHandle, - performance_func_t *pollFn) -{ -#if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) - CpaStatus status = CPA_STATUS_SUCCESS; - int fd = -1; - - status = icp_sal_DcGetFileDescriptor(instanceHandle, &fd); - if (CPA_STATUS_SUCCESS == status) - { - *pollFn = sampleCodeDcEventPoll; - icp_sal_DcPutFileDescriptor(instanceHandle, fd); - return CPA_STATUS_SUCCESS; - } - else if (CPA_STATUS_FAIL == status) - { - return CPA_STATUS_FAIL; - } - /* else feature is unsupported */ - return CPA_STATUS_UNSUPPORTED; -#else - /* Event-based polling not applicable in this configuration */ - return CPA_STATUS_UNSUPPORTED; -#endif -} CpaStatus dcCreatePollingThreadsIfPollingIsEnabled(void) { @@ -1043,22 +2519,9 @@ CpaStatus dcCreatePollingThreadsIfPollingIsEnabled(void) { numDcPolledInstances_g++; #if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) - /* Try to set up dynamic polling with runtime API check */ - status = trySetupDynamicPoll(dcInstances_g[i], &pollFnArr[i]); - if (CPA_STATUS_FAIL == status) - { - PRINT_ERR("Error checking dynamic polling support for " - "instance #%d\n", - i); - qaeMemFree((void **)&instanceInfo2); - qaeMemFree((void **)&pollFnArr); - return CPA_STATUS_FAIL; - } - /* If unsupported, try legacy event polling as fallback */ - if (CPA_STATUS_UNSUPPORTED == status) { - status = trySetupLegacyEventPoll(dcInstances_g[i], - &pollFnArr[i]); + status = trySetupDcLegacyEventPoll(dcInstances_g[i], + &pollFnArr[i]); if (CPA_STATUS_FAIL == status) { PRINT_ERR( @@ -1339,6 +2802,123 @@ void sampleCodeDcPoll(CpaInstanceHandle instanceHandle_in) sampleCodeThreadExit(); } +static void sampleCodeDecompPoll(CpaInstanceHandle instanceHandle_in) +{ + CpaStatus status = CPA_STATUS_FAIL; +#ifdef USER_SPACE + struct timespec reqTime, remTime; + reqTime.tv_sec = 0; + reqTime.tv_nsec = dcPollingThreadsInterval_g; +#endif + while (decomp_service_started_g == CPA_TRUE) + { + status = icp_sal_DcPollInstance(instanceHandle_in, 0); + if (CPA_STATUS_SUCCESS == status || CPA_STATUS_RETRY == status) + { + /* do nothing */ + } + else + { + PRINT_ERR("ERROR icp_sal_DcPollInstance returned status %d " + "for DECOMP instance\n", + status); + error_flag_g = CPA_TRUE; + break; + } +#ifdef USER_SPACE + nanosleep(&reqTime, &remTime); +#else + sampleCodeSleepMilliSec(DEFAULT_POLL_INTERVAL_KERNEL); +#endif + } + sampleCodeThreadExit(); +} + +CpaStatus dcCreateDecompPollingThreads(void) +{ + CpaInstanceInfo2 instanceInfo2 = { 0 }; + Cpa16U i = 0, j = 0, numCreatedPollingThreads = 0; + Cpa32U coreAffinity = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + if (CPA_TRUE == decomp_polling_started_g) + { + return CPA_STATUS_SUCCESS; + } + if (0 == numDecompInstances_g || NULL == decompInstances_g) + { + return CPA_STATUS_SUCCESS; + } + for (i = 0; i < numDecompInstances_g; i++) + { + status = cpaDcInstanceGetInfo2(decompInstances_g[i], &instanceInfo2); + if (CPA_STATUS_SUCCESS != status) + { + return CPA_STATUS_FAIL; + } + if (CPA_TRUE == instanceInfo2.isPolled) + { + numDecompPolledInstances_g++; + } + } + if (0 == numDecompPolledInstances_g) + { + return CPA_STATUS_SUCCESS; + } + + decompPollingThread_g = + qaeMemAlloc(numDecompPolledInstances_g * sizeof(sample_code_thread_t)); + if (NULL == decompPollingThread_g) + { + PRINT_ERR("Failed to allocate memory for DECOMP polling threads\n"); + return CPA_STATUS_FAIL; + } + + for (i = 0; i < numDecompInstances_g; i++) + { + status = cpaDcInstanceGetInfo2(decompInstances_g[i], &instanceInfo2); + if (CPA_STATUS_SUCCESS != status) + { + qaeMemFree((void **)&decompPollingThread_g); + return CPA_STATUS_FAIL; + } + if (CPA_TRUE == instanceInfo2.isPolled) + { + status = sampleCodeThreadCreate( + &decompPollingThread_g[numCreatedPollingThreads], + NULL, + (performance_func_t)sampleCodeDecompPoll, + decompInstances_g[i]); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error starting DECOMP polling thread %d\n", status); + qaeMemFree((void **)&decompPollingThread_g); + return CPA_STATUS_FAIL; + } + for (j = 0; j < CPA_MAX_CORES; j++) + { + if (CPA_BITMAP_BIT_TEST(instanceInfo2.coreAffinity, j)) + { +#if defined(USER_SPACE) + coreAffinity = j; +#else + coreAffinity = j + 1; +#endif + break; + } + } + sampleCodeThreadBind( + &decompPollingThread_g[numCreatedPollingThreads], coreAffinity); + sampleCodeThreadStart( + &decompPollingThread_g[numCreatedPollingThreads]); + numCreatedPollingThreads++; + } + } + decomp_polling_started_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(dcCreateDecompPollingThreads); + CpaStatus stopDcServicesFromPrintStats(thread_creation_data_t *dummy_ptr) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -1822,7 +3402,6 @@ void dcPrintTestData(compression_test_params_t *dcSetup) } EXPORT_SYMBOL(dcPrintTestData); -#if defined(SC_CHAINING_ENABLED) || defined(SC_CHAINING_EXT_ENABLED) void dcChainPrintTestData(compression_test_params_t *chainSetup) { PRINT("API "); @@ -2004,8 +3583,6 @@ void dcChainPrintTestData(compression_test_params_t *chainSetup) } EXPORT_SYMBOL(dcChainPrintTestData); -#endif - void dcDpSetBytesProducedAndConsumed(CpaDcDpOpData ***opdata, perf_data_t *perfData, compression_test_params_t *setup) @@ -2186,8 +3763,8 @@ CpaStatus dcPollNumOperations(perf_data_t *pPerfData, return CPA_STATUS_SUCCESS; } EXPORT_SYMBOL(dcPollNumOperations); - -CpaStatus dynamicHuffmanEnabled(CpaInstanceHandle *dcInstanceHandle, +CpaStatus dynamicHuffmanEnabled(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *dcInstanceHandle, CpaBoolean *isEnabled) { CpaDcInstanceCapabilities capabilities = {0}; @@ -2200,11 +3777,11 @@ CpaStatus dynamicHuffmanEnabled(CpaInstanceHandle *dcInstanceHandle, if (NULL == dcInstanceHandle) { - status = cpaDcGetNumInstances(&numInstances); + status = cpaGetNumInstances(accelSrvType, &numInstances); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("Unable to check if dynamic Huffman is enabled, " - "cpaDcGetNumInstances failed with status: %d\n", + "cpaGetNumInstances failed with status: %d\n", status); return CPA_STATUS_FAIL; } @@ -2214,11 +3791,11 @@ CpaStatus dynamicHuffmanEnabled(CpaInstanceHandle *dcInstanceHandle, "No DC instances available"); return CPA_STATUS_FAIL; } - status = cpaDcGetInstances(1, &pLocalDcInstanceHandle); + status = cpaGetInstances(accelSrvType, 1, &pLocalDcInstanceHandle); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("Unable to check if dynamic Huffman is enabled, " - "cpaDcGetInstances failed with status: %d" + "cpaGetInstances failed with status: %d" "\n", status); return CPA_STATUS_FAIL; @@ -2245,6 +3822,79 @@ CpaStatus dynamicHuffmanEnabled(CpaInstanceHandle *dcInstanceHandle, } EXPORT_SYMBOL(dynamicHuffmanEnabled); +CpaStatus staticHuffmanEnabled(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *dcInstanceHandle, + CpaBoolean *isEnabled) +{ + CpaStatus status = CPA_STATUS_FAIL; + CpaInstanceHandle pLocalDcInstanceHandle = NULL; + CpaDcCapabilityReq capabilityReq = { 0 }; + capabilityReq.capId = CPA_DC_CAP_BOOL_STATIC_HUFFMAN; + capabilityReq.algo = CPA_DC_DEFLATE; + capabilityReq.dir = (accelSrvType == CPA_ACC_SVC_TYPE_DATA_COMPRESSION) + ? CPA_DC_DIR_COMPRESS + : CPA_DC_DIR_DECOMPRESS; + CpaDcCapabilityResp capabilityResp = { 0 }; + Cpa16U numInstances = 0; + + if (NULL == isEnabled) + { + PRINT_ERR("isEnabled is NULL\n"); + return CPA_STATUS_FAIL; + } + + /* Initialize to CPA_FALSE */ + *isEnabled = CPA_FALSE; + + if (NULL == dcInstanceHandle) + { + status = cpaGetNumInstances(accelSrvType, &numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to check if static Huffman is enabled, " + "cpaGetNumInstances failed with status: %d\n", + status); + return CPA_STATUS_FAIL; + } + if (0 == numInstances) + { + PRINT_ERR("Unable to check if static Huffman is enabled, " + "No DC instances available"); + return CPA_STATUS_FAIL; + } + status = cpaGetInstances(accelSrvType, 1, &pLocalDcInstanceHandle); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to check if static Huffman is enabled, " + "cpaGetInstances failed with status: %d" + "\n", + status); + return CPA_STATUS_FAIL; + } + } + else + { + pLocalDcInstanceHandle = *dcInstanceHandle; + } + + status = cpaDcQueryCapabilityByType( + pLocalDcInstanceHandle, capabilityReq, &capabilityResp); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to check if static Huffman is enabled, " + "cpaDcQueryCapabilityByType failed with status: %d" + "\n", + status); + return CPA_STATUS_FAIL; + } + + *isEnabled = capabilityResp.boolStatus; + + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(staticHuffmanEnabled); + CpaStatus dcSampleCreateStatefulContextBuffer(Cpa32U buffSize, Cpa32U metaSize, CpaBufferList **pBuffListArray, @@ -2550,3 +4200,41 @@ CpaStatus sampleRemoveDcDpSession(CpaInstanceHandle dcInstance, } EXPORT_SYMBOL(sampleRemoveDcDpSession); +CpaStatus getDcCapabilityStatusForAlg(CpaInstanceHandle dcInstance, + Cpa32U capId, + CpaDcCompType algorithm, + CpaDcSessionDir direction, + CpaBoolean *pCapStatus) + +{ + CpaDcCapabilityReq capabilityReq = { 0 }; + CpaDcCapabilityResp capabilityResp = { 0 }; + CpaStatus status = CPA_STATUS_FAIL; + + capabilityReq.capId = capId; + capabilityReq.algo = algorithm; + capabilityReq.dir = direction; + + status = + cpaDcQueryCapabilityByType(dcInstance, capabilityReq, &capabilityResp); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get dc capability status\n"); + return CPA_STATUS_FAIL; + } + + if (NULL == pCapStatus) + { + PRINT_ERR("pCapStatus is NULL\n"); + status = CPA_STATUS_FAIL; + } + else + { + *pCapStatus = capabilityResp.boolStatus; + } + + return status; +} +EXPORT_SYMBOL(getDcCapabilityStatusForAlg); + diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.h b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.h index e8762b41..d37df342 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_dc_utils.h @@ -27,6 +27,7 @@ #include "cpa_sample_code_dc_perf.h" #include "cpa.h" #include "cpa_dc.h" +#include "cpa_dc_capabilities.h" #include "cpa_dc_dp.h" #include "cpa_sample_code_framework.h" #include "qat_compression_cnv_utils.h" @@ -177,6 +178,40 @@ CpaStatus populateCorpus(Cpa32U buffSize, corpus_type_t corpusType); ******************************************************************************/ CpaStatus startDcServices(Cpa32U buffSize, Cpa32U numBuffs); +/** + * ***************************************************************************** + * @ingroup compressionThreads + * startServices + * + * @description + * this API starts the services of the given type if not already started + * @threadSafe + * No + * + * @param[in] serviceType Acceleration Service required + * @param[in] buffsize buffer size for intermittent buffers + * @param[in] numBuffs number of intermittent Buffers required + * + ******************************************************************************/ +CpaStatus startServices(const CpaAccelerationServiceType serviceType, + Cpa32U buffSize, + Cpa32U numBuffs); +/** + ***************************************************************************** + * @ingroup compressionThreads + * dcCreateDecompPollingThreads + * + * @description + * This function checks whether each instance handle is set for polling + * and will allocate create and start the same number polling threads + * as they are polling instances. + * @pre numDecompInstances_g is set and all instances have been started. + * @post numDecompPolledInstances_g is set by the function to the number of + * polling instances available. + * + *****************************************************************************/ +CpaStatus dcCreateDecompPollingThreads(void); + /** * ***************************************************************************** * @ingroup compressionThreads @@ -353,45 +388,6 @@ CpaStatus sampleCodeDcGetNode(CpaInstanceHandle instanceHandle, Cpa32U *node); ******************************************************************************/ void sampleCodeDcPoll(CpaInstanceHandle instanceHandle_in); -/** - ***************************************************************************** - * @ingroup compressionThreads - * @description - * Dynamic polling function for Data Compression instances that supports - * both epoll-based event notification and traditional busy-wait polling. - * The function dynamically switches between polling modes based on the - * instance's current response mode setting, allowing runtime optimization - * of polling behavior. - * - * @context - * This function runs in a polling thread and continues until the DC - * service is stopped (dc_service_started_g == CPA_FALSE). - * - * @assumptions - * - instanceHandle is valid and initialized - * - SUPPORTED_FEAT_EPOLL is defined and epoll is available - * - dcPollingThreadsInterval_g is set to appropriate nanoseconds value - * - * @sideEffects - * - May temporarily change instance response mode for epoll setup - * - Sets error_flag_g on critical errors - * - Allocates memory for epoll events (cleaned up before return) - * - * @blocking - * Yes - blocks on epoll_wait() or nanosleep() calls - * - * @reentrant - * No - * - * @threadSafe - * No - should be called from a single polling thread per instance - * - * @param[in] instanceHandle DC instance handle to poll - * - * @return void - ******************************************************************************/ -void sampleCodeDcDynamicPoll(CpaInstanceHandle instanceHandle_in); - /** * ***************************************************************************** * @ingroup compressionThreads @@ -423,6 +419,9 @@ CpaStatus dcPrintStats(thread_creation_data_t *data); ******************************************************************************/ CpaStatus dcChainPrintStats(thread_creation_data_t *data); +CpaStatus dcGetInstances(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle **pInstHandle, + Cpa16U *numInstances); /** * ***************************************************************************** * @ingroup compressionThreads @@ -544,6 +543,7 @@ Cpa32U getDcThroughput(Cpa32U totalBytes, * dcInstanceHandle is NULL a local instance, i.e. the * first instance from cpaDcGetNumInstances() will be * used to determine if dynamic Huffman is enabled. + * @param[in] accelSrvType service type of the instance. * @param[in,out] isEnabled Pointer to CpaBoolean. When set to CPA_TRUE * the instance handle has dynamic Huffman enabled. * Will be set to CPA_FALSE for all error conditions @@ -552,8 +552,33 @@ Cpa32U getDcThroughput(Cpa32U totalBytes, * @retval CPA_STATUS_SUCCESS Instance query for dynamic compression succeeded * @retval CPA_STATUS_FAIL Instance query for dynamic compression failed *****************************************************************************/ -CpaStatus dynamicHuffmanEnabled(CpaInstanceHandle *dcInstanceHandle, +CpaStatus dynamicHuffmanEnabled(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *dcInstanceHandle, CpaBoolean *isEnabled); +/** + ***************************************************************************** + * @ingroup compressionThreads + * staticHuffmanEnabled + * + * @description + * Determines if a given instance has Static Huffman enabled. + * + * @param[in] dcInstanceHandle Pointer to CpaInstanceHandle. If + * dcInstanceHandle is NULL a local instance, i.e. the + * first instance from cpaDcGetNumInstances() will be + * used to determine if static Huffman is enabled. + *@param[in] accelSrvType service type of the instance. + * @param[in,out] isEnabled Pointer to CpaBoolean. When set to CPA_TRUE + * the instance handle has static Huffman enabled. + * Will be set to CPA_FALSE for all error conditions + * or when static Huffman is not enabled for the + * instance. + * @retval CPA_STATUS_SUCCESS Instance query for static compression succeeded + * @retval CPA_STATUS_FAIL Instance query for static compression failed + *****************************************************************************/ +CpaStatus staticHuffmanEnabled(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *dcInstanceHandle, + CpaBoolean *isEnabled); /*This function tells the compression sample code to use zLib software to * compress the data prior to calling the decompression*/ @@ -592,6 +617,449 @@ Cpa32U getSetupCnVRequestFlag(void); void setSetupCnVRequestFlag(Cpa32U flag); void setDcPollingThreadsInterval(long interval); +void getDecompNumInstances(void); + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/* Core response mode configuration functions */ +/** + ***************************************************************************** + * @ingroup compressionThreads + * Set the response mode for DC instances + * + * @description + * This function sets the CpaInstanceResponseMode that will be + * applied to DC instances specified by the mask. This explicitly + * overrides the QAT library's default response mode. + * + * @param[in] responseMode The response mode to set + * + *****************************************************************************/ +CpaStatus setDcInstanceResponseMode(CpaInstanceResponseMode responseMode); +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceResponseModeByValue + * + * @description + * Unified user-friendly function that accepts response mode as user input + * values (0 for polling, 1 for event notification) and configures ALL + * available DC instances. This function maps the user input to the correct + * CpaInstanceResponseMode enum values and automatically applies to all + * instances, making it the primary function for response mode + * configuration. + * + * @param[in] userMode User input mode (0 = polling, 1 = event notification) + * + *****************************************************************************/ +CpaStatus setDcInstanceResponseModeByValue(Cpa32U userMode); +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceResponseModeWithMask + * + * @description + * Combined function that sets both the response mode and instance mask + * in a single call. This is the recommended function for most use cases + * as it ensures both the mode and target instances are set atomically. + * + * @param[in] userMode User input mode (0 = polling, 1 = event notification) + * @param[in] mask 64-bit mask indicating which instances to configure + * (bit 0 = instance 0, bit 1 = instance 1, etc.) + * + *****************************************************************************/ +CpaStatus setDcInstanceResponseModeWithMask(Cpa32U userMode, Cpa64U mask); +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceResponseModeForRange + * + * @description + * Convenience function to set response mode for a range of instances. + * This is useful when you want to configure consecutive instances. + * + * @param[in] userMode User input mode (0 = polling, 1 = event notification) + * @param[in] startInst First instance to configure (0-based) + * @param[in] endInst Last instance to configure (inclusive, 0-based) + * + *****************************************************************************/ +CpaStatus setDcInstanceResponseModeForRange(Cpa32U userMode, + Cpa16U startInst, + Cpa16U endInst); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Get the configured response mode for DC instances + * + * @description + * This function returns the configured CpaInstanceResponseMode + * that will be applied to DC instances, if one has been set. + * + * @retval CpaInstanceResponseMode Configured response mode + * + *****************************************************************************/ +CpaInstanceResponseMode getDcInstanceResponseMode(void); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Check if response mode has been explicitly configured + * + * @description + * This function returns whether a response mode has been explicitly + * configured, indicating that the QAT library's default should be + * overridden. + * + * @retval CpaBoolean CPA_TRUE if configured, CPA_FALSE if using defaults + * + *****************************************************************************/ +CpaBoolean isDcInstanceResponseModeConfigured(void); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Clear/reset the response mode configuration + * + * @description + * This function clears any explicitly configured response mode, + * allowing the QAT library's default to be used again. + * + *****************************************************************************/ +CpaStatus clearDcInstanceResponseModeConfiguration(void); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Apply configured response modes to DC instances + * + * @description + * This function applies the configured response modes to the actual + * DC instances based on the current mask and configuration. This should + * be called after DC services are started but before polling threads + * are created. + * + * @retval CpaStatus Status of the operation + * + *****************************************************************************/ +CpaStatus applyDcInstanceResponseModeConfiguration(void); + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +/* Coalescing timer configuration functions (require driver APIs only + * available when SUPPORTED_FEAT_INT_COALESCING_TIMER is set) */ +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceCoalescingTimer + * + * @description + * Sets the interrupt coalescing timer value (in nanoseconds) that will be + * applied to DC instances specified by the mask. This explicitly + * overrides the QAT library's default coalescing timer. + * + * @param[in] coalescingTimerInNs Coalescing timer value in nanoseconds + * + *****************************************************************************/ +CpaStatus setDcInstanceCoalescingTimer(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceCoalescingTimerWithMask + * + * @description + * Combined function that sets both the coalescing timer value and the + * instance mask in a single call. + * + * @param[in] coalescingTimerInNs Coalescing timer value in nanoseconds + * @param[in] mask 64-bit bitmask of instances to configure + * + *****************************************************************************/ +CpaStatus setDcInstanceCoalescingTimerWithMask(Cpa32U coalescingTimerInNs, + Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceCoalescingTimerForRange + * + * @description + * Convenience function to set the coalescing timer for a range of + * consecutive instances. + * + * @param[in] coalescingTimerInNs Coalescing timer value in nanoseconds + * @param[in] startInst First instance to configure (0-based) + * @param[in] endInst Last instance to configure (inclusive) + * + *****************************************************************************/ +CpaStatus setDcInstanceCoalescingTimerForRange(Cpa32U coalescingTimerInNs, + Cpa16U startInst, + Cpa16U endInst); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * getDcInstanceCoalescingTimer + * + * @description + * Returns the configured coalescing timer value (in nanoseconds) that + * will be applied to DC instances, if one has been set. + * + *****************************************************************************/ +Cpa32U getDcInstanceCoalescingTimer(void); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * isDcInstanceCoalescingTimerConfigured + * + * @description + * Returns whether a coalescing timer value has been explicitly + * configured, indicating that the QAT library default should be + * overridden. + * + *****************************************************************************/ +CpaBoolean isDcInstanceCoalescingTimerConfigured(void); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * clearDcInstanceCoalescingTimerConfiguration + * + * @description + * Clears any explicitly configured coalescing timer, allowing the QAT + * library default to be used again. + * + *****************************************************************************/ +CpaStatus clearDcInstanceCoalescingTimerConfiguration(void); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * setDcInstanceCoalescingTimerMask + * + * @description + * Sets a 64-bit mask to control which DC instances should have the + * configured coalescing timer applied (supports up to 64 instances). + * + * @param[in] mask 64-bit bitmask indicating which instances to configure + * + *****************************************************************************/ +void setDcInstanceCoalescingTimerMask(Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * getDcInstanceCoalescingTimerMask + * + * @description + * Returns the current 64-bit mask that controls which DC instances will + * have the configured coalescing timer applied. + * + *****************************************************************************/ +Cpa64U getDcInstanceCoalescingTimerMask(void); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * configureDcInstanceCoalescingTimerForAll + * + * @description + * Convenience function that configures the specified coalescing timer + * for all available DC instances (up to 64). + * + * @param[in] coalescingTimerInNs Coalescing timer value in nanoseconds + * + *****************************************************************************/ +CpaStatus configureDcInstanceCoalescingTimerForAll(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * configureDcInstanceCoalescingTimerForHalf + * + * @description + * Convenience function that configures the specified coalescing timer + * for half of the available DC instances. + * + * @param[in] coalescingTimerInNs Coalescing timer value in nanoseconds + * + *****************************************************************************/ +CpaStatus configureDcInstanceCoalescingTimerForHalf(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * getDcInstanceRxInterruptMetaData + * + * @description + * Wrapper around cpaInstanceGetRxInterruptMetaData() for DC instances. + * Returns the currently-configured coalescing timer along with the + * maximum supported value and granularity. + * + * @param[in] instanceHandle DC instance handle + * @param[out] pInterruptData Pointer to a CpaRxInterruptMetaData structure + * that will receive the values + * + *****************************************************************************/ +CpaStatus getDcInstanceRxInterruptMetaData( + CpaInstanceHandle instanceHandle, + CpaRxInterruptMetaData *pInterruptData); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * applyDcInstanceCoalescingTimerConfiguration + * + * @description + * Applies the configured coalescing timer value to the actual DC + * instances based on the current mask and configuration. After setting + * the timer on each masked instance the value is read back via + * cpaInstanceGetRxInterruptMetaData() and verified (taking the + * hardware-reported granularity into account). This should be called + * after DC services are started but before polling threads are created. + * + *****************************************************************************/ +CpaStatus applyDcInstanceCoalescingTimerConfiguration(void); +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ + +/* Instance selection functions - supports up to 64 instances */ +/** + ***************************************************************************** + * @ingroup compressionThreads + * Set the response mode mask for DC instances + * + * @description + * This function sets a 64-bit mask to control which DC instances should + * use the configured response mode. Each bit in the mask corresponds to + * an instance index (supports up to 64 instances). + * + * @param[in] mask 64-bit bitmask indicating which instances to apply + * response mode + * + *****************************************************************************/ +void setDcInstanceResponseModeMask(Cpa64U mask); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Get the current response mode mask for DC instances + * + * @description + * This function returns the current 64-bit bitmask that controls which + * DC instances will use the configured response mode. + * + * @retval Cpa64U Current instance response mode mask + * + *****************************************************************************/ +Cpa64U getDcInstanceResponseModeMask(void); +/** + ***************************************************************************** + * @ingroup compressionThreads + * Configure response mode for all available DC instances + * + * @description + * This is a convenience function that explicitly configures the specified + * response mode for all available DC instances (up to 64), overriding + * the QAT library's default. This should be called at the application + * level before starting performance tests only when you need to override + * the library's default behavior. + * + * @param[in] responseMode The response mode to apply to all instances + * + *****************************************************************************/ +CpaStatus configureDcInstanceResponseModeForAll( + CpaInstanceResponseMode responseMode); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * Configure response mode for all available DC instances + * + * @description + * This is a convenience function that explicitly configures the specified + * response mode for half of the available DC instances (up to 64), + * overriding the QAT library's default. This should be called at the + * application level before starting performance tests only when you need to + * override the library's default behavior. + * + * @param[in] responseMode The response mode to apply to all instances + * + *****************************************************************************/ +CpaStatus configureDcInstanceResponseModeForHalf( + CpaInstanceResponseMode responseMode); + +/* Response mode iteration functions for data path testing */ +/** + ***************************************************************************** + * @ingroup compressionThreads + * Set the iteration count for response mode alternation + * + * @description + * This function sets the number of iterations for response mode + * alternation in the data path. Used for testing response mode switching + * behavior. Default is 1 (no iteration). + * + * @param[in] count Number of iterations to perform + * + * @retval CPA_STATUS_SUCCESS Successfully set iteration count + * @retval CPA_STATUS_FAIL Failed to set iteration count + * + *****************************************************************************/ +CpaStatus setDcResponseModeIterationCount(Cpa32U count); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * Get the current iteration count for response mode alternation + * + * @description + * This function returns the current number of iterations configured + * for response mode alternation. + * + * @param[out] count Pointer to store the current iteration count + * + * @retval CPA_STATUS_SUCCESS Successfully retrieved iteration count + * @retval CPA_STATUS_FAIL Invalid parameter (NULL pointer) + * + *****************************************************************************/ +CpaStatus getDcResponseModeIterationCount(Cpa32U *count); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * Get response mode with iteration for data path + * + * @description + * This function returns the response mode after performing n iterations + * starting from the currentResponseMode in the test parameters. Each + * iteration alternates between the initial mode (from test params) and + * its opposite. If iteration count is 1 (default), returns the current + * response mode unchanged. + * + * @param[in] testParams Test parameters containing currentResponseMode + * + * @retval CpaInstanceResponseMode Response mode after iteration + * + *****************************************************************************/ +CpaInstanceResponseMode getDcResponseModeWithIteration( + compression_test_params_t *testParams); + +/** + ***************************************************************************** + * @ingroup compressionThreads + * Enable or disable response mode iteration + * + * @description + * Convenience function to enable response mode iteration in the data path. + * Set count > 1 to enable iteration, or count = 1 to disable (default). + * + * @param[in] count Number of iterations (1 = disabled, >1 = enabled) + * + * @retval CPA_STATUS_SUCCESS Successfully configured iteration count + * @retval CPA_STATUS_FAIL Failed to configure iteration count + * + *****************************************************************************/ +CpaStatus enableDcResponseModeIteration(Cpa32U count); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + /** * ***************************************************************************** * @ingroup compressionThreads @@ -609,4 +1077,9 @@ void setDcPollingThreadsInterval(long interval); CpaStatus sampleRemoveDcDpSession(CpaInstanceHandle dcInstance, CpaDcSessionHandle pSessionHandle); +CpaStatus getDcCapabilityStatusForAlg(CpaInstanceHandle dcInstance, + Cpa32U capId, + CpaDcCompType algorithm, + CpaDcSessionDir direction, + CpaBoolean *pCapStatus); #endif /* CPA_SAMPLE_CODE_DC_UTILS_H_ */ diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_zlib.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_zlib.c index 10e95541..5099d735 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_zlib.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/cpa_sample_code_zlib.c @@ -24,6 +24,9 @@ #include "cpa_sample_code_dc_utils.h" #ifdef USER_SPACE #include "zlib.h" +#if !defined(USE_ZLIB) +#define USE_ZLIB +#endif // USE_ZLIB #else #include #include diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_chaining_main.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_chaining_main.c index b1d5378d..2cbdffbf 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_chaining_main.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_chaining_main.c @@ -556,6 +556,64 @@ void dcChainOpDataMemFree(CpaDcChainOpData *pOpdata, } } +void dcExtChainOpDataMemFree(CpaDcChainSubOpData2 *pOpdata, + Cpa32U numLists, + Cpa32U numSessions) +{ + Cpa32U k = 0; + Cpa32U j = numSessions; + CpaDcOpData2 *pDcOp = NULL; + CpaCySymOpData2 *pCySymOp = NULL; + + for (k = 0; k < numLists; k++) + { + if (NULL != pOpdata) + { + if (pOpdata[k * j].opType == CPA_DC_CHAIN_SYMMETRIC_CRYPTO) + { + pCySymOp = pOpdata[k * j].pCySymOp2; + pDcOp = pOpdata[k * j + 1].pDcOp2; + } + else + { + pCySymOp = pOpdata[k * j + 1].pCySymOp2; + pDcOp = pOpdata[k * j].pDcOp2; + } + if (NULL != pCySymOp) + { + if (NULL != pCySymOp->symOpData.pDigestResult) + { + qaeMemFreeNUMA( + (void **)&(pCySymOp->symOpData.pDigestResult)); + } + if (NULL != pCySymOp->symOpData.pIv) + { + qaeMemFreeNUMA((void **)&(pCySymOp->symOpData.pIv)); + } + if (NULL != pCySymOp->symOpData.pAdditionalAuthData) + { + qaeMemFreeNUMA( + (void **)&(pCySymOp->symOpData.pAdditionalAuthData)); + } + if (NULL != pCySymOp->deriveCtxData.pContext) + { + qaeMemFreeNUMA( + (void **)&(pCySymOp->deriveCtxData.pContext)); + } + qaeMemFree((void **)&pCySymOp); + } + if (NULL != pDcOp) + { + if (NULL != pDcOp->dcOpData.pCrcData) + { + qaeMemFreeNUMA((void **)&(pDcOp->dcOpData.pCrcData)); + } + qaeMemFree((void **)&pDcOp); + } + } + } +} + CpaStatus dcChainPerformOpDataSetup(compression_test_params_t *setup, CpaBufferList *srcBufferListArray, CpaDcChainOpData *chainOpDataArray) @@ -1143,6 +1201,7 @@ void dcChainPerformance(single_thread_test_data_t *testSetup) Cpa32U node = 0; CpaDcInstanceCapabilities capabilities = {0}; CpaDcStats dcStats = {0}; + CpaBoolean capabilityStatus = CPA_FALSE; /* Get the setup pointer */ tmpSetup = (compression_test_params_t *)(testSetup->setupPtr); @@ -1216,40 +1275,14 @@ void dcChainPerformance(single_thread_test_data_t *testSetup) /*Initialize the statsPrintFunc to dcChainPrintStats */ testSetup->statsPrintFunc = (stats_print_func_t)dcChainPrintStats; - /* Get the number of instances */ - status = cpaDcGetNumInstances(&numInstances); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR(" Unable to get number of DC instances\n"); - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); - } - } - if (CPA_STATUS_SUCCESS == status) - { - if (0 == numInstances) - { - PRINT_ERR(" DC Instances are not present\n"); - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); - } - } - if (CPA_STATUS_SUCCESS == status) - { - instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); - if (NULL == instances) - { - PRINT_ERR("Unable to allocate Memory for Instances\n"); - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); - } - } - if (CPA_STATUS_SUCCESS == status) - { /* Get the instance handles so that we can start * our thread on the selected instance */ - status = cpaDcGetInstances(numInstances, instances); + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &instances, &numInstances); if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR("Unable to get DC instances\n"); + PRINT_ERR(" dcGetInstances failed\n"); QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); } } @@ -1265,6 +1298,66 @@ void dcChainPerformance(single_thread_test_data_t *testSetup) dcSetup.dcChainReadInsHandle = instances[(testSetup->logicalQaReadInstance) % numInstances]; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + { + Cpa16U instanceIndex = + (testSetup->logicalQaInstance) % numInstances; + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(dcSetup.dcInstanceHandle, + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, + &dcSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + dcSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + PRINT("Failed to query instance response mode, using fallback: " + "%d\n", + responseStatus); + } + + /* Check if this instance has been explicitly configured with + * override */ + if (isDcInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getDcInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + dcSetup.currentResponseMode = getDcInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + dcSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT("Using library default response mode %d for instance " + "%d\n", + dcSetup.currentResponseMode, + instanceIndex); + } + } + + /* Print the final response mode for this thread */ + PRINT( + "Thread %u using DC instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + dcSetup.currentResponseMode, + (dcSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (dcSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ /* Find node that thread is running on */ status = sampleCodeDcGetNode(dcSetup.dcInstanceHandle, &node); if (CPA_STATUS_SUCCESS != status) @@ -1367,6 +1460,32 @@ void dcChainPerformance(single_thread_test_data_t *testSetup) dcSetup.induceOverflow = CPA_FALSE; + if (CPA_STATUS_SUCCESS == status) + { + if (CPA_DC_ASB_DISABLED == dcSetup.setupData.autoSelectBestHuffmanTree) + { + status = getDcCapabilityStatusForAlg( + dcSetup.dcInstanceHandle, + CPA_DC_CAP_BOOL_ASB_ENABLE_PREFERRED, + dcSetup.setupData.compType, + CPA_DC_DIR_COMPRESS, + &capabilityStatus); + + if (CPA_STATUS_SUCCESS != status) + { + QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); + } + + if (CPA_TRUE == capabilityStatus) + { + /* Enable ASB if ASB preferred capability is set for the + * algorithm */ + dcSetup.setupData.autoSelectBestHuffmanTree = + CPA_DC_ASB_ENABLED; + } + } + } + if (CPA_STATUS_SUCCESS == status) { /* Launch function that does all the work */ @@ -1498,6 +1617,16 @@ CpaStatus setupDcChainTest(CpaDcChainOperations chainOperation, PRINT_ERR("Error in Starting Dc Services\n"); return CPA_STATUS_FAIL; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyDcInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying DC instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (!poll_inline_g) { /* start polling threads if polling is enabled in the configuration @@ -1586,6 +1715,12 @@ CpaStatus setupDcChainTest(CpaDcChainOperations chainOperation, authKeyLengthInBytes; dcSetup->symSetupData.digestIsAppended = CPA_FALSE; dcSetup->symSetupData.verifyDigest = CPA_FALSE; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Initialize response mode to library default (will be queried per-thread) + */ + dcSetup->currentResponseMode = CPA_INST_RX_NOTIFY_NONE; /* Fallback value */ +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ return status; } diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_cnv_utils.h b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_cnv_utils.h index 424ea02f..cdaf480c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_cnv_utils.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_cnv_utils.h @@ -302,14 +302,15 @@ static CpaStatus getDcCapabilities(CpaDcInstanceCapabilities *capabilities) Cpa16U numInstances = 0; /* Get the number of instances */ - status = cpaDcGetNumInstances(&numInstances); + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &numInstances); if (CPA_STATUS_SUCCESS != status) return CPA_STATUS_FAIL; if (numInstances == 0) return CPA_STATUS_FAIL; - status = cpaDcGetInstances(1, &instHandle); + status = cpaGetInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, 1, &instHandle); if (status != CPA_STATUS_SUCCESS) return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.c index e19975e0..06f97c1f 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.c @@ -26,6 +26,13 @@ extern CpaStatus createStartandWaitForCompletion(Cpa32U instType); #define COUNT_RESPONSES dcPerformCallback(setup, status) +/* Resolve to the per-thread dictionary buffer list array when the test + * was configured for dictionary-based (de)compression, NULL otherwise. + * The useDictionary field of compression_test_params_t only exists in + * STV_TEST_CODE builds, so on stripped builds this collapses to NULL + * unconditionally. */ +#define QAT_DC_DICT_LIST(setup, arr) (NULL) + #define RESET_PERF_STATS(perfStats, numLists, numLoops) \ do \ { \ @@ -64,6 +71,7 @@ CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, CpaBufferList *arrayOfSrcBufferLists, CpaBufferList *arrayOfDestBufferLists, CpaBufferList *arrayOfCmpBufferLists, + CpaBufferList *dictionaryBufferListArray, Cpa32U listNum, CpaDcRqResults *arrayOfResults); @@ -226,7 +234,21 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, } /*Start DC Services */ - status = startDcServices(testBufferSize, TEMP_NUM_BUFFS); + getDecompNumInstances(); + dcSetup->useDecompService = + (direction == CPA_DC_DIR_DECOMPRESS && numDecompInstances_g > 0) + ? CPA_TRUE + : CPA_FALSE; + if (dcSetup->useDecompService) + { + status = startServices(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + testBufferSize, + TEMP_NUM_BUFFS); + } + else + { + status = startDcServices(testBufferSize, TEMP_NUM_BUFFS); + } if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("Error in Starting Dc Services\n"); @@ -239,6 +261,17 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, #endif } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyDcInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying DC instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + if (!poll_inline_g) { /* start polling threads if polling is enabled in the configuration @@ -248,6 +281,14 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, PRINT_ERR("Error creating polling threads\n"); return CPA_STATUS_FAIL; } + if (dcSetup->useDecompService) + { + if (CPA_STATUS_SUCCESS != dcCreateDecompPollingThreads()) + { + PRINT_ERR("Error creating DECOMP polling threads\n"); + return CPA_STATUS_FAIL; + } + } } INIT_OPDATA_DEFAULT(&dcSetup->requestOps); @@ -294,6 +335,9 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, dcSetup->corpusFileIndex = corpusFileIndex; dcSetup->bufferSize = testBufferSize; dcSetup->dcSessDir = direction; + /* Disable reliability checks for decompression-only runs. The framework + * still SW-compresses. + */ dcSetup->syncFlag = syncFlag; dcSetup->numLoops = numLoops; dcSetup->isDpApi = CPA_FALSE; @@ -302,6 +346,13 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, dcSetup->setupData.checksum = gChecksum; dcSetup->passCriteria = getPassCriteria(); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Initialize response mode to library default (will be queried per-thread) + */ + dcSetup->currentResponseMode = CPA_INST_RX_NOTIFY_NONE; /* Fallback value */ +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + return status; } @@ -317,6 +368,7 @@ void dcPerformance(single_thread_test_data_t *testSetup) CpaInstanceHandle *instances = NULL; CpaStatus status = CPA_STATUS_FAIL; CpaDcInstanceCapabilities capabilities = {0}; + CpaBoolean bCapabilityStatus = CPA_FALSE; /* Get the setup pointer */ tmpSetup = (compression_test_params_t *)(testSetup->setupPtr); @@ -338,6 +390,7 @@ void dcPerformance(single_thread_test_data_t *testSetup) dcSetup.syncFlag = tmpSetup->syncFlag; dcSetup.numLoops = tmpSetup->numLoops; dcSetup.setupData.checksum = tmpSetup->setupData.checksum; + dcSetup.useDecompService = tmpSetup->useDecompService; dcSetup.setNsRequest = tmpSetup->setNsRequest; dcSetup.useE2E = tmpSetup->useE2E; dcSetup.useE2EVerify = tmpSetup->useE2EVerify; @@ -374,39 +427,19 @@ void dcPerformance(single_thread_test_data_t *testSetup) */ testSetup->statsPrintFunc = NULL; - /* Get the number of instances */ - status = cpaDcGetNumInstances(&numInstances); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR(" Unable to get number of DC instances\n"); - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); - } - } - if (CPA_STATUS_SUCCESS == status) - { - if (0 == numInstances) + /*get the instance handles so that we can start + * our thread on the selected instance + */ + if (dcSetup.useDecompService) { - PRINT_ERR(" DC Instances are not present\n"); - status = CPA_STATUS_FAIL; - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &instances, &numInstances); } - } - if (CPA_STATUS_SUCCESS == status) - { - instances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); - if (NULL == instances) + else { - PRINT_ERR("Unable to allocate Memory for Instances\n"); - status = CPA_STATUS_FAIL; - QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); + status = dcGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &instances, &numInstances); } - } - if (CPA_STATUS_SUCCESS == status) - { - /*get the instance handles so that we can start - * our thread on the selected instance - */ - status = cpaDcGetInstances(numInstances, instances); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR(" Unable to get DC instances\n"); @@ -420,6 +453,65 @@ void dcPerformance(single_thread_test_data_t *testSetup) dcSetup.dcInstanceHandle = instances[(testSetup->logicalQaInstance) % numInstances]; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(dcSetup.dcInstanceHandle, + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, + &dcSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + dcSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + PRINT("Failed to query instance response mode, using fallback: " + "%d\n", + responseStatus); + } + + /* Check if this instance has been explicitly configured with + * override */ + if (isDcInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getDcInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + dcSetup.currentResponseMode = getDcInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + dcSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT("Using library default response mode %d for instance " + "%d\n", + dcSetup.currentResponseMode, + instanceIndex); + } + } + } + + /* Print the final response mode for this thread */ + PRINT("Thread %u using DC instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + dcSetup.currentResponseMode, + (dcSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (dcSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + // find node that thread is running on status = sampleCodeDcGetNode(dcSetup.dcInstanceHandle, &dcSetup.node); if (CPA_STATUS_SUCCESS != status) @@ -460,7 +552,7 @@ void dcPerformance(single_thread_test_data_t *testSetup) #if DC_API_VERSION_AT_LEAST(3, 1) if ((CPA_DC_STATELESS == tmpSetup->setupData.sessState) && (CPA_DC_LZ4 == tmpSetup->setupData.compType) && - ((CPA_FALSE == capabilities.statelessLZ4Compression) || + ((CPA_FALSE == capabilities.statelessLZ4Compression) && (CPA_FALSE == capabilities.statelessLZ4Decompression))) { PRINT("LZ4 is not supported on logical instance %d\n", @@ -471,7 +563,7 @@ void dcPerformance(single_thread_test_data_t *testSetup) } if ((CPA_DC_STATELESS == tmpSetup->setupData.sessState) && (CPA_DC_LZ4S == tmpSetup->setupData.compType) && - ((CPA_FALSE == capabilities.statelessLZ4Compression) || + ((CPA_FALSE == capabilities.statelessLZ4Compression) && (CPA_FALSE == capabilities.statelessLZ4Decompression))) { PRINT("LZ4s is not supported on logical instance %d\n", @@ -504,10 +596,6 @@ void dcPerformance(single_thread_test_data_t *testSetup) CPA_STATUS_UNSUPPORTED; status = CPA_STATUS_UNSUPPORTED; QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); - qaeMemFree((void **)&instances); - qaeMemFree((void **)&dcSetup.numberOfBuffers); - qaeMemFree((void **)&dcSetup.packetSizeInBytesArray); - sampleCodeThreadExit(); } } } @@ -524,6 +612,28 @@ void dcPerformance(single_thread_test_data_t *testSetup) dcSetup.induceOverflow = CPA_FALSE; dcSetup.threadID = testSetup->threadID; + if (CPA_DC_ASB_DISABLED == dcSetup.setupData.autoSelectBestHuffmanTree) + { + status = + getDcCapabilityStatusForAlg(dcSetup.dcInstanceHandle, + CPA_DC_CAP_BOOL_ASB_ENABLE_PREFERRED, + dcSetup.setupData.compType, + CPA_DC_DIR_COMPRESS, + &bCapabilityStatus); + + if (CPA_STATUS_SUCCESS != status) + { + QAT_PERF_FAIL_WAIT_AND_GOTO_LABEL(testSetup, err); + } + + if (CPA_TRUE == bCapabilityStatus) + { + /* Enable ASB if ASB preferred capability is set for the algorithm + */ + dcSetup.setupData.autoSelectBestHuffmanTree = CPA_DC_ASB_ENABLED; + } + } + if (CPA_STATUS_SUCCESS == status) { /*launch function that does all the work*/ @@ -601,6 +711,7 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) Cpa32U *testBufferSize = setup->packetSizeInBytesArray; Cpa32U numberOfBuffersPerList = dc_bufferCount_g; CpaBufferList *srcBufferListArray = NULL; + CpaBufferList *dictionaryBufferListArray = NULL; CpaBufferList *destBufferListArray = NULL; CpaBufferList *cmpBufferListArray = NULL; CpaDcRqResults *resultArray = NULL; @@ -618,28 +729,29 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) (Cpa64U)setup->numLists * (Cpa64U)setup->numLoops); // allocate memory for source & destination bufferLists and results - status = qatAllocateCompressionLists(setup, - &srcBufferListArray, - &destBufferListArray, - &cmpBufferListArray, - &resultArray); - - // Allocate the CpaFlatBuffers in each list - if (CPA_STATUS_SUCCESS == status) { - status = qatAllocateCompressionFlatBuffers(setup, - srcBufferListArray, - numberOfBuffersPerList, - testBufferSize, - destBufferListArray, - numberOfBuffersPerList, - testBufferSize, - cmpBufferListArray, - numberOfBuffersPerList, - testBufferSize); - if (CPA_STATUS_SUCCESS != status) + status = qatAllocateCompressionLists(setup, + &srcBufferListArray, + &destBufferListArray, + &cmpBufferListArray, + &resultArray); + if (CPA_STATUS_SUCCESS == status) { - PRINT_ERR("could not allocate all flat buffers for compression\n"); + status = qatAllocateCompressionFlatBuffers(setup, + srcBufferListArray, + numberOfBuffersPerList, + testBufferSize, + destBufferListArray, + numberOfBuffersPerList, + testBufferSize, + cmpBufferListArray, + numberOfBuffersPerList, + testBufferSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "could not allocate all flat buffers for compression\n"); + } } } @@ -653,6 +765,10 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) fileArray[setup->corpusFileIndex].corpusBinaryDataLen, testBufferSize); } + + // copy corpus data into allocated buffers (dictionary buffers populated + // above) + if (CPA_FALSE == setup->setNsRequest) { // Initialize the compression session to use @@ -687,14 +803,58 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) reliability_g == CPA_FALSE) { - /* When STV_TEST_CODE with USER_SPACE and SUPPORTED_FEAT_EPOLL is not defined, always use default behavior */ - status = qatCompressData(setup, - pSessionHandle, - CPA_DC_DIR_COMPRESS, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray, - resultArray); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Check if response mode iteration is enabled */ + { + Cpa32U iterCount = 0; + status = getDcResponseModeIterationCount(&iterCount); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get DC response mode iteration count " + "in qatDcPerform\n"); + return status; + } + + if (iterCount > 1) + { + status = qatCompressDataWithIteration( + setup, + pSessionHandle, + CPA_DC_DIR_COMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); + } + else + { + /* Default behavior - single execution */ + status = qatCompressData( + setup, + pSessionHandle, + CPA_DC_DIR_COMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); + } + } +#else + /* When STV_TEST_CODE with USER_SPACE and SUPPORTED_FEAT_EPOLL is + * not defined, always use default behavior */ + status = qatCompressData( + setup, + pSessionHandle, + CPA_DC_DIR_COMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ qatDcUpdateProducedBufferLength( setup, destBufferListArray, resultArray); @@ -717,14 +877,28 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) */ latency_enable = 0; coo_deinit(setup->performanceStats); - - status = qatCompressData(setup, - pSessionHandle, - CPA_DC_DIR_COMPRESS, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray, - resultArray); + if (pSessionHandle == NULL && setup->useDecompService) + { + /* Generate the compressed test data + * via the SW (zlib / lz4 / zstd) helper instead. */ + PRINT("Decomp-only instance: pre-compressing corpus in SW\n"); + status = qatSwCompress(setup, + srcBufferListArray, + destBufferListArray, + resultArray); + } + else + { + status = qatCompressData( + setup, + pSessionHandle, + CPA_DC_DIR_COMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); + } /* Restore latency and COO measurement */ latency_enable = latency_enable_flag; @@ -744,13 +918,15 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) } RESET_PERF_STATS( setup->performanceStats, setup->numLists, setup->numLoops); - status = qatCompressData(setup, - pDecompressSessionHandle, - CPA_DC_DIR_DECOMPRESS, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray, - resultArray); + status = qatCompressData( + setup, + pDecompressSessionHandle, + CPA_DC_DIR_DECOMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); dcScSetBytesProducedAndConsumed(resultArray, setup->performanceStats, setup, @@ -768,13 +944,15 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) setup->numLoops = 1; for (i = 0; i < numLoops; i++) { - status = qatCompressData(setup, - pSessionHandle, - CPA_DC_DIR_COMPRESS, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray, - resultArray); + status = qatCompressData( + setup, + pSessionHandle, + CPA_DC_DIR_COMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + resultArray); qatDcUpdateProducedBufferLength( setup, destBufferListArray, resultArray); dcScSetBytesProducedAndConsumed(resultArray, @@ -838,67 +1016,58 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) else if (setup->dcSessDir == CPA_DC_DIR_DECOMPRESS && reliability_g == CPA_TRUE) { - /*copy numLoops, set setup->numLoops to 1 to do repeated - * swcompress-decompress for numLoops times*/ - numLoops = setup->numLoops; - setup->numLoops = 1; - for (i = 0; i < numLoops; i++) + /* Generate the compressed payload once via SW compress, then + * let qatCompressData() iterate the HW decompress. */ + + /* Disable latency/COO measurement during the one-time SW + * compress used only to produce decompress input data. */ + latency_enable = 0; + coo_deinit(setup->performanceStats); + + status = qatSwCompress( + setup, srcBufferListArray, destBufferListArray, resultArray); + qatDcUpdateProducedBufferLength( + setup, destBufferListArray, resultArray); + + /* Restore latency and COO measurement for the decompress + * performance run. */ + latency_enable = latency_enable_flag; + coo_init(setup->performanceStats, + (Cpa64U)setup->numLists * (Cpa64U)setup->numLoops); + + if (CPA_STATUS_SUCCESS == status) { - status = qatSwCompress(setup, - srcBufferListArray, - destBufferListArray, - resultArray); - qatDcUpdateProducedBufferLength( - setup, destBufferListArray, resultArray); - if (CPA_STATUS_SUCCESS == status) + if (setup->e2e) { - status = qatCompressData(setup, - pDecompressSessionHandle, - CPA_DC_DIR_DECOMPRESS, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray, - resultArray); - qatDcUpdateProducedBufferLength( - setup, cmpBufferListArray, resultArray); - dcScSetBytesProducedAndConsumed(resultArray, - setup->performanceStats, - setup, - setup->dcSessDir); - if (CPA_STATUS_SUCCESS == status) - { - status = qatCmpBuffers( - setup, srcBufferListArray, cmpBufferListArray); - QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( - "qatCmpBuffers", status); - } - if (CPA_STATUS_SUCCESS == status) - { - /*reset destination buffer*/ - status = qatCompressResetBufferList(setup, - destBufferListArray, - testBufferSize, - CPA_FALSE); - QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( - "qatCompressResetBufferList", status); - } + setup->e2e->swInputChecksum = 0x0; + setup->e2e->swOutputChecksum = 0x0; } + RESET_PERF_STATS( + setup->performanceStats, setup->numLists, setup->numLoops); + + status = qatCompressData(setup, + pDecompressSessionHandle, + CPA_DC_DIR_DECOMPRESS, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray, + dictionaryBufferListArray, + resultArray); + qatDcUpdateProducedBufferLength( + setup, cmpBufferListArray, resultArray); + dcScSetBytesProducedAndConsumed(resultArray, + setup->performanceStats, + setup, + setup->dcSessDir); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("qatCompressData returned status %d\n", status); - break; - } - if (CPA_TRUE == stopTestsIsEnabled_g) - { - /* Check if terminated by global flag. - * stop issuing new requests - */ - if (CPA_TRUE == exitLoopFlag_g) - { - break; - } } } + else + { + PRINT_ERR("qatSwCompress returned status %d\n", status); + } } if (CPA_STATUS_SUCCESS != status) { @@ -938,22 +1107,22 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) } } /*free CpaFlatBuffers and privateMetaData in CpaBufferLists*/ - if ((CPA_STATUS_SUCCESS != - qatFreeCompressionFlatBuffers(setup, - srcBufferListArray, - destBufferListArray, - cmpBufferListArray)) && - (CPA_STATUS_SUCCESS != qatFreeFlatBuffersInList(&contextBuffer))) + if ((CPA_STATUS_SUCCESS != + qatFreeCompressionFlatBuffers(setup, + srcBufferListArray, + destBufferListArray, + cmpBufferListArray)) && + (CPA_STATUS_SUCCESS != qatFreeFlatBuffersInList(&contextBuffer))) { PRINT_ERR("freeCompressionFlatBuffers error\n"); status = CPA_STATUS_FAIL; } // free CpaBufferLists - if (CPA_STATUS_SUCCESS != qatFreeCompressionLists(setup, - &srcBufferListArray, - &destBufferListArray, - &cmpBufferListArray, - &resultArray)) + if (CPA_STATUS_SUCCESS != qatFreeCompressionLists(setup, + &srcBufferListArray, + &destBufferListArray, + &cmpBufferListArray, + &resultArray)) { PRINT_ERR("freeCompressionLists error\n"); status = CPA_STATUS_FAIL; @@ -969,12 +1138,14 @@ CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, CpaBufferList *arrayOfSrcBufferLists, CpaBufferList *arrayOfDestBufferLists, CpaBufferList *arrayOfCmpBufferLists, + CpaBufferList *dictionaryBufferListArray, Cpa32U listNum, CpaDcRqResults *arrayOfResults) { CpaStatus status = CPA_STATUS_SUCCESS; static Cpa32U staticAssign = 0; CpaDcCallbackFn dcCbFn = NULL; + (void)dictionaryBufferListArray; if (setup->requestOps.flushFlag != setup->flushFlag) { @@ -1017,14 +1188,16 @@ CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, } else { - status = - cpaDcCompressData2(setup->dcInstanceHandle, - pSessionHandle, - &arrayOfSrcBufferLists[listNum], - &arrayOfDestBufferLists[listNum], - &(setup->requestOps), - &arrayOfResults[listNum], - (void *)setup); + { + status = + cpaDcCompressData2(setup->dcInstanceHandle, + pSessionHandle, + &arrayOfSrcBufferLists[listNum], + &arrayOfDestBufferLists[listNum], + &(setup->requestOps), + &arrayOfResults[listNum], + (void *)setup); + } } coo_req_stop(setup->performanceStats, status); } @@ -1039,7 +1212,15 @@ CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, if (CPA_TRUE == setup->setNsRequest) { setup->setupData.sessDirection = CPA_DC_DIR_DECOMPRESS; - + CpaDcCompLZ4BlockMaxSize savedBlockMaxSize = + setup->setupData.lz4BlockMaxSize; + if (CPA_DC_LZ4 == setup->setupData.compType && + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K == + setup->setupData.lz4BlockMaxSize) + { + setup->setupData.lz4BlockMaxSize = + CPA_DC_LZ4_MAX_BLOCK_SIZE_256K; + } if (ASYNC == setup->syncFlag) { dcCbFn = dcPerformCallback; @@ -1053,16 +1234,20 @@ CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, &arrayOfResults[listNum], dcCbFn, (void *)setup); + setup->setupData.lz4BlockMaxSize = savedBlockMaxSize; } else { - status = cpaDcDecompressData2(setup->dcInstanceHandle, - pSessionHandle, - &arrayOfDestBufferLists[listNum], - &arrayOfCmpBufferLists[listNum], - &(setup->requestOps), - &arrayOfResults[listNum], - (void *)setup); + { + status = + cpaDcDecompressData2(setup->dcInstanceHandle, + pSessionHandle, + &arrayOfDestBufferLists[listNum], + &arrayOfCmpBufferLists[listNum], + &(setup->requestOps), + &arrayOfResults[listNum], + (void *)setup); + } } coo_req_stop(setup->performanceStats, status); } @@ -1090,12 +1275,14 @@ EXPORT_SYMBOL(qatDcSubmitRequest); /*performance measurement function to compress a file for 'n' number of loops * */ +// Remove default argument, use plain pointer for C compatibility CpaStatus qatCompressData(compression_test_params_t *setup, CpaDcSessionHandle pSessionHandle, CpaDcSessionDir compressDirection, CpaBufferList *arrayOfSrcBufferLists, CpaBufferList *arrayOfDestBufferLists, CpaBufferList *arrayOfCmpBufferLists, + CpaBufferList *dictionaryBufferListArray, CpaDcRqResults *arrayOfResults) { CpaStatus status = CPA_STATUS_SUCCESS; @@ -1134,6 +1321,7 @@ CpaStatus qatCompressData(compression_test_params_t *setup, QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(arrayOfCmpBufferLists, status); QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(arrayOfResults, status); + (void)dictionaryBufferListArray; if (CPA_STATUS_SUCCESS == status) { status = qatCompressionE2EInit(setup); @@ -1201,15 +1389,17 @@ CpaStatus qatCompressData(compression_test_params_t *setup, */ arrayOfResults[listNum].checksum = previousChecksum; /*submit request*/ - status = qatDcSubmitRequest(setup, - instanceInfo2, - compressDirection, - pSessionHandle, - arrayOfSrcBufferLists, - arrayOfDestBufferLists, - arrayOfCmpBufferLists, - listNum, - arrayOfResults); + status = qatDcSubmitRequest( + setup, + instanceInfo2, + compressDirection, + pSessionHandle, + arrayOfSrcBufferLists, + arrayOfDestBufferLists, + arrayOfCmpBufferLists, + QAT_DC_DICT_LIST(setup, dictionaryBufferListArray), + listNum, + arrayOfResults); /* Check submit status and update thread status*/ if (CPA_STATUS_SUCCESS != status) { @@ -1537,6 +1727,7 @@ static CpaStatus qatInduceOverflow(compression_test_params_t *setup, srcBufferListArray, destBufferListArray, cmpBufferListArray, + NULL, resultArray); if (status != CPA_STATUS_SUCCESS) { @@ -1560,20 +1751,35 @@ static CpaStatus qatInduceOverflow(compression_test_params_t *setup, goto err; } numListOverflowed++; - - /* Find the amount of data unconsumed */ - srcBufferListArray[i].pBuffers[0].dataLenInBytes -= - resultArray[i].consumed; - srcBufferListArray[i].pBuffers[0].pData += - resultArray[i].consumed; - /* Update Output buffers for the amount of bytes produced. - * From the amount of memory actually allocated for the buffer, - * reduced the amount taken up by produced data. - */ - destBufferListArray[i].pBuffers[0].dataLenInBytes = - destBufferMemSize[i] - resultArray[i].produced; - destBufferListArray[i].pBuffers[0].pData += - resultArray[i].produced; + if (resultArray[i].consumed < + srcBufferListArray[i].pBuffers[0].dataLenInBytes) + { + /* Find the amount of data unconsumed */ + srcBufferListArray[i].pBuffers[0].dataLenInBytes -= + resultArray[i].consumed; + srcBufferListArray[i].pBuffers[0].pData += + resultArray[i].consumed; + /* Update Output buffers for the amount of bytes produced. + * From the amount of memory actually allocated for the + * buffer, reduced the amount taken up by produced data. + */ + destBufferListArray[i].pBuffers[0].dataLenInBytes = + destBufferMemSize[i] - resultArray[i].produced; + destBufferListArray[i].pBuffers[0].pData += + resultArray[i].produced; + } + else + { + /* All source data was consumed but overflow still + * reported (dynamic Huffman translator overflow). + * Re-compress the entire source with full dest buffer + * on the second pass. + */ + destBufferListArray[i].pBuffers[0].dataLenInBytes = + destBufferMemSize[i]; + resultArray[i].produced = 0; + resultArray[i].consumed = 0; + } } else { @@ -1601,6 +1807,7 @@ static CpaStatus qatInduceOverflow(compression_test_params_t *setup, srcBufferListArray, destBufferListArray, cmpBufferListArray, + NULL, overflowResArray); if (status != CPA_STATUS_SUCCESS) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.h b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.h index 60ee430b..aed5c5bc 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_main.h @@ -138,7 +138,6 @@ CpaStatus qatCompressionVerifyOverflow(compression_test_params_t *setup, CpaDcRqResults *arrayOfResults, CpaBufferList *arrayOfSrcBufferLists, Cpa32U listNum); -#ifdef SC_CHAINING_ENABLED /** ***************************************************************************** * @file qat_compression_main.h @@ -162,7 +161,6 @@ CpaStatus qatCompressionVerifyOverflow(compression_test_params_t *setup, ****************************************************************************/ CpaStatus qatFreeDcChainLists(void **chainResultArray, void **chainOpDataArray); -#endif /** ***************************************************************************** * @file qat_compression_main.h @@ -192,7 +190,33 @@ CpaStatus qatAllocateCompressionLists(compression_test_params_t *setup, CpaBufferList **cpmBufferListArray, CpaDcRqResults **resultArray); -#ifdef SC_CHAINING_ENABLED +/** + *************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sampleCode + * + * @description + * allocate the memory used to store a list of CpaBufferLists + * + * @param[in] setup pointer to the compression setup structure + * @param[in] srcBufferListArray array of CpaBufferLists to be allocated + * @param[in] destBufferListArray array of CpaBufferLists to be allocated + * @param[in] dictionaryBufferListArray array of CpaBufferLists to be + * allocated + * @param[in] cpmBufferListArray array of CpaBufferLists to be allocated + * @param[in] resultArray array of cpaDcResults to be allocated + * + * @pre none + * + * @post all memory is allocated + * + * @retval CPA_STATUS_SUCCESS Function executed successfully + * + * @retval CPA_STATUS_FAIL some of the memory could not be + * allocated + ***************************************************************************/ + /** ***************************************************************************** * @file qat_compression_main.h @@ -219,7 +243,6 @@ CpaStatus qatAllocateCompressionLists(compression_test_params_t *setup, CpaStatus qatAllocateDcChainLists(compression_test_params_t *setup, void **chainResultArray, void **chainOpDataArray); -#endif /** ***************************************************************************** @@ -262,6 +285,49 @@ CpaStatus qatAllocateCompressionFlatBuffers(compression_test_params_t *setup, CpaBufferList *cpmBufferListArray, Cpa32U numberBuffersInCpmList, Cpa32U *sizeOfBuffersInCpmList); +/** + *************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sampleCode + * + * @description + * allocate the CpaFlatBuffers and members of the CpaBufferLists + * + * @param[in] setup pointer to the compression setup + * structure + * @param[in] srcBufferListArray array of CpaBufferLists to be allocated + * @param[in] numBuffersInSrcList number of CpaFlatBuffers to be allocated + * in srcBufferListArray + * @param[in] sizeOfBuffersInSrcList size of CpaBufferLists to be allocated + * in srcBufferLists + * @param[in] destBufferListArray array of CpaBufferLists to be allocated + * @param[in] numBuffersInDstList number of CpaFlatBuffers to be allocated + * in dstBufferListArray + * @param[in] sizeOfBuffersInDestList size of CpaBufferLists to be allocated + * in destBufferLists + * @param[in] cpmBufferListArray array of CpaBufferLists to be allocated + * @param[in] numBuffersInCpmList number of CpaFlatBuffers to be allocated + * in cpmBufferListArray + * @param[in] sizeOfBuffersInCpmList size of CpaBufferLists to be allocated + * in cpmBufferListArray + * @param[in] dictionaryBufferListArray array of CpaBufferLists to be + * allocated + * @param[in] numBuffersInDictList number of CpaFlatBuffers to be + * allocated in dictionaryBufferListArray + * @param[in] sizeOfBuffersInDictList size of CpaBufferLists to be allocated + * in dictionaryBufferListArray + * + * + * @pre none + * + * @post all memory is allocated + * + * @retval CPA_STATUS_SUCCESS Function executed successfully + * + * @retval CPA_STATUS_FAIL some of the memory could not be + * allocated + ***************************************************************************/ /** ***************************************************************************** @@ -292,6 +358,66 @@ CpaStatus qatFreeCompressionFlatBuffers(compression_test_params_t *setup, CpaBufferList *destBufferListArray, CpaBufferList *cpmBufferListArray); +/** + ***************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sample_code + * + * @description + * Free the CpaFlatBuffers and members of the CpaBufferLists used by + * the dictionary-aware allocator. Frees src/dest/cmp buffer-list + * contents (via qatFreeCompressionFlatBuffers) plus the per-list + * dictionary buffers. + ****************************************************************************/ + +/** + ***************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sample_code + * + * @description + * Free the array-of-CpaBufferLists allocations done by + * qatAllocateCompressionListsDict() (src, dest, cmp, dictionary and + * results). Each pointer is set to NULL after a successful free. + ****************************************************************************/ + +/** + ***************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sample_code + * + * @description + * Load a dictionary file from disk into a freshly allocated + * heap buffer (qaeMemAlloc). On success the caller owns the + * returned buffer and must free it with qaeMemFree. + * + * @param[in] filePath Absolute path to the dictionary file to load + * @param[in] maxSize Maximum number of bytes to read from the file + * (the buffer allocation is sized to maxSize) + * @param[out] ppData On success, set to the allocated buffer + * @param[out] pActualSize On success, set to the number of bytes + * actually read from the file (may be less + * than maxSize) + * + * @retval CPA_STATUS_SUCCESS Dictionary loaded successfully + * @retval CPA_STATUS_FAIL Allocation or file open/read failed + ****************************************************************************/ + +/** + ***************************************************************************** + * @file qat_compression_main.h + * + * @ingroup sample_code + * + * @description + * Replicate dictionary data into every per-list dictionary buffer in + * dictionaryBufferListArray. Each buffer's dataLenInBytes is set to + * dataLen (or buffer's allocated size, whichever is smaller). + ****************************************************************************/ + /** ***************************************************************************** * @file qat_compression_main.h @@ -361,7 +487,6 @@ CpaStatus qatCompressionSessionTeardown( CpaDcSessionHandle *pDecompressSessionHandle); #ifdef USER_SPACE -#ifdef SC_CHAINING_ENABLED /** ***************************************************************************** * @file qat_compression_main.h @@ -427,7 +552,6 @@ CpaStatus qatDcChainSessionTeardown( CpaDcSessionHandle *pDecompressSessionHandle); #endif -#endif /** ***************************************************************************** @@ -925,9 +1049,9 @@ void qatDcChainResponseStatusCheck(compression_test_params_t *setup, * @retval CPA_STATUS_FAIL the file could not be loaded or the * compression service could not be started ****************************************************************************/ -CpaStatus populateCorpusAndStartDcService(Cpa32U testBufferSize, +CpaStatus populateCorpusAndStartDcService(CpaDcSessionDir direction, + Cpa32U testBufferSize, corpus_type_t corpusType); - /** ***************************************************************************** * @file qat_compression_main.h @@ -1410,6 +1534,7 @@ CpaStatus qatDcPerform(compression_test_params_t *setup); * @param[in] arrayOfSrcBufferLists source data to be compressed * @param[in] arrayOfDestBufferLists pointer to memory to write out results * @param[in] arrayOfCpmBufferLists pointer to memory compare results + * @param[in] dictionaryBufferListArray pointer to memory for dictionary data * @param[in] arrayOfResults structure to store produced and consumed * data * @@ -1423,6 +1548,7 @@ CpaStatus qatCompressData(compression_test_params_t *setup, CpaBufferList *arrayOfSrcBufferLists, CpaBufferList *arrayOfDestBufferLists, CpaBufferList *arrayOfCpmBufferLists, + CpaBufferList *dictionaryBufferListArray, CpaDcRqResults *arrayOfResults); #ifdef SC_CHAINING_ENABLED diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_utils.c index c530e85a..604ae1e6 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_utils.c @@ -78,7 +78,12 @@ static CpaStatus qatDcGetDestBufferAdditionalSize( QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(additionalSize, status); *additionalSize = 0; - + if (setup->setupData.sessDirection == CPA_DC_DIR_DECOMPRESS && + setup->setupData.compType != CPA_DC_LZ4 && setup->useDecompService) + { + setup->dcDestBufferSize = setup->bufferSize; + return CPA_STATUS_SUCCESS; + } status = qatGetCompressBoundDestinationBufferSize( setup, setup->bufferSize, &compDestBufferSize); @@ -138,7 +143,6 @@ CpaStatus qatFreeCompressionLists(compression_test_params_t *setup, return retStatus; } -#ifdef SC_CHAINING_ENABLED /*free the array of chaining source and destination CpaBufferLists * free the array of chaining results*/ CpaStatus qatFreeDcChainLists(void **chainResultArray, void **chainOpDataArray) @@ -164,7 +168,9 @@ CpaStatus qatFreeDcChainLists(void **chainResultArray, void **chainOpDataArray) } return retStatus; } -#endif + +/*allocate the array of source , destination, CpaBufferList and dectionary + * allocate the array of results*/ /*allocate the array of source and destination CpaBufferLists * allocate the array of results*/ @@ -232,7 +238,6 @@ CpaStatus qatAllocateCompressionLists(compression_test_params_t *setup, return status; } -#ifdef SC_CHAINING_ENABLED /*allocate the array of source and destination dc chain Lists * allocate the array of results*/ CpaStatus qatAllocateDcChainLists(compression_test_params_t *setup, @@ -281,7 +286,6 @@ CpaStatus qatAllocateDcChainLists(compression_test_params_t *setup, } return status; } -#endif /*free the CpaFlatBuffers and privateMetaData in the CpaBufferLists array * for both source and destination lists*/ @@ -330,6 +334,56 @@ CpaStatus qatFreeCompressionFlatBuffer(compression_test_params_t *setup, return status; } +/*allocate the CpaFlatBuffers and privateMetaData in the CpaBufferLists array + * for source, destination, compare and dictionary lists. Used by the + * dictionary-based performance test path. + * + * Notes: + * - The src buffer-list meta size is queried with + * cpaDcGetMetaSizeForSrcBuffWithDict() because the src list will be + * submitted along with a dictionary list. + * - The dictionary buffer-list itself uses the standard + * cpaDcBufferListGetMetaSize() and is allocated with + * BYTE_ALIGNMENT_16 since the dictionary buffer addresses must be + * 16-byte aligned (see cpaDcCompressDataWithDict() docs). + * - additionalSize is 0 for the dictionary buffer (no overflow padding). + */ + +static CpaStatus qatAllocateCompressionFlatBuffer( + compression_test_params_t *setup, + CpaBufferList *bufferList, + Cpa32U numBuffersInList, /*affects the metaSize of CpaBufferList*/ + Cpa32U sizeOfBuffersInList) /*size of CpaFlatBuffers to allocate*/ +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U metaSize = 0; + /*shared common buffer allocation with crypto means we need to declare this + but its not used in compression*/ + Cpa32U bufferSize = sizeOfBuffersInList; + if (CPA_STATUS_SUCCESS == status) + { + // getDcMetaSize required for the list + status = cpaDcBufferListGetMetaSize( + setup->dcInstanceHandle, numBuffersInList, &metaSize); + } + + if (CPA_STATUS_SUCCESS == status) + { + status = qatAllocateFlatBuffersInList(bufferList, + setup->node, + metaSize, + numBuffersInList, + bufferSize, + BYTE_ALIGNMENT_64); + } + // not able to allocate all memory, so free any that was allocated + if (CPA_STATUS_SUCCESS != status) + { + // an error has occurred allocating memory so we need to free + qatFreeFlatBuffersInList(bufferList); + } + return status; +} /*allocate the CpaFlatBuffers and privateMetaData in the CpaBufferLists array * for both source and destination lists*/ CpaStatus qatAllocateCompressionFlatBuffers( @@ -434,44 +488,7 @@ CpaStatus qatAllocateCompressionFlatBuffers( return status; } -static CpaStatus qatAllocateCompressionFlatBuffer( - compression_test_params_t *setup, - CpaBufferList *bufferList, - Cpa32U numBuffersInList, /*affects the metaSize of CpaBufferList*/ - Cpa32U sizeOfBuffersInList) /*size of CpaFlatBuffers to allocate*/ -{ - CpaStatus status = CPA_STATUS_SUCCESS; - Cpa32U metaSize = 0; - /*shared common buffer allocation with crypto means we need to declare this - but its not used in compression*/ - Cpa32U bufferSize = sizeOfBuffersInList; - if (CPA_STATUS_SUCCESS == status) - { - // getDcMetaSize required for the list - status = cpaDcBufferListGetMetaSize( - setup->dcInstanceHandle, numBuffersInList, &metaSize); - } - - if (CPA_STATUS_SUCCESS == status) - { - status = qatAllocateFlatBuffersInList(bufferList, - setup->node, - metaSize, - numBuffersInList, - bufferSize, - BYTE_ALIGNMENT_64); - } - // not able to allocate all memory, so free any that was allocated - if (CPA_STATUS_SUCCESS != status) - { - // an error has occurred allocating memory so we need to free - qatFreeFlatBuffersInList(bufferList); - } - return status; -} - #ifdef USER_SPACE -#ifdef SC_CHAINING_ENABLED /*allocate a compression session and initialize it for a Chaining thread*/ CpaStatus qatDcChainSessionInit(compression_test_params_t *setup, CpaDcSessionHandle *pSessionHandle, @@ -589,7 +606,6 @@ CpaStatus qatDcChainSessionTeardown( return retStatus; } #endif -#endif /*allocate a compression session and initialize it for a compression thread*/ CpaStatus qatCompressionSessionInit( @@ -624,7 +640,7 @@ CpaStatus qatCompressionSessionInit( case CPA_DC_DIR_DECOMPRESS: decompressionSessionInitialize = 1; - if (!reliability_g) + if (!reliability_g && numDecompInstances_g == 0) compressionSessionInitialize = 1; break; @@ -686,6 +702,11 @@ CpaStatus qatCompressionSessionInit( if (CPA_STATUS_SUCCESS == status) { tempSetupData.sessDirection = CPA_DC_DIR_DECOMPRESS; + if (CPA_DC_LZ4 == tempSetupData.compType && + setup->bufferSize == BUFFER_SIZE_65536) + { + tempSetupData.lz4BlockMaxSize = CPA_DC_LZ4_MAX_BLOCK_SIZE_256K; + } status = cpaDcInitSession(setup->dcInstanceHandle, *pDecompressSessionHandle, &(tempSetupData), @@ -719,6 +740,7 @@ CpaStatus qatCompressionSessionInit( if (CPA_STATUS_SUCCESS == status) { tempSetupData.sessDirection = CPA_DC_DIR_COMPRESS; + tempSetupData.lz4BlockMaxSize = setup->setupData.lz4BlockMaxSize; status = cpaDcInitSession(setup->dcInstanceHandle, *pSessionHandle, &(tempSetupData), @@ -1070,8 +1092,9 @@ CpaStatus qatCheckAndHandleUnconsumedData(compression_test_params_t *setup, Cpa64S offset = 0; CpaStatus status = CPA_STATUS_FAIL; - remainder = arrayOfDestBufferLists[listNum].pBuffers->dataLenInBytes - - arrayOfResults[listNum].consumed; + remainder = + (Cpa64S)arrayOfDestBufferLists[listNum].pBuffers->dataLenInBytes - + (Cpa64S)arrayOfResults[listNum].consumed; // signed arithmetic offset = arrayOfDestBufferLists[listNum].pBuffers->dataLenInBytes - remainder; @@ -1422,7 +1445,19 @@ static CpaStatus qatSwZlibDecompress(compression_test_params_t *setup, inflate_destroy(&stream); break; } - cmpBuffListArray[j].pBuffers[0].dataLenInBytes = stream.avail_out; + if (stream.avail_out > cmpBuffListArray[j].pBuffers[0].dataLenInBytes) + { + PRINT_ERR("avail_out(%u) > dataLenInBytes(%u) for list %u\n", + stream.avail_out, + cmpBuffListArray[j].pBuffers[0].dataLenInBytes, + j); + qatCompressDumpToFile( + setup, destBuffListArray, "destBuffer", "destBuffSize", 0); + inflate_destroy(&stream); + status = CPA_STATUS_FAIL; + break; + } + cmpBuffListArray[j].pBuffers[0].dataLenInBytes -= stream.avail_out; /*the results passed in contain the uncompressed consumed data * and the compressed produced data, so now we swap them, so that * consumed contains the compressed data consumed by zlib and the @@ -1521,17 +1556,35 @@ CpaStatus qatSwChainDecompress(compression_test_params_t *setup, inflate_destroy(&stream); break; } - cmpBufferListArray[j].pBuffers[0].dataLenInBytes = + if (stream.avail_out > + cmpBufferListArray[j].pBuffers[0].dataLenInBytes) + { + PRINT_ERR( + "avail_out(%u) > dataLenInBytes(%u) for list %u\n", + stream.avail_out, + cmpBufferListArray[j].pBuffers[0].dataLenInBytes, + j); + qatCompressDumpToFile(setup, + destBuffListArray, + "destBuffer", + "destBuffSize", + 0); + inflate_destroy(&stream); + status = CPA_STATUS_FAIL; + break; + } + cmpBufferListArray[j].pBuffers[0].dataLenInBytes -= stream.avail_out; - /*the results passed in contain the uncompressed consumed data - * and the compressed produced data, so now we swap them, so - * that consumed contains the compressed data consumed by zlib - * and the decompressed data produced by zlib*/ + /*the results passed in contain the uncompressed consumed + * data and the compressed produced data, so now we swap + * them, so that consumed contains the compressed data + * consumed by zlib and the decompressed data produced by + * zlib*/ cmpResults[j].consumed = cmpResults[j].produced; cmpResults[j].produced = cmpBufferListArray[j].pBuffers->dataLenInBytes; - /* Destroy the stream every time for stateless but only in the - * end for stateful. + /* Destroy the stream every time for stateless but only in + * the end for stateful. */ if (setup->setupData.sessState != CPA_DC_STATEFUL || j == (setup->numLists - 1)) @@ -1662,10 +1715,12 @@ void qatCompressionResponseStatusCheck(compression_test_params_t *setup, } } -CpaStatus populateCorpusAndStartDcService(Cpa32U testBufferSize, +CpaStatus populateCorpusAndStartDcService(CpaDcSessionDir direction, + Cpa32U testBufferSize, corpus_type_t corpusType) { CpaStatus status = CPA_STATUS_SUCCESS; + CpaBoolean useDecompService = CPA_FALSE; /* Populate Corpus: copy from file on disk into memory*/ /* this method limits to compressing 1 corpus at any point in time */ status = populateCorpus(testBufferSize, corpusType); @@ -1678,7 +1733,21 @@ CpaStatus populateCorpusAndStartDcService(Cpa32U testBufferSize, } /*Start DC Services */ - status = startDcServices(DYNAMIC_BUFFER_AREA, TEMP_NUM_BUFFS); + getDecompNumInstances(); + useDecompService = + (direction == CPA_DC_DIR_DECOMPRESS && numDecompInstances_g > 0) + ? CPA_TRUE + : CPA_FALSE; + if (useDecompService) + { + status = startServices(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + DYNAMIC_BUFFER_AREA, + TEMP_NUM_BUFFS); + } + else + { + status = startDcServices(DYNAMIC_BUFFER_AREA, TEMP_NUM_BUFFS); + } if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("Error in Starting Dc Services\n"); @@ -1775,6 +1844,7 @@ CpaStatus performSleeptimeCalculation(compression_test_params_t *setup, arrayOfSrcBufferLists, arrayOfDestBufferLists, arrayOfCmpBufferLists, + NULL, resultArray); dcScSetBytesProducedAndConsumed( resultArray, setup->performanceStats, setup, dcSessDir); @@ -1795,6 +1865,7 @@ CpaStatus performSleeptimeCalculation(compression_test_params_t *setup, arrayOfSrcBufferLists, arrayOfDestBufferLists, arrayOfCmpBufferLists, + NULL, resultArray); dcScSetBytesProducedAndConsumed( resultArray, setup->performanceStats, setup, dcSessDir); @@ -1976,6 +2047,7 @@ CpaStatus performOffloadCalculationBusyLoop( arrayOfSrcBufferLists, arrayOfDestBufferLists, arrayOfCmpBufferLists, + NULL, resultArray); dcScSetBytesProducedAndConsumed( @@ -1994,6 +2066,7 @@ CpaStatus performOffloadCalculationBusyLoop( arrayOfSrcBufferLists, arrayOfDestBufferLists, arrayOfCmpBufferLists, + NULL, resultArray); dcScSetBytesProducedAndConsumed( diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/cpa_sample_code_main.c b/quickassist/lookaside/access_layer/src/sample_code/performance/cpa_sample_code_main.c index a2931e02..069af5ac 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/cpa_sample_code_main.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/cpa_sample_code_main.c @@ -94,26 +94,48 @@ int includeWirelessAlgs; int configFileVersion; int runStateful; int includeLZ4; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +int response_mode = 0; /* 0=polling, 1=epoll */ +int halfinstance_response = 0; /* 0=polling, 1=epoll */ +#endif /*SUPPORTED_FEAT_EPOLL && STV_TEST_CODE*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +int coalescing_timer_ns = 0; /* 0=feature disabled, >0 = ns value */ +int halfinstance_coalescing = 0; /* 1=apply to half of instances only */ +#endif /*SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE*/ static int singleInstThread = 0; -option_t optArray[MAX_NUMOPT] = { { "signOfLife", DEFAULT_SIGN_OF_LIFE }, - { "runTests", RUN_ALL_TESTS }, - { "cyNumBuffers", DEFAULT_CY_BUFFERS }, - { "cyAsymLoops", DEFAULT_ASYM_LOOPS }, - { "cySymLoops", DEFAULT_SYM_LOOPS }, - { "dcLoops", DEFAULT_DC_LOOPS }, - { "includeWirelessAlgs", - DEFAULT_INCLUDE_WIRELESS_ALGS }, - { "configFileVer", USE_V2_CONFIG_FILE }, - { "runStateful", 0 }, - { "useStaticPrime", 1 }, - { "getLatency", 0 }, - { "getOffloadCost", 0 }, - { "includeLZ4", DEFAULT_INCLUDE_LZ4 }, - { "compOnly", 0 }, - { "singleInstThread", 0 }, - { "verboseOutput", 1 } - }; +option_t optArray[MAX_NUMOPT] = { + { "signOfLife", DEFAULT_SIGN_OF_LIFE }, + { "runTests", RUN_ALL_TESTS }, + { "cyNumBuffers", DEFAULT_CY_BUFFERS }, + { "cyAsymLoops", DEFAULT_ASYM_LOOPS }, + { "cySymLoops", DEFAULT_SYM_LOOPS }, + { "dcLoops", DEFAULT_DC_LOOPS }, + { "includeWirelessAlgs", DEFAULT_INCLUDE_WIRELESS_ALGS }, + { "configFileVer", USE_V2_CONFIG_FILE }, + { "runStateful", 0 }, + { "useStaticPrime", 1 }, + { "getLatency", 0 }, + { "getOffloadCost", 0 }, + { "includeLZ4", DEFAULT_INCLUDE_LZ4 }, + { "compOnly", 0 }, + { "singleInstThread", 0 }, + { "verboseOutput", 1 } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + , + { "response_mode", 0 }, + { "halfinstance_response", 0 } +#endif /*SUPPORTED_FEAT_EPOLL && STV_TEST_CODE*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) + , + { "coalescing_timer_ns", 0 }, + { "halfinstance_coalescing", 0 } +#endif /*SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE*/ +}; #define SIGN_OF_LIFE_OPT_ARRAY_POS (0) #define RUN_TEST_OPT_ARRAY_POS (1) @@ -129,6 +151,25 @@ option_t optArray[MAX_NUMOPT] = { { "signOfLife", DEFAULT_SIGN_OF_LIFE }, #define GET_OFFLOAD_COST_POS (11) #define RUN_LZ4_TEST_POS (12) #define SINGLE_INST_THREAD_ARRAY_POS (14) +#define VERBOSE_OUTPUT_ARRAY_POS (15) +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +#define RESPONSE_MODE_ARRAY_POS (16) +#define HALFINSTANCE_RESPONSE_ARRAY_POS (17) +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +#if defined(SUPPORTED_FEAT_EPOLL) +#define COALESCING_TIMER_ARRAY_POS (18) +#define HALFINSTANCE_COALESCING_ARRAY_POS (19) +#else /* !SUPPORTED_FEAT_EPOLL */ +#define COALESCING_TIMER_ARRAY_POS (16) +#define HALFINSTANCE_COALESCING_ARRAY_POS (17) +#endif /* SUPPORTED_FEAT_EPOLL */ +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ + #else /* #ifdef USER_SPACE */ extern int cyNumBuffers; @@ -143,6 +184,14 @@ extern int verboseOutput; #endif /* #ifdef USER_SPACE */ +/* Emit a capability-skip warning only in verbose mode (verboseOutput). */ +#define VERBOSE_WARN(...) \ + do \ + { \ + if (verboseOutput) \ + PRINT(__VA_ARGS__); \ + } while (0) + /*this function contains the top level tests, it is called main to support * user space executable, otherwise it is called in kernel space by the kernel * space init upon loading of the kernel module @@ -172,16 +221,29 @@ CpaInstanceHandle *cyInst_g = NULL; CpaInstanceHandle *symCyInst_g = NULL; CpaInstanceHandle *asymCyInst_g = NULL; CpaInstanceHandle *dcInst_g = NULL; +CpaInstanceHandle *decompInst_g = NULL; Cpa32U *cyInstMap_g = NULL; Cpa32U *symCyInstMap_g = NULL; Cpa32U *asymCyInstMap_g = NULL; Cpa32U *dcInstMap_g = NULL; +Cpa32U *decompInstMap_g = NULL; Cpa32U instMap_g; Cpa16U numInst_g = 0; +Cpa16U numdcinst_g = 0; +Cpa16U numdecompinst_g = 0; Cpa8U singleInstRequired_g = 0; extern Cpa32U packageIdCount_g; extern CpaBoolean devicesCounted_g; +/* True when the per-test compression_test_params_t::useDecompService field + * for the most-recently-registered test variation is set. The framework + * dispatch (createStartandWaitForCompletion) and the per-thread perform + * function (which selects between DATA_DECOMPRESSION and DATA_COMPRESSION + * service instances). */ +#define DISPATCH_USE_DECOMP_SERVICE \ + (((compression_test_params_t *)&thread_setup_g[testTypeCount_g][0]) \ + ->useDecompService) + #ifdef USER_SPACE #define MAX_SAMPLE_LOOPS 5 #define ONE_KILO 1000 @@ -221,7 +283,8 @@ CpaStatus checkSingleInstance() numInstances = 0; #endif /* DO_CRYPTO */ #ifdef INCLUDE_COMPRESSION - status = cpaDcGetNumInstances(&numInstances); + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances > 1) { return CPA_STATUS_FAIL; @@ -241,6 +304,7 @@ CpaStatus checkSingleInstance() #define ECDSA_CODE (8) #define DH_CODE (16) #define COMPRESSION_CODE (32) +#define DECOMPRESSION_CODE (64) #define CHAINING_CODE (128) #if CY_API_VERSION_AT_LEAST(3, 0) #define SMx_CODE (2048) @@ -284,6 +348,8 @@ int main(int argc, char *argv[]) CpaBoolean dynamicEnabled = CPA_FALSE; CpaBoolean staticEnabled = CPA_TRUE; CpaDcInstanceCapabilities dcCap = {0}; + CpaDcInstanceCapabilities deCap = { 0 }; + CpaBoolean useDecompService = CPA_FALSE; #endif CpaStatus status = CPA_STATUS_FAIL; @@ -341,6 +407,17 @@ int main(int argc, char *argv[]) computeOffloadCost = optArray[GET_OFFLOAD_COST_POS].optValue; includeLZ4 = optArray[RUN_LZ4_TEST_POS].optValue; singleInstThread = optArray[SINGLE_INST_THREAD_ARRAY_POS].optValue; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + response_mode = optArray[RESPONSE_MODE_ARRAY_POS].optValue; + halfinstance_response = optArray[HALFINSTANCE_RESPONSE_ARRAY_POS].optValue; +#endif /*SUPPORTED_FEAT_EPOLL && STV_TEST_CODE*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) + coalescing_timer_ns = optArray[COALESCING_TIMER_ARRAY_POS].optValue; + halfinstance_coalescing = + optArray[HALFINSTANCE_COALESCING_ARRAY_POS].optValue; +#endif /*SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE*/ /* Use single instance */ singleInstRequired_g = singleInstThread; @@ -460,6 +537,116 @@ int main(int argc, char *argv[]) } #ifdef DO_CRYPTO +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Configure epoll response mode if enabled via command line */ + if (response_mode == 1 && halfinstance_response == 0) + { + PRINT("Epoll mode enabled via responseMode=1\n"); + /* Set response mode for all CY instances */ + status = setCyInstanceResponseModeByValue(1); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to enable epoll mode: %d\n", status); + } + else + { + PRINT("Epoll mode successfully configured for all CY instances\n"); + } + status = applyCyInstanceResponseModeConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply epoll mode configuration: %d\n", status); + } + else + { + PRINT("Epoll mode configuration applied successfully\n"); + } + } + else if (halfinstance_response == 1) + { + PRINT("Epoll mode enabled for HALF instances via " + "halfinstance_response=1\n"); + /* Set response mode for half of CY instances */ + status = + configureCyInstanceResponseModeForHalf(CPA_INST_RX_NOTIFY_BY_EVENT); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to enable epoll mode: %d\n", status); + } + else + { + PRINT("Epoll mode successfully configured for HALF of CY " + "instances\n"); + } + status = applyCyInstanceResponseModeConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply epoll mode configuration: %d\n", status); + } + else + { + PRINT("Epoll mode configuration applied successfully\n"); + } + } + else + { + PRINT("Traditional polling mode (no epoll)\n"); + } +#endif /*SUPPORTED_FEAT_EPOLL && STV_TEST_CODE*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) + /* Configure RX-interrupt coalescing timer if enabled via command line */ + if (coalescing_timer_ns > 0 && halfinstance_coalescing == 0) + { + PRINT("Coalescing timer %d ns requested for all CY instances\n", + coalescing_timer_ns); + status = configureCyInstanceCoalescingTimerForAll( + (Cpa32U)coalescing_timer_ns); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to configure CY coalescing timer: %d\n", status); + } + else + { + status = applyCyInstanceCoalescingTimerConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply CY coalescing timer: %d\n", status); + } + else + { + PRINT("CY coalescing timer configuration step completed\n"); + } + } + } + else if (coalescing_timer_ns > 0 && halfinstance_coalescing == 1) + { + PRINT("Coalescing timer %d ns requested for HALF of CY instances\n", + coalescing_timer_ns); + status = configureCyInstanceCoalescingTimerForHalf( + (Cpa32U)coalescing_timer_ns); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to configure CY coalescing timer (half): %d\n", + status); + } + else + { + status = applyCyInstanceCoalescingTimerConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply CY coalescing timer (half): %d\n", + status); + } + else + { + PRINT("CY coalescing timer configuration step completed for " + "HALF\n"); + } + } + } +#endif /*SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE*/ status = cpaCyGetNumInstances(&numInst_g); if (CPA_STATUS_SUCCESS != status) { @@ -629,7 +816,7 @@ int main(int argc, char *argv[]) if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, CPA_CY_SYM_CIPHER_KASUMI_F8)) { - PRINT( + VERBOSE_WARN( "Warning! Skipping Kasumi wireless algorithm tests as " "they are not supported on " "Instance\n"); @@ -641,20 +828,22 @@ int main(int argc, char *argv[]) (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, CPA_CY_SYM_HASH_SNOW3G_UIA2))) { - PRINT("Warning! Skipping Snow3G wireless algorithm chain " - "tests as they are not supported on " - "Instance\n"); + VERBOSE_WARN( + "Warning! Skipping Snow3G wireless algorithm chain " + "tests as they are not supported on " + "Instance\n"); includeSnow3GAlgChain = 0; } + } /* Check capabilities before running AES-CBC alg tests */ if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, CPA_CY_SYM_CIPHER_AES_CBC)) { - PRINT("Warning! Skipping AES-CBC algorithm tests as " - "they are not supported on " - "Instance\n"); + VERBOSE_WARN("Warning! Skipping AES-CBC algorithm tests as " + "they are not supported on " + "Instance\n"); includeAesCbcAlg = 0; } @@ -662,9 +851,9 @@ int main(int argc, char *argv[]) if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, CPA_CY_SYM_CIPHER_AES_XTS)) { - PRINT("Warning! Skipping AES-XTS algorithm tests as " - "they are not supported on " - "Instance\n"); + VERBOSE_WARN("Warning! Skipping AES-XTS algorithm tests as " + "they are not supported on " + "Instance\n"); includeAesXtsAlg = 0; } @@ -672,9 +861,9 @@ int main(int argc, char *argv[]) if (!CPA_BITMAP_BIT_TEST(symCapInfo.ciphers, CPA_CY_SYM_CIPHER_AES_CTR)) { - PRINT("Warning! Skipping AES-CTR algorithm tests as " - "they are not supported on " - "Instance\n"); + VERBOSE_WARN("Warning! Skipping AES-CTR algorithm tests as " + "they are not supported on " + "Instance\n"); includeAesCtrAlg = 0; } @@ -684,9 +873,9 @@ int main(int argc, char *argv[]) (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, CPA_CY_SYM_HASH_AES_GCM))) { - PRINT("Warning! Skipping AES-GCM algorithm chain " - "tests as they are not supported on " - "Instance\n"); + VERBOSE_WARN("Warning! Skipping AES-GCM algorithm chain " + "tests as they are not supported on " + "Instance\n"); includeAesGcmAlgChain = 0; } @@ -696,9 +885,9 @@ int main(int argc, char *argv[]) CPA_CY_SYM_CIPHER_CHACHA)) || (!CPA_BITMAP_BIT_TEST(symCapInfo.hashes, CPA_CY_SYM_HASH_POLY))) { - PRINT("Warning! Skipping CHACHA POLY algorithm chain " - "tests as they are not supported on " - "Instance\n"); + VERBOSE_WARN("Warning! Skipping CHACHA POLY algorithm chain " + "tests as they are not supported on " + "Instance\n"); includeChachaPolyAlgChain = 0; } } @@ -709,22 +898,137 @@ int main(int argc, char *argv[]) /* Check if compression service need to be tested * and update the runTests accordingly. * */ - if (COMPRESSION_CODE & runTests) - { - runTests = COMPRESSION_CODE; - } + runTests &= (COMPRESSION_CODE | DECOMPRESSION_CODE | CHAINING_CODE); } #endif /* DO_CRYPTO */ #ifdef INCLUDE_COMPRESSION - status = cpaDcGetNumInstances(&numInst_g); - if (CPA_STATUS_SUCCESS != status) +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Configure epoll response mode if enabled via command line */ + if (response_mode == 1 && halfinstance_response == 0) { - PRINT_ERR("cpaDcGetNumInstances failed with status: %d\n", status); - return status; + PRINT("Epoll mode enabled via responseMode=1\n"); + /* Set response mode for all DC instances */ + status = setDcInstanceResponseModeByValue(1); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to enable epoll mode: %d\n", status); + } + else + { + PRINT("Epoll mode successfully configured for all DC instances\n"); + } + status = applyDcInstanceResponseModeConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply epoll mode configuration: %d\n", status); + } + else + { + PRINT("Epoll mode configuration applied successfully\n"); + } + } + else if (halfinstance_response == 1) + { + PRINT("Epoll mode enabled for HALF instances via " + "halfinstance_response=1\n"); + /* Set response mode for half of DC instances */ + status = + configureDcInstanceResponseModeForHalf(CPA_INST_RX_NOTIFY_BY_EVENT); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to enable epoll mode: %d\n", status); + } + else + { + PRINT("Epoll mode successfully configured for HALF of DC " + "instances\n"); + } + status = applyDcInstanceResponseModeConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply epoll mode configuration: %d\n", status); + } + else + { + PRINT("Epoll mode configuration applied successfully\n"); + } + } + else + { + PRINT("Traditional polling mode (no epoll)\n"); + } +#endif /*SUPPORTED_FEAT_EPOLL && STV_TEST_CODE*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) + /* Configure RX-interrupt coalescing timer if enabled via command line */ + if (coalescing_timer_ns > 0 && halfinstance_coalescing == 0) + { + PRINT("Coalescing timer %d ns requested for all DC instances\n", + coalescing_timer_ns); + status = configureDcInstanceCoalescingTimerForAll( + (Cpa32U)coalescing_timer_ns); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to configure DC coalescing timer: %d\n", status); + } + else + { + status = applyDcInstanceCoalescingTimerConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply DC coalescing timer: %d\n", status); + } + else + { + PRINT("DC coalescing timer configuration step completed\n"); + } + } + } + else if (coalescing_timer_ns > 0 && halfinstance_coalescing == 1) + { + PRINT("Coalescing timer %d ns requested for HALF of DC instances\n", + coalescing_timer_ns); + status = configureDcInstanceCoalescingTimerForHalf( + (Cpa32U)coalescing_timer_ns); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to configure DC coalescing timer (half): %d\n", + status); + } + else + { + status = applyDcInstanceCoalescingTimerConfiguration(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to apply DC coalescing timer (half): %d\n", + status); + } + else + { + PRINT("DC coalescing timer configuration step completed for " + "HALF\n"); + } + } } +#endif /*SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE*/ - if (numInst_g > 0) + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + &numdecompinst_g); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Decompression instance query failed: %d\n", status); + } + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_COMPRESSION, &numdcinst_g); + if (status != CPA_STATUS_SUCCESS) + PRINT_ERR("Compression instance query failed: %d\n", status); + if (numdcinst_g == 0 && numdecompinst_g == 0) + { + PRINT_ERR("No compression or decompression instances found.\n"); + } + if ((numdcinst_g + numdecompinst_g) > 0) { /* use single instance for latency and COO */ if (singleInstRequired_g) @@ -732,8 +1036,16 @@ int main(int argc, char *argv[]) numInst_g = 1; } /*allocate memory to store the instance handles*/ - dcInst_g = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInst_g); - if (dcInst_g == NULL) + if (numdcinst_g > 0) + { + dcInst_g = qaeMemAlloc(sizeof(CpaInstanceHandle) * numdcinst_g); + } + if (numdecompinst_g > 0) + { + decompInst_g = + qaeMemAlloc(sizeof(CpaInstanceHandle) * numdecompinst_g); + } + if (dcInst_g == NULL && decompInst_g == NULL) { PRINT_ERR("Failed to allocate memory for instances\n"); freeInstanceMapping(); @@ -741,17 +1053,40 @@ int main(int argc, char *argv[]) } /*get the instances handles and place in allocated memory*/ - status = cpaDcGetInstances(numInst_g, dcInst_g); - if (CPA_STATUS_SUCCESS != status) + if (numdcinst_g > 0) { - PRINT_ERR("cpaDcGetInstances failed with status: %d\n", status); - freeInstanceMapping(); - return status; + status = cpaGetInstances( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, numdcinst_g, dcInst_g); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaGetInstances failed with status: %d\n", status); + freeInstanceMapping(); + return status; + } + } + if (numdecompinst_g > 0) + { + status = cpaGetInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, + numdecompinst_g, + decompInst_g); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaGetInstances failed with status: %d\n", status); + freeInstanceMapping(); + return status; + } } /*allocate memory for the instance core mapping*/ - dcInstMap_g = qaeMemAlloc(sizeof(Cpa32U) * numInst_g); - if (dcInstMap_g == NULL) + if (numdcinst_g > 0) + { + dcInstMap_g = qaeMemAlloc(sizeof(Cpa32U) * numdcinst_g); + } + if (numdecompinst_g > 0) + { + decompInstMap_g = qaeMemAlloc(sizeof(Cpa32U) * numdecompinst_g); + } + if (dcInstMap_g == NULL && decompInstMap_g == NULL) { PRINT_ERR("Failed to allocate memory for instance mapping\n"); freeInstanceMapping(); @@ -767,7 +1102,7 @@ int main(int argc, char *argv[]) } memset(info, 0, sizeof(CpaInstanceInfo2)); - for (i = 0; i < numInst_g; i++) + for (i = 0; i < numdcinst_g; i++) { status = cpaDcInstanceGetInfo2(dcInst_g[i], info); if (CPA_STATUS_SUCCESS != status) @@ -783,14 +1118,42 @@ int main(int argc, char *argv[]) prevDevId = info->physInstId.acceleratorId; printDriverVersion(prevDevId); } + for (i = 0; i < numdecompinst_g; i++) + { + status = cpaDcInstanceGetInfo2(decompInst_g[i], info); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("could not get instance info\n"); + qaeMemFree((void **)&info); + return status; + } + if (prevDevId == info->physInstId.acceleratorId) + { + continue; + } + prevDevId = info->physInstId.acceleratorId; + printDriverVersion(prevDevId); + } qaeMemFree((void **)&info); - - status = cpaDcQueryCapabilities(dcInst_g[0], &dcCap); - if (CPA_STATUS_SUCCESS != status) + if (numdcinst_g > 0) { - PRINT_ERR("cpaDcQueryCapabilities failed with status: %d\n", - status); - return status; + status = cpaDcQueryCapabilities(dcInst_g[0], &dcCap); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcQueryCapabilities failed with status: %d\n", + status); + return status; + } + } + if (numdecompinst_g > 0) + { + status = cpaDcQueryCapabilities(decompInst_g[0], &deCap); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcQueryCapabilities failed with status: %d\n", + status); + return status; + } } } else @@ -816,833 +1179,844 @@ int main(int argc, char *argv[]) **************************************************************************/ if ((SYMMETRIC_CODE & runTests) == SYMMETRIC_CODE) { - if (includeAesCbcAlg) - { - /*AES128-CBC TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; + if (includeAesCbcAlg) + { + /*AES128-CBC TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-CBC TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-CBC HMAC-SHA512 test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_SHA512, + CPA_CY_SYM_HASH_MODE_AUTH, + SHA512_AUTH_KEY_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES256-CBC AES-XCBC-MAC test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_AES_XCBC, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_XCBC_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES256-CBC HMAC-SHA512 test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_SHA512, + CPA_CY_SYM_HASH_MODE_AUTH, + SHA512_AUTH_KEY_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES256-CBC AES-XCBC-MAC test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_AES_XCBC, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_XCBC_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES128-CBC TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-CBC TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CBC, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - else - { - testsExecuted++; + } + + if (includeAesXtsAlg) + { + /*AES128-XTS TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_XTS, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-XTS TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_XTS, + KEY_SIZE_512_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES128-XTS TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_XTS, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-XTS TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_XTS, + KEY_SIZE_512_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + } + + if (includeAesCtrAlg) + { + /*AES128-CTR TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CTR, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-CTR TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CTR, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES128-CTR TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CTR, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*AES256-CTR TEST*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CTR, + KEY_SIZE_256_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } } - /*AES256-CBC TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + if (includeAesGcmAlgChain) + { + /*AES128-GCM AES-GCM test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_AES_GCM, + KEY_SIZE_128_IN_BYTES, + CPA_CY_SYM_HASH_AES_GCM, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_GCM_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES256-GCM AES-GCM test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_AES_GCM, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_AES_GCM, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_GCM_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES128-GCM AES-GCM test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_AES_GCM, + KEY_SIZE_128_IN_BYTES, + CPA_CY_SYM_HASH_AES_GCM, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_GCM_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*AES256-GCM AES-GCM test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_AES_GCM, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_AES_GCM, + CPA_CY_SYM_HASH_MODE_AUTH, + AES_GCM_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + } + + if (includeChachaPolyAlgChain) + { + /*CHACHA POLY test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_CHACHA, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_POLY, + CPA_CY_SYM_HASH_MODE_AUTH, + POLY_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + packetSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*CHACHA POLY test*/ + for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + { + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_CHACHA, + KEY_SIZE_256_IN_BYTES, + CPA_CY_SYM_HASH_POLY, + CPA_CY_SYM_HASH_MODE_AUTH, + POLY_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + packetSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + } + + if (includeKasumiAlg) { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; - } - else + /*KASUMI TEST*/ + for (lv_count = 0; lv_count < numWirelessPacketSizes; + lv_count++) { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) + status = setupCipherTest(CPA_CY_SYM_CIPHER_KASUMI_F8, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + wirelessPacketSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + + /*KASUMI TEST*/ + for (lv_count = 0; lv_count < numWirelessPacketSizes; + lv_count++) { - retStatus = CPA_STATUS_FAIL; + + status = + setupCipherDpTest(CPA_CY_SYM_CIPHER_KASUMI_F8, + KEY_SIZE_128_IN_BYTES, + CPA_CY_PRIORITY_HIGH, + ASYNC, + wirelessPacketSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupCipherDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } } - /*AES256-CBC HMAC-SHA512 test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) + if (includeSnow3GAlgChain) { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_SHA512, - CPA_CY_SYM_HASH_MODE_AUTH, - SHA512_AUTH_KEY_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else + /*SNOW3G-UEA2 HMAC-SNOW3G-UIA2 TEST*/ + for (lv_count = 0; lv_count < numWirelessPacketSizes; + lv_count++) { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) + status = setupAlgChainTest( + CPA_CY_SYM_CIPHER_SNOW3G_UEA2, + KEY_SIZE_128_IN_BYTES, + CPA_CY_SYM_HASH_SNOW3G_UIA2, + CPA_CY_SYM_HASH_MODE_AUTH, + SNOW3G_UIA2_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_NORMAL, + ASYNC, + wirelessPacketSizes[lv_count], + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + + /*SNOW3G-UEA2 HMAC-SNOW3G-UIA2 TEST*/ + for (lv_count = 0; lv_count < numWirelessPacketSizes; + lv_count++) { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES256-CBC AES-XCBC-MAC test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_AES_XCBC, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_XCBC_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES256-CBC HMAC-SHA512 test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_SHA512, - CPA_CY_SYM_HASH_MODE_AUTH, - SHA512_AUTH_KEY_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES256-CBC AES-XCBC-MAC test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_AES_XCBC, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_XCBC_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES128-CBC TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES256-CBC TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CBC, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - } - - if (includeAesXtsAlg) - { - /*AES128-XTS TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_XTS, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES256-XTS TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_XTS, - KEY_SIZE_512_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES128-XTS TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_XTS, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES256-XTS TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_XTS, - KEY_SIZE_512_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - } - - if (includeAesCtrAlg) - { - /*AES128-CTR TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CTR, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES256-CTR TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_AES_CTR, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES128-CTR TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CTR, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*AES256-CTR TEST*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_AES_CTR, - KEY_SIZE_256_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - } - - if (includeAesGcmAlgChain) - { - /*AES128-GCM AES-GCM test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_AES_GCM, - KEY_SIZE_128_IN_BYTES, - CPA_CY_SYM_HASH_AES_GCM, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_GCM_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES256-GCM AES-GCM test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_AES_GCM, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_AES_GCM, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_GCM_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES128-GCM AES-GCM test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_AES_GCM, - KEY_SIZE_128_IN_BYTES, - CPA_CY_SYM_HASH_AES_GCM, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_GCM_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*AES256-GCM AES-GCM test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_AES_GCM, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_AES_GCM, - CPA_CY_SYM_HASH_MODE_AUTH, - AES_GCM_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - } - - if (includeChachaPolyAlgChain) - { - /*CHACHA POLY test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_CHACHA, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_POLY, - CPA_CY_SYM_HASH_MODE_AUTH, - POLY_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - packetSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*CHACHA POLY test*/ - for (lv_count = 0; lv_count < numPacketSizes; lv_count++) - { - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_CHACHA, - KEY_SIZE_256_IN_BYTES, - CPA_CY_SYM_HASH_POLY, - CPA_CY_SYM_HASH_MODE_AUTH, - POLY_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - packetSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - } - - if (includeKasumiAlg) - { - /*KASUMI TEST*/ - for (lv_count = 0; lv_count < numWirelessPacketSizes; lv_count++) - { - status = setupCipherTest(CPA_CY_SYM_CIPHER_KASUMI_F8, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - wirelessPacketSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - - /*KASUMI TEST*/ - for (lv_count = 0; lv_count < numWirelessPacketSizes; lv_count++) - { - - status = setupCipherDpTest(CPA_CY_SYM_CIPHER_KASUMI_F8, - KEY_SIZE_128_IN_BYTES, - CPA_CY_PRIORITY_HIGH, - ASYNC, - wirelessPacketSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupCipherDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } - } - - if (includeSnow3GAlgChain) - { - /*SNOW3G-UEA2 HMAC-SNOW3G-UIA2 TEST*/ - for (lv_count = 0; lv_count < numWirelessPacketSizes; lv_count++) - { - status = setupAlgChainTest( - CPA_CY_SYM_CIPHER_SNOW3G_UEA2, - KEY_SIZE_128_IN_BYTES, - CPA_CY_SYM_HASH_SNOW3G_UIA2, - CPA_CY_SYM_HASH_MODE_AUTH, - SNOW3G_UIA2_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_NORMAL, - ASYNC, - wirelessPacketSizes[lv_count], - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - - /*SNOW3G-UEA2 HMAC-SNOW3G-UIA2 TEST*/ - for (lv_count = 0; lv_count < numWirelessPacketSizes; lv_count++) - { - status = setupAlgChainDpTest( - CPA_CY_SYM_CIPHER_SNOW3G_UEA2, - KEY_SIZE_128_IN_BYTES, - CPA_CY_SYM_HASH_SNOW3G_UIA2, - CPA_CY_SYM_HASH_MODE_AUTH, - SNOW3G_UIA2_DIGEST_LENGTH_IN_BYTES, - CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, - CPA_CY_PRIORITY_HIGH, - ASYNC, - wirelessPacketSizes[lv_count], - SYM_DP_ENQUEUEING, - DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, - SINGLE_REQUEST, - SYM_DP_SINGLE_SESSION, - cyNumBuffers, - cySymLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupAlgChainDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletionCrypto(SYM); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - } /*End of test*/ - } + status = setupAlgChainDpTest( + CPA_CY_SYM_CIPHER_SNOW3G_UEA2, + KEY_SIZE_128_IN_BYTES, + CPA_CY_SYM_HASH_SNOW3G_UIA2, + CPA_CY_SYM_HASH_MODE_AUTH, + SNOW3G_UIA2_DIGEST_LENGTH_IN_BYTES, + CPA_CY_SYM_ALG_CHAIN_ORDER_CIPHER_THEN_HASH, + CPA_CY_PRIORITY_HIGH, + ASYNC, + wirelessPacketSizes[lv_count], + SYM_DP_ENQUEUEING, + DEFAULT_CPA_FLAT_BUFFERS_PER_LIST, + SINGLE_REQUEST, + SYM_DP_SINGLE_SESSION, + cyNumBuffers, + cySymLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupAlgChainDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletionCrypto(SYM); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } /*End of test*/ + } } #endif /* DO_CRYPTO */ @@ -1915,537 +2289,1226 @@ int main(int argc, char *argv[]) * START OF COMPRESSION TESTS CALGARY CORPUS **************************************************************************/ if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) || - ((CHAINING_CODE & runTests) == CHAINING_CODE)) + ((CHAINING_CODE & runTests) == CHAINING_CODE) || + ((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE)) { - status = cpaDcGetNumInstances(&numDcInst); - /* Check the status */ - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Unable to Get Number of DC instances\n"); - return CPA_STATUS_FAIL; - } + /* Reuse the global count already queried above so chaining/DC + * code paths that guard on numDcInst work under SC_WITH_QAT51. */ + numDcInst = numdcinst_g; } /************************************************************************** * COMPRESSION TESTS CALGARY CORPUS **************************************************************************/ - - if ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) || + ((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE)) { - - if (numDcInst > 0) + if (numdcinst_g > 0 || numdecompinst_g > 0) { - disableAdditionalCmpbufferSize_g = 1; - dynamicHuffmanEnabled(NULL, &dynamicEnabled); - -#if defined(SC_BSD_UPSTREAM) || !defined(_KERNEL) - /*STATIC L1 & L3 COMPRESSION*/ - if (staticEnabled) + useDecompService = + (numdecompinst_g > 0 && + (DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) + ? CPA_TRUE + : CPA_FALSE; + if (useDecompService) { - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_STATIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_STATIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_STATIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_STATIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } + setDecompServiceRequest(1); } + disableAdditionalCmpbufferSize_g = 1; - /*DYNAMIC L1 & L3 COMPRESSION*/ - if (dynamicEnabled) + if ((numdcinst_g > 0 && + (COMPRESSION_CODE & runTests) == COMPRESSION_CODE) || + (numdcinst_g > 0 && numdecompinst_g == 0 && + (DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE)) { - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_FULL_DYNAMIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_FULL_DYNAMIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_FULL_DYNAMIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - status = setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_FULL_DYNAMIC, - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } + dynamicHuffmanEnabled( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, NULL, &dynamicEnabled); } - - if (staticEnabled) + else { - /*DECOMPRESSION OF ZLIB COMPRESSED DATA*/ - useZlib(); - status = - setupDcTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, /*not used in this test*/ - CPA_DC_HT_STATIC, /*not used in this test*/ - CPA_DC_STATELESS, - DEFAULT_COMPRESSION_WINDOW_SIZE, - dcBufferSize, - sampleCorpus, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - useAccelCompression(); + dynamicHuffmanEnabled( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, NULL, &dynamicEnabled); } - - if (runStateful && dynamicEnabled) + if (numdcinst_g > 0) { - /*STATEFUL COMPRESSION TEST*/ - status = setupDcStatefulTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_FULL_DYNAMIC, - BUFFER_SIZE_8192, - sampleCorpus, - SYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Stateful setup failed\n"); - } - else - { - testsExecuted++; - } - - /*set the array of cores to create threads on*/ - for (lv_count = 0; - lv_count < - sizeof(statefulMultiThreadCoreMap) / sizeof(Cpa32U); - lv_count++) - { - statefulMultiThreadCoreMap[lv_count] = - lv_count % NUMBER_OF_CORES_TO_USE; - } - /*create the threads using all available instances*/ - status = createPerfomanceThreads( - sizeof(statefulMultiThreadCoreMap) / sizeof(Cpa32U), - statefulMultiThreadCoreMap, - numInst_g, - 0); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Could not create threads\n"); - return status; - } - status = startThreads(); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error starting threads\n"); - return status; - } - status = waitForThreadCompletion(); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Stateful Compression thread(s) failed\n"); - return status; - } + staticHuffmanEnabled( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, NULL, &staticEnabled); + } + else + { + staticHuffmanEnabled( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, NULL, &staticEnabled); } -#endif /* _KERNEL */ - - /* Data Plane API Sample Code Test */ - /*STATIC DP_API L1 & L3 COMPRESS & DECOMPRESS*/ - if (staticEnabled) - { - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_STATIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_STATIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_STATIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_STATIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; +#if defined(SC_BSD_UPSTREAM) || !defined(_KERNEL) + /*STATIC L1 & L3 COMPRESSION*/ + if (staticEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + } + /*STATIC L1 & L2 COMPRESSION - 64KB packets*/ + if (staticEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } } + /*DYNAMIC L1 & L3 COMPRESSION*/ if (dynamicEnabled) { - /*DYNAMIC DP_API L1 & L3 COMPRESS & DECOMPRESS*/ - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_FULL_DYNAMIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + } + /*DYNAMIC L1 & L2 COMPRESSION - 64KB packets*/ + if (dynamicEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } + } - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_HT_FULL_DYNAMIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + if (staticEnabled) + { + /*DECOMPRESSION OF ZLIB COMPRESSED DATA*/ + useZlib(); + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcTest( + CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, /*not used in this test*/ + CPA_DC_HT_STATIC, /*not used in this test*/ + CPA_DC_STATELESS, + DEFAULT_COMPRESSION_WINDOW_SIZE, + dcBufferSize, + sampleCorpus, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + useAccelCompression(); } + } - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_FULL_DYNAMIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + if (runStateful && dynamicEnabled) + { + /*STATEFUL COMPRESSION TEST*/ + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcStatefulTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + BUFFER_SIZE_8192, + sampleCorpus, + SYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Stateful setup failed\n"); + } + else + { + testsExecuted++; + } + + /*set the array of cores to create threads on*/ + for (lv_count = 0; + lv_count < + sizeof(statefulMultiThreadCoreMap) / sizeof(Cpa32U); + lv_count++) + { + statefulMultiThreadCoreMap[lv_count] = + lv_count % NUMBER_OF_CORES_TO_USE; + } + /*create the threads using all available instances*/ + status = createPerfomanceThreads( + sizeof(statefulMultiThreadCoreMap) / sizeof(Cpa32U), + statefulMultiThreadCoreMap, + numInst_g, + 0); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Could not create threads\n"); + return status; + } + status = startThreads(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error starting threads\n"); + return status; + } + status = waitForThreadCompletion(); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Stateful Compression thread(s) failed\n"); + return status; + } } + } +#endif /* _KERNEL */ - status = setupDcDpTest(CPA_DC_DEFLATE, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L2, - CPA_DC_HT_FULL_DYNAMIC, - DEFAULT_COMPRESSION_WINDOW_SIZE, - BUFFER_SIZE_8192, - sampleCorpus, - ASYNC, - DC_DP_ENQUEUEING, - SINGLE_REQUEST, - dcLoops); - if (CPA_STATUS_SUCCESS != status) + /* Data Plane API Sample Code Test */ + /*STATIC DP_API L1 & L3 COMPRESS & DECOMPRESS*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + if (halfinstance_response == 1) + goto skip_static_dp_tests; +#endif + if (staticEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) { - PRINT_ERR("Error calling setupDcDpTest\n"); - return CPA_STATUS_FAIL; + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - else + } + /*STATIC DP_API L1 & L2 COMPRESS & DECOMPRESS - 64KB packets*/ + if (staticEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) { - testsExecuted++; + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_STATIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) + } + if (dynamicEnabled) + { + /*DYNAMIC DP_API L1 & L3 COMPRESS & DECOMPRESS*/ + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_8192, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + } + /*DYNAMIC DP_API L1 & L2 COMPRESS & DECOMPRESS - 64KB packets*/ + if (dynamicEnabled) + { + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) { - retStatus = CPA_STATUS_FAIL; + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if (((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) + { + status = setupDcDpTest(CPA_DC_DEFLATE, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L2, + CPA_DC_HT_FULL_DYNAMIC, + DEFAULT_COMPRESSION_WINDOW_SIZE, + BUFFER_SIZE_65536, + sampleCorpus, + ASYNC, + DC_DP_ENQUEUEING, + SINGLE_REQUEST, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcDpTest\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + skip_static_dp_tests:; +#endif #ifdef USER_SPACE #if DC_API_VERSION_AT_LEAST(3, 1) if (includeLZ4 == 1) @@ -2453,204 +3516,240 @@ int main(int argc, char *argv[]) /*LZ4 Tests Compression & Decompression */ /*XXhash global flag need to be set for LZ4 tests*/ setChecksum(CPA_DC_XXHASH32); - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_STATELESS, - BUFFER_SIZE_8192, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_STATELESS, - BUFFER_SIZE_65536, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L9, - CPA_DC_STATELESS, - BUFFER_SIZE_8192, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_COMPRESS, - SAMPLE_CODE_CPA_DC_L9, - CPA_DC_STATELESS, - BUFFER_SIZE_65536, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_STATELESS, - BUFFER_SIZE_8192, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L1, - CPA_DC_STATELESS, - BUFFER_SIZE_65536, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L9, - CPA_DC_STATELESS, - BUFFER_SIZE_8192, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; - } - - setupDcLZ4Test(CPA_DC_LZ4, - CPA_DC_DIR_DECOMPRESS, - SAMPLE_CODE_CPA_DC_L9, - CPA_DC_STATELESS, - BUFFER_SIZE_65536, - sampleCorpus, - CPA_DC_MIN_4_BYTE_MATCH, - CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, - ASYNC, - dcLoops); - if (CPA_STATUS_SUCCESS != status) - { - PRINT_ERR("Error calling setupDcLZ4Test\n"); - return CPA_STATUS_FAIL; - } - else - { - testsExecuted++; - } - status = createStartandWaitForCompletion(COMPRESSION); - if (CPA_STATUS_SUCCESS != status) - { - retStatus = CPA_STATUS_FAIL; + if (((COMPRESSION_CODE & runTests) == COMPRESSION_CODE) && + numdcinst_g > 0) + { + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_STATELESS, + BUFFER_SIZE_8192, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_STATELESS, + dcBufferSize, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L9, + CPA_DC_STATELESS, + BUFFER_SIZE_8192, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_COMPRESS, + SAMPLE_CODE_CPA_DC_L9, + CPA_DC_STATELESS, + dcBufferSize, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + status = createStartandWaitForCompletion(COMPRESSION); + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + } + if ((((DECOMPRESSION_CODE & runTests) == DECOMPRESSION_CODE) || + ((COMPRESSION_CODE & runTests) == COMPRESSION_CODE)) && + numdecompinst_g == 0) + { + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_STATELESS, + BUFFER_SIZE_8192, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L1, + CPA_DC_STATELESS, + dcBufferSize, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L9, + CPA_DC_STATELESS, + BUFFER_SIZE_8192, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } + + status = setupDcLZ4Test(CPA_DC_LZ4, + CPA_DC_DIR_DECOMPRESS, + SAMPLE_CODE_CPA_DC_L9, + CPA_DC_STATELESS, + dcBufferSize, + sampleCorpus, + CPA_DC_MIN_4_BYTE_MATCH, + CPA_DC_LZ4_MAX_BLOCK_SIZE_64K, + ASYNC, + dcLoops); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Error calling setupDcLZ4Test\n"); + return CPA_STATUS_FAIL; + } + else + { + testsExecuted++; + } + if (DISPATCH_USE_DECOMP_SERVICE) + { + status = createStartandWaitForCompletion(DECOMPRESSION); + } + else + { + status = createStartandWaitForCompletion(COMPRESSION); + } + if (CPA_STATUS_SUCCESS != status) + { + retStatus = CPA_STATUS_FAIL; + } } } #else @@ -2789,6 +3888,11 @@ int main(int argc, char *argv[]) } } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + if (halfinstance_response == 1) + goto skip_algchain_sm_tests; +#endif for (sm_count = 0; sm_count < algChainSM4SM3TestList_count; sm_count++) { for (lv_count = 0; lv_count < numPacketSizes; lv_count++) @@ -2857,6 +3961,10 @@ int main(int argc, char *argv[]) } } } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + skip_algchain_sm_tests:; +#endif } #endif /*DO_CRYPTO*/ #endif @@ -2874,6 +3982,8 @@ int main(int argc, char *argv[]) prevCnVRequestFlag = getSetupCnVRequestFlag(); setSetupCnVRequestFlag(STRICT_CNV_CONDITIONAL_RECOVERY | LOOSE_CNV_CONDITIONAL_RECOVERY); + staticHuffmanEnabled( + CPA_ACC_SVC_TYPE_DATA_COMPRESSION, NULL, &staticEnabled); if (staticEnabled) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.c index 9cb82e7f..5b955e38 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.c @@ -46,6 +46,12 @@ CpaBoolean timeStampInLoop = CPA_FALSE; EXPORT_SYMBOL(timeStampTime_g); long cyPollingThreadsInterval_g = 0; EXPORT_SYMBOL(cyPollingThreadsInterval_g); +Cpa32U gcmAadLenInBytes_g = 0; +EXPORT_SYMBOL(gcmAadLenInBytes_g); +Cpa32U ccmAadLenInBytes_g = 0; +EXPORT_SYMBOL(ccmAadLenInBytes_g); +Cpa32U chachaPolyAadLenInBytes_g = 0; +EXPORT_SYMBOL(chachaPolyAadLenInBytes_g); #define NUM_BITS_IN_MEGABIT (1000000) #define LOWEST_EVEN_NUMBER (2) @@ -869,6 +875,66 @@ CpaStatus setCyPollInterval(Cpa32U interval) } EXPORT_SYMBOL(setCyPollInterval); +CpaStatus setGcmAadLen(Cpa32U aadLenInBytes) +{ + if (aadLenInBytes > AES_CCM_MIN_AAD_ALLOC_LENGTH) + { + PRINT_ERR("GCM AAD length %u exceeds max alloc %d\n", + aadLenInBytes, + AES_CCM_MIN_AAD_ALLOC_LENGTH); + return CPA_STATUS_INVALID_PARAM; + } + gcmAadLenInBytes_g = aadLenInBytes; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setGcmAadLen); + +CpaStatus setCcmAadLen(Cpa32U aadLenInBytes) +{ + if (aadLenInBytes > AES_CCM_MIN_AAD_ALLOC_LENGTH) + { + PRINT_ERR("CCM AAD length %u exceeds max alloc %d\n", + aadLenInBytes, + AES_CCM_MIN_AAD_ALLOC_LENGTH); + return CPA_STATUS_INVALID_PARAM; + } + ccmAadLenInBytes_g = aadLenInBytes; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCcmAadLen); + +Cpa32U getGcmAadLen(void) +{ + return gcmAadLenInBytes_g; +} +EXPORT_SYMBOL(getGcmAadLen); + +Cpa32U getCcmAadLen(void) +{ + return ccmAadLenInBytes_g; +} +EXPORT_SYMBOL(getCcmAadLen); + +CpaStatus setChachaPolyAadLen(Cpa32U aadLenInBytes) +{ + if (aadLenInBytes > AES_CCM_MIN_AAD_ALLOC_LENGTH) + { + PRINT_ERR("ChaChaPoly AAD length %u exceeds max alloc %d\n", + aadLenInBytes, + AES_CCM_MIN_AAD_ALLOC_LENGTH); + return CPA_STATUS_INVALID_PARAM; + } + chachaPolyAadLenInBytes_g = aadLenInBytes; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setChachaPolyAadLen); + +Cpa32U getChachaPolyAadLen(void) +{ + return chachaPolyAadLenInBytes_g; +} +EXPORT_SYMBOL(getChachaPolyAadLen); + static void sampleCodePoll(CpaInstanceHandle instanceHandle_in) { CpaStatus status = CPA_STATUS_FAIL; @@ -898,7 +964,7 @@ static void sampleCodePoll(CpaInstanceHandle instanceHandle_in) } /*start crypto acceleration service if its not already started*/ -CpaStatus startCyServices(void) +CpaStatus startCryptoServices(CpaAccelerationServiceType serviceType) { CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U i = 0; @@ -907,7 +973,7 @@ CpaStatus startCyServices(void) if (cy_service_started_g == CPA_FALSE) { /*start all crypto instances*/ - status = cpaCyGetNumInstances(&numInstances_g); + status = cpaGetNumInstances(serviceType, &numInstances_g); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("cpaCyGetNumInstances failed with status: %d\n", status); @@ -922,7 +988,8 @@ CpaStatus startCyServices(void) PRINT_ERR("Failed to allocate memory for instances\n"); return CPA_STATUS_FAIL; } - status = cpaCyGetInstances(numInstances_g, cyInstances_g); + status = + cpaGetInstances(serviceType, numInstances_g, cyInstances_g); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("cpaCyGetInstances failed with status: %d\n", status); @@ -974,6 +1041,21 @@ CpaStatus startCyServices(void) return status; } +CpaStatus startCyServices(void) +{ + return startCryptoServices(CPA_ACC_SVC_TYPE_CRYPTO); +} + +CpaStatus startSymServices(void) +{ + return startCryptoServices(CPA_ACC_SVC_TYPE_CRYPTO_SYM); +} + +CpaStatus startAsymServices(void) +{ + return startCryptoServices(CPA_ACC_SVC_TYPE_CRYPTO_ASYM); +} + /*stop all crypto services*/ CpaStatus stopCyServices(void) { @@ -2937,31 +3019,11 @@ CpaStatus waitForResponses(perf_data_t *perfData, return status; } -static CpaStatus trySetupLegacyEventPoll(CpaInstanceHandle instanceHandle, - performance_func_t *pollFn) -{ #if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) - CpaStatus status = CPA_STATUS_SUCCESS; - int fd = -1; +#endif /* USER_SPACE && !SC_EPOLL_DISABLED */ - status = icp_sal_CyGetFileDescriptor(instanceHandle, &fd); - if (CPA_STATUS_SUCCESS == status) - { - *pollFn = sampleCodeCyEventPoll; - icp_sal_CyPutFileDescriptor(instanceHandle, fd); - return CPA_STATUS_SUCCESS; - } - else if (CPA_STATUS_FAIL == status) - { - return CPA_STATUS_FAIL; - } - /* else feature is unsupported */ - return CPA_STATUS_UNSUPPORTED; -#else - /* Event-based polling not applicable in this configuration */ - return CPA_STATUS_UNSUPPORTED; -#endif -} +#if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) +#endif /* USER_SPACE && !SC_EPOLL_DISABLED */ CpaStatus cyCreatePollingThreadsIfPollingIsEnabled(void) { @@ -3008,16 +3070,25 @@ CpaStatus cyCreatePollingThreadsIfPollingIsEnabled(void) if (CPA_TRUE == instanceInfo2[i].isPolled) { numPolledInstances_g++; - status = trySetupLegacyEventPoll(cyInstances_g[i], &pollFnArr[i]); - if (CPA_STATUS_FAIL == status) +#if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) { - PRINT_ERR("Error getting file descriptor for Event based " - "instance #%d\n", - i); - qaeMemFree((void **)&instanceInfo2); - qaeMemFree((void **)&pollFnArr); - return CPA_STATUS_FAIL; + status = trySetupCyLegacyEventPoll(cyInstances_g[i], + &pollFnArr[i]); + if (CPA_STATUS_FAIL == status) + { + PRINT_ERR( + "Error getting file descriptor for Event based " + "instance #%d\n", + i); + qaeMemFree((void **)&instanceInfo2); + qaeMemFree((void **)&pollFnArr); + return CPA_STATUS_FAIL; + } } +#endif /* USER_SPACE && !defined(SC_EPOLL_DISABLED) */ +#if !defined(USER_SPACE) + setCyPollWaitFn(1, 0); +#endif if (NULL == pollFnArr[i]) { pollFnArr[i] = sampleCodePoll; @@ -3181,16 +3252,25 @@ CpaStatus asymCreatePollingThreadsIfPollingIsEnabled(void) if (CPA_TRUE == instanceInfo2[i].isPolled) { numAsymPolledInstances_g++; - status = trySetupLegacyEventPoll(asymInstances_g[i], &pollFnArr[i]); - if (CPA_STATUS_FAIL == status) +#if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) { - PRINT_ERR("Error getting file descriptor for Event based " - "instance #%d\n", - i); - qaeMemFree((void **)&instanceInfo2); - qaeMemFree((void **)&pollFnArr); - return CPA_STATUS_FAIL; + status = trySetupCyLegacyEventPoll(asymInstances_g[i], + &pollFnArr[i]); + if (CPA_STATUS_FAIL == status) + { + PRINT_ERR( + "Error getting file descriptor for Event based " + "instance #%d\n", + i); + qaeMemFree((void **)&instanceInfo2); + qaeMemFree((void **)&pollFnArr); + return CPA_STATUS_FAIL; + } } +#endif /* USER_SPACE && !defined(SC_EPOLL_DISABLED) */ +#if !defined(USER_SPACE) + setCyPollWaitFn(1, 0); +#endif if (NULL == pollFnArr[i]) { pollFnArr[i] = sampleCodePoll; @@ -3281,7 +3361,6 @@ CpaStatus asymCreatePollingThreadsIfPollingIsEnabled(void) EXPORT_SYMBOL(asymCreatePollingThreadsIfPollingIsEnabled); #endif - CpaBoolean cyCheckAllInstancesArePolled(void) { CpaInstanceInfo2 *instanceInfo2 = NULL; @@ -4058,8 +4137,11 @@ CpaBoolean checkCapability(CpaInstanceHandle *cyInstanceHandle, symTestSetup->setupData.cipherSetupData .cipherAlgorithm)) == CPA_FALSE)) { - PRINT("\nUnsupported Cipher "); - printCipherAlg(symTestSetup->setupData.cipherSetupData); + if (verboseOutput) + { + PRINT("\nUnsupported Cipher "); + printCipherAlg(symTestSetup->setupData.cipherSetupData); + } return CPA_FALSE; } break; @@ -4070,8 +4152,11 @@ CpaBoolean checkCapability(CpaInstanceHandle *cyInstanceHandle, symTestSetup->setupData.hashSetupData.hashAlgorithm)) == CPA_FALSE)) { - PRINT("\nUnsupported Hash "); - printHashAlg(symTestSetup->setupData.hashSetupData); + if (verboseOutput) + { + PRINT("\nUnsupported Hash "); + printHashAlg(symTestSetup->setupData.hashSetupData); + } return CPA_FALSE; } break; @@ -4081,8 +4166,11 @@ CpaBoolean checkCapability(CpaInstanceHandle *cyInstanceHandle, symTestSetup->setupData.cipherSetupData .cipherAlgorithm)) == CPA_FALSE)) { - PRINT("\nUnsupported AlgChain "); - printCipherAlg(symTestSetup->setupData.cipherSetupData); + if (verboseOutput) + { + PRINT("\nUnsupported AlgChain "); + printCipherAlg(symTestSetup->setupData.cipherSetupData); + } return CPA_FALSE; } if (symTestSetup->setupData.hashSetupData.hashAlgorithm && @@ -4091,8 +4179,11 @@ CpaBoolean checkCapability(CpaInstanceHandle *cyInstanceHandle, symTestSetup->setupData.hashSetupData.hashAlgorithm)) == CPA_FALSE)) { - PRINT("\nUnsupported AlgChain "); - printHashAlg(symTestSetup->setupData.hashSetupData); + if (verboseOutput) + { + PRINT("\nUnsupported AlgChain "); + printHashAlg(symTestSetup->setupData.hashSetupData); + } return CPA_FALSE; } break; @@ -4410,3 +4501,812 @@ CpaStatus checkForChachapolySupport(void) } return status; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/**< Global mask to track which instances should use which response mode (up to + * 64 instances) */ +static Cpa64U cyInstanceResponseModeMask_g = 0; +/**< Response mode to apply when explicitly configured */ +static CpaInstanceResponseMode cyConfiguredResponseMode_g = + CPA_INST_RX_NOTIFY_NONE; +/**< Flag to track if response mode has been explicitly configured */ +static CpaBoolean cyResponseModeConfigured_g = CPA_FALSE; +/**< Response mode iteration support for testing */ +static Cpa32U cyResponseModeIterationCount_g = 1; + +/** + ***************************************************************************** + * @ingroup sampleCryptoUtils + * + * @description + * Map user-provided response mode value to enum + *****************************************************************************/ +static CpaInstanceResponseMode mapUserResponseModeToEnum(Cpa32U userMode) +{ + switch (userMode) + { + case 0: + return CPA_INST_RX_NOTIFY_NONE; + case 1: + return CPA_INST_RX_NOTIFY_BY_EVENT; + default: + return CPA_INST_RX_NOTIFY_NONE; + } +} + +CpaStatus setCyInstanceResponseMode(CpaInstanceResponseMode responseMode) +{ + cyConfiguredResponseMode_g = responseMode; + cyResponseModeConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceResponseMode); + +CpaStatus setCyInstanceResponseModeWithMask(Cpa32U userMode, Cpa64U mask) +{ + CpaInstanceResponseMode responseMode = mapUserResponseModeToEnum(userMode); + cyConfiguredResponseMode_g = responseMode; + cyInstanceResponseModeMask_g = mask; + cyResponseModeConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceResponseModeWithMask); + +CpaStatus setCyInstanceResponseModeForRange(Cpa32U userMode, + Cpa16U startInst, + Cpa16U endInst) +{ + Cpa64U mask = 0; + Cpa16U i = 0; + CpaInstanceResponseMode responseMode = mapUserResponseModeToEnum(userMode); + + if (startInst > endInst || endInst >= 64) + { + PRINT_ERR( + "Invalid instance range: start=%u, end=%u\n", startInst, endInst); + return CPA_STATUS_INVALID_PARAM; + } + + for (i = startInst; i <= endInst; i++) + { + mask |= (1ULL << i); + } + + cyConfiguredResponseMode_g = responseMode; + cyInstanceResponseModeMask_g = mask; + cyResponseModeConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceResponseModeForRange); + +CpaInstanceResponseMode getCyInstanceResponseMode(void) +{ + return cyConfiguredResponseMode_g; +} +EXPORT_SYMBOL(getCyInstanceResponseMode); + +void setCyInstanceResponseModeMask(Cpa64U mask) +{ + cyInstanceResponseModeMask_g = mask; +} +EXPORT_SYMBOL(setCyInstanceResponseModeMask); + +Cpa64U getCyInstanceResponseModeMask(void) +{ + return cyInstanceResponseModeMask_g; +} +EXPORT_SYMBOL(getCyInstanceResponseModeMask); + +CpaStatus configureCyInstanceResponseModeForAll( + CpaInstanceResponseMode responseMode) +{ + Cpa16U numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + /* Get the number of CY instances */ + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Cy instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0) + { + /* No CY instances in the active config (e.g. a DC-only section). + * Nothing to configure; not a fatal condition. */ + PRINT("No CY instances available - skipping CY response mode " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + /* Set mask for all instances (up to 64 instances supported) */ + Cpa64U allInstancesMask; + + if (numInstances >= 64) + { + allInstancesMask = 0xFFFFFFFFFFFFFFFFULL; /* All 64 bits set */ + } + else + { + allInstancesMask = + (1ULL << numInstances) - 1; /* Set bits 0 to numInstances-1 */ + } + + setCyInstanceResponseMode(responseMode); + setCyInstanceResponseModeMask(allInstancesMask); + + PRINT("Explicitly configured response mode %d for %d Cy instances " + "(mask: 0x%llx)\n", + responseMode, + numInstances, + (unsigned long long)allInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureCyInstanceResponseModeForAll); + +CpaStatus configureCyInstanceResponseModeForHalf( + CpaInstanceResponseMode responseMode) +{ + Cpa16U numInstances = 0; + Cpa16U half_numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + /* Get the number of CY instances */ + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get CY instances count for response mode " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0) + { + /* No CY instances in the active config (e.g. a DC-only section). + * Nothing to configure; not a fatal condition. */ + PRINT("No CY instances available - skipping CY response mode " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + half_numInstances = numInstances / 2; + { + /* Set mask for half the instances (up to 64 instances supported) */ + Cpa64U halfInstancesMask; + + if (half_numInstances >= 64) + { + halfInstancesMask = 0xFFFFFFFFFFFFFFFFULL; /* All 64 bits set */ + } + else + { + halfInstancesMask = (1ULL << half_numInstances) - + 1; /* Set bits 0 to half_numInstances-1 */ + } + + setCyInstanceResponseMode(responseMode); + setCyInstanceResponseModeMask(halfInstancesMask); + + PRINT("Explicitly configured response mode %d for HALF (%d of %d) CY " + "instances (mask: 0x%llx)\n", + responseMode, + half_numInstances, + numInstances, + (unsigned long long)halfInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureCyInstanceResponseModeForHalf); + +CpaStatus setCyInstanceResponseModeByValue(Cpa32U userMode) +{ + CpaInstanceResponseMode enumMode = mapUserResponseModeToEnum(userMode); + configureCyInstanceResponseModeForAll(enumMode); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceResponseModeByValue); + +CpaBoolean isCyInstanceResponseModeConfigured(void) +{ + return cyResponseModeConfigured_g; +} +EXPORT_SYMBOL(isCyInstanceResponseModeConfigured); + +CpaStatus clearCyInstanceResponseModeConfiguration(void) +{ + cyResponseModeConfigured_g = CPA_FALSE; + /* Reset to a neutral value - actual library default will be queried + * per-thread */ + cyConfiguredResponseMode_g = CPA_INST_RX_NOTIFY_NONE; + cyInstanceResponseModeMask_g = 0; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(clearCyInstanceResponseModeConfiguration); + +CpaStatus applyCyInstanceResponseModeConfiguration(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa16U numInstances = 0; + CpaInstanceHandle *cyInstances = NULL; + Cpa64U instanceMask = 0; + CpaBoolean applyToAllInstances = CPA_FALSE; + Cpa16U i = 0; + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaInstanceResponseMode responseMode; + CpaInstanceResponseMode testMode = CPA_INST_RX_NOTIFY_NONE; + CpaAccelerationServiceType verifyServiceType; + + if (!isCyInstanceResponseModeConfigured()) + { + /* No explicit configuration - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + instanceMask = getCyInstanceResponseModeMask(); + + /* Get all CY instances (combined + pure SYM + pure ASYM) */ + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get number of CY instances: %d\n", status); + return status; + } + + if (numInstances == 0) + { + /* No CY instances in the active config (e.g. a DC-only section). + * Nothing to apply; not a fatal condition. */ + PRINT("No CY instances available - skipping CY response mode " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + + /* Allocate and get all crypto instances */ + cyInstances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); + if (NULL == cyInstances) + { + PRINT_ERR("Failed to allocate memory for instance handles\n"); + return CPA_STATUS_FAIL; + } + + status = cpaCyGetInstances(numInstances, cyInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get CY instances\n"); + qaeMemFree((void **)&cyInstances); + return status; + } + + responseMode = getCyInstanceResponseMode(); + + /* Process each instance individually based on its actual type */ + for (i = 0; i < numInstances && i < 64; i++) + { + /* Check if we should apply to this instance */ + if (!applyToAllInstances && !(instanceMask & (1ULL << i))) + { + /* Skip this instance if not in mask */ + continue; + } + + status = cpaCyInstanceGetInfo2(cyInstances[i], &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get info for instance %d\n", i); + continue; + } + /* Set response mode using the actual service type from instanceInfo */ + status = cpaInstanceSetResponseMode( + cyInstances[i], instanceInfo.accelerationServiceType, responseMode); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "Failed to set response mode for instance %d: %d\n", i, status); + continue; + } + + /* Verify response mode - use appropriate service type for verification + */ + if (instanceInfo.accelerationServiceType == CPA_ACC_SVC_TYPE_CRYPTO) + { + /* Combined instance - verify with SYM service type */ + verifyServiceType = CPA_ACC_SVC_TYPE_CRYPTO_SYM; + } + else + { + /* Pure SYM or ASYM instance - use its actual type */ + verifyServiceType = instanceInfo.accelerationServiceType; + } + + status = cpaInstanceGetResponseMode( + cyInstances[i], verifyServiceType, &testMode); + if (CPA_STATUS_SUCCESS == status && testMode == responseMode) + { + PRINT("Verified response mode %d for instance %d\n", testMode, i); + } + else + { + PRINT_ERR("Failed to verify response mode for instance %d (verify " + "type=%d)\n", + i, + verifyServiceType); + } + } + + /* Free allocated memory */ + qaeMemFree((void **)&cyInstances); + + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(applyCyInstanceResponseModeConfiguration); + +CpaStatus setCyResponseModeIterationCount(Cpa32U count) +{ + cyResponseModeIterationCount_g = count; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyResponseModeIterationCount); + +CpaStatus getCyResponseModeIterationCount(Cpa32U *count) +{ + if (NULL == count) + { + PRINT_ERR("Invalid parameter: count pointer is NULL\n"); + return CPA_STATUS_INVALID_PARAM; + } + *count = cyResponseModeIterationCount_g; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(getCyResponseModeIterationCount); + +CpaInstanceResponseMode getSymResponseModeWithIteration( + symmetric_test_params_t *testParams) +{ + CpaInstanceResponseMode currentMode; + CpaInstanceResponseMode alternateMode; + Cpa32U i; + /* If iteration count is 1 or less, return currentResponseMode (default + * behavior) */ + if (cyResponseModeIterationCount_g <= 1) + { + return (testParams != NULL) ? testParams->currentResponseMode + : CPA_INST_RX_NOTIFY_NONE; + } + + /* If testParams is NULL, cannot perform iteration */ + if (testParams == NULL) + { + PRINT_ERR( + "Cannot perform response mode iteration without test parameters\n"); + return CPA_INST_RX_NOTIFY_NONE; + } + /* Use currentResponseMode from test parameters as the starting point */ + currentMode = testParams->currentResponseMode; + + /* Determine alternate mode - opposite of current mode */ + if (currentMode == CPA_INST_RX_NOTIFY_NONE) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + + /* Perform iterations with alternation starting from currentResponseMode */ + for (i = 0; i < cyResponseModeIterationCount_g; i++) + { + if (i % 2 == 0) + { + /* Even iterations (0, 2, 4...): use initial mode from test params + */ + currentMode = testParams->currentResponseMode; + } + else + { + /* Odd iterations (1, 3, 5...): use alternate mode */ + currentMode = alternateMode; + } + } + return currentMode; +} +EXPORT_SYMBOL(getSymResponseModeWithIteration); + +CpaStatus enableCyResponseModeIteration(Cpa32U count) +{ + CpaStatus status; + if (count < 1) + { + PRINT_ERR("Invalid iteration count %d, using default (1)\n", count); + count = 1; + } + status = setCyResponseModeIterationCount(count); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set Cy response mode iteration count\n"); + return CPA_STATUS_FAIL; + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(enableCyResponseModeIteration); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +/**< Global mask to track which CY instances should have the coalescing timer + * applied (up to 64 instances). Covers symmetric, asymmetric, and combined + * CRYPTO instances. */ +static Cpa64U cyInstanceCoalescingTimerMask_g = 0; +/**< Coalescing timer value (in nanoseconds) to apply when explicitly + * configured */ +static Cpa32U cyConfiguredCoalescingTimerNs_g = 0; +/**< Flag to track if the coalescing timer has been explicitly configured */ +static CpaBoolean cyCoalescingTimerConfigured_g = CPA_FALSE; + +CpaStatus setCyInstanceCoalescingTimer(Cpa32U coalescingTimerInNs) +{ + cyConfiguredCoalescingTimerNs_g = coalescingTimerInNs; + cyCoalescingTimerConfigured_g = CPA_TRUE; + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceCoalescingTimer); + +Cpa32U getCyInstanceCoalescingTimer(void) +{ + return cyConfiguredCoalescingTimerNs_g; +} +EXPORT_SYMBOL(getCyInstanceCoalescingTimer); + +void setCyInstanceCoalescingTimerMask(Cpa64U mask) +{ + cyInstanceCoalescingTimerMask_g = mask; +} +EXPORT_SYMBOL(setCyInstanceCoalescingTimerMask); + +Cpa64U getCyInstanceCoalescingTimerMask(void) +{ + return cyInstanceCoalescingTimerMask_g; +} +EXPORT_SYMBOL(getCyInstanceCoalescingTimerMask); + +CpaBoolean isCyInstanceCoalescingTimerConfigured(void) +{ + return cyCoalescingTimerConfigured_g; +} +EXPORT_SYMBOL(isCyInstanceCoalescingTimerConfigured); + +CpaStatus clearCyInstanceCoalescingTimerConfiguration(void) +{ + cyCoalescingTimerConfigured_g = CPA_FALSE; + cyConfiguredCoalescingTimerNs_g = 0; + cyInstanceCoalescingTimerMask_g = 0; + + PRINT("Cleared CY instance coalescing timer configuration\n"); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(clearCyInstanceCoalescingTimerConfiguration); + +CpaStatus setCyInstanceCoalescingTimerWithMask(Cpa32U coalescingTimerInNs, + Cpa64U mask) +{ + setCyInstanceCoalescingTimer(coalescingTimerInNs); + setCyInstanceCoalescingTimerMask(mask); + + PRINT("Set CY coalescing timer %u ns for instances with mask 0x%llx\n", + coalescingTimerInNs, + (unsigned long long)mask); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceCoalescingTimerWithMask); + +CpaStatus setCyInstanceCoalescingTimerForRange(Cpa32U coalescingTimerInNs, + Cpa16U startInst, + Cpa16U endInst) +{ + Cpa64U mask = 0; + Cpa16U i; + + if (startInst > endInst || endInst >= 64) + { + PRINT_ERR("Invalid instance range %d-%d (must be 0-63)\n", + startInst, + endInst); + return CPA_STATUS_FAIL; + } + + for (i = startInst; i <= endInst; i++) + { + mask |= (1ULL << i); + } + + setCyInstanceCoalescingTimerWithMask(coalescingTimerInNs, mask); + PRINT("Configured CY instances %d-%d with coalescing timer %u ns\n", + startInst, + endInst, + coalescingTimerInNs); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(setCyInstanceCoalescingTimerForRange); + +CpaStatus configureCyInstanceCoalescingTimerForAll(Cpa32U coalescingTimerInNs) +{ + Cpa16U numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get CY instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0) + { + /* No CY instances in the active config (e.g. a DC-only section). + * Nothing to configure; not a fatal condition. */ + PRINT("No CY instances available - skipping CY coalescing timer " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + { + Cpa64U allInstancesMask; + + if (numInstances >= 64) + { + allInstancesMask = 0xFFFFFFFFFFFFFFFFULL; + } + else + { + allInstancesMask = (1ULL << numInstances) - 1; + } + + setCyInstanceCoalescingTimer(coalescingTimerInNs); + setCyInstanceCoalescingTimerMask(allInstancesMask); + + PRINT("Explicitly configured coalescing timer %u ns for %d CY " + "instances (mask: 0x%llx)\n", + coalescingTimerInNs, + numInstances, + (unsigned long long)allInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureCyInstanceCoalescingTimerForAll); + +CpaStatus configureCyInstanceCoalescingTimerForHalf(Cpa32U coalescingTimerInNs) +{ + Cpa16U numInstances = 0; + Cpa16U half_numInstances = 0; + CpaStatus status = CPA_STATUS_SUCCESS; + + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get CY instances count for coalescing timer " + "configuration\n"); + return CPA_STATUS_FAIL; + } + if (numInstances == 0) + { + PRINT("No CY instances available - skipping CY coalescing timer " + "configuration\n"); + return CPA_STATUS_SUCCESS; + } + half_numInstances = numInstances / 2; + { + Cpa64U halfInstancesMask; + + if (half_numInstances >= 64) + { + halfInstancesMask = 0xFFFFFFFFFFFFFFFFULL; + } + else + { + halfInstancesMask = (1ULL << half_numInstances) - 1; + } + + setCyInstanceCoalescingTimer(coalescingTimerInNs); + setCyInstanceCoalescingTimerMask(halfInstancesMask); + + PRINT("Explicitly configured coalescing timer %u ns for HALF (%d of " + "%d) CY instances (mask: 0x%llx)\n", + coalescingTimerInNs, + half_numInstances, + numInstances, + (unsigned long long)halfInstancesMask); + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(configureCyInstanceCoalescingTimerForHalf); + +CpaStatus getCyInstanceRxInterruptMetaData( + CpaInstanceHandle instanceHandle, + CpaRxInterruptMetaData *pInterruptData) +{ + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaAccelerationServiceType svcType; + CpaStatus status; + + if (NULL == pInterruptData) + { + PRINT_ERR("Invalid parameter: pInterruptData is NULL\n"); + return CPA_STATUS_FAIL; + } + + status = cpaCyInstanceGetInfo2(instanceHandle, &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get CY instance info: %d\n", status); + return status; + } + + /* Combined CRYPTO instances are queried via the SYM service type. */ + svcType = (instanceInfo.accelerationServiceType == CPA_ACC_SVC_TYPE_CRYPTO) + ? CPA_ACC_SVC_TYPE_CRYPTO_SYM + : instanceInfo.accelerationServiceType; + + return cpaInstanceGetRxInterruptMetaData( + instanceHandle, svcType, pInterruptData); +} +EXPORT_SYMBOL(getCyInstanceRxInterruptMetaData); + +CpaStatus applyCyInstanceCoalescingTimerConfiguration(void) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa16U numInstances = 0; + CpaInstanceHandle *cyInstances = NULL; + CpaInstanceInfo2 instanceInfo = { 0 }; + CpaRxInterruptMetaData interruptData = { 0 }; + Cpa64U instanceMask = 0; + Cpa32U coalescingTimerInNs = 0; + Cpa16U i = 0; + Cpa16U applied = 0; + CpaAccelerationServiceType svcType; + + if (!isCyInstanceCoalescingTimerConfigured()) + { + /* No explicit configuration - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + instanceMask = getCyInstanceCoalescingTimerMask(); + if (instanceMask == 0) + { + /* Empty mask - nothing to apply */ + return CPA_STATUS_SUCCESS; + } + + coalescingTimerInNs = getCyInstanceCoalescingTimer(); + + status = cpaCyGetNumInstances(&numInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get number of CY instances: %d\n", status); + return status; + } + + if (numInstances == 0) + { + PRINT_ERR("No CY instances available to apply coalescing timer\n"); + return CPA_STATUS_FAIL; + } + + cyInstances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); + if (NULL == cyInstances) + { + PRINT_ERR("Unable to allocate memory for CY instances\n"); + return CPA_STATUS_FAIL; + } + + status = cpaCyGetInstances(numInstances, cyInstances); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Unable to get CY instances: %d\n", status); + qaeMemFree((void **)&cyInstances); + return status; + } + + for (i = 0; i < numInstances && i < 64; i++) + { + if (!(instanceMask & (1ULL << i))) + { + continue; + } + + status = cpaCyInstanceGetInfo2(cyInstances[i], &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get info for CY instance %d: %d\n", i, status); + continue; + } + + /* cpaCyInstanceGetInfo2 may report + * the legacy generic CRYPTO type even on SYM-only configurations, + * so when that happens fall back to CRYPTO_SYM. Pure SYM / ASYM + * instances use their reported type. */ + svcType = + (instanceInfo.accelerationServiceType == CPA_ACC_SVC_TYPE_CRYPTO) + ? CPA_ACC_SVC_TYPE_CRYPTO_SYM + : instanceInfo.accelerationServiceType; + + status = cpaInstanceSetIntCoalescingTimer( + cyInstances[i], svcType, coalescingTimerInNs); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to set coalescing timer %u ns for CY " + "instance %d (Type=%d): %d\n", + coalescingTimerInNs, + i, + svcType, + status); + continue; + } + + memset(&interruptData, 0, sizeof(interruptData)); + status = cpaInstanceGetRxInterruptMetaData( + cyInstances[i], svcType, &interruptData); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to verify coalescing timer for CY " + "instance %d: %d\n", + i, + status); + qaeMemFree((void **)&cyInstances); + return status; + } + + if (interruptData.coalescingTimerInNs == coalescingTimerInNs) + { + PRINT("Verified coalescing timer %u ns for CY instance %d " + "(max %u ns, granularity %u ns)\n", + interruptData.coalescingTimerInNs, + i, + interruptData.coalescingTimerMaxInNs, + interruptData.coalescingTimerGranularityInNs); + applied++; + } + else + { + /* Hardware may round to nearest supported granularity. + * Treat differences within one granularity step as success. */ + Cpa32U granularity = interruptData.coalescingTimerGranularityInNs; + Cpa32U diff = + (interruptData.coalescingTimerInNs > coalescingTimerInNs) + ? (interruptData.coalescingTimerInNs - coalescingTimerInNs) + : (coalescingTimerInNs - interruptData.coalescingTimerInNs); + + if (granularity > 0 && diff <= granularity) + { + PRINT("Coalescing timer for CY instance %d rounded: " + "requested %u ns, actual %u ns (granularity %u ns)\n", + i, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + granularity); + applied++; + } + else + { + PRINT_ERR("Mismatch verifying coalescing timer for CY " + "instance %d: set %u ns, got %u ns " + "(max %u ns, granularity %u ns)\n", + i, + coalescingTimerInNs, + interruptData.coalescingTimerInNs, + interruptData.coalescingTimerMaxInNs, + granularity); + qaeMemFree((void **)&cyInstances); + return CPA_STATUS_FAIL; + } + } + } + + PRINT("Coalescing timer %u ns applied to %u CY instance(s)\n", + coalescingTimerInNs, + applied); + + qaeMemFree((void **)&cyInstances); + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(applyCyInstanceCoalescingTimerConfiguration); +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.h b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.h index 4f3b4380..5c1d22b9 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_crypto_utils.h @@ -370,6 +370,17 @@ typedef enum ec_gen_step_s #define SNOW3G_UIA2_BLOCK_LENGTH_IN_BYTES (8) #define ZUC_EIA3_BLOCK_LENGTH_IN_BYTES (4) #define SHA3_256_BLOCK_LENGTH_IN_BYTES (136) +/* Test convention: AAD buffers are initialized to this fixed pattern */ +#define AAD_INIT_PATTERN (0xAA) + +#define AES_128_CMAC_KEYLENGTH_IN_BYTES (128 / NUM_BITS_IN_BYTE) +#define AES_192_CMAC_KEYLENGTH_IN_BYTES (192 / NUM_BITS_IN_BYTE) +#define AES_256_CMAC_KEYLENGTH_IN_BYTES (256 / NUM_BITS_IN_BYTE) +#define ZUC256_KEYLENGTH_IN_BYTES (256 / NUM_BITS_IN_BYTE) +#define ZUC_EIA3_KEY_256_DIGEST_32_LENGTH_IN_BYTES ((256 + 32) / 8) +#define ZUC_EIA3_KEY_256_DIGEST_64_LENGTH_IN_BYTES ((256 + 64) / 8) +#define ZUC_EIA3_KEY_256_DIGEST_128_LENGTH_IN_BYTES ((256 + 128) / 8) +#define ZUC256_AAD_LEN_IN_BYTES (16) #define POLY_DIGEST_LENGTH_IN_BYTES (16) @@ -557,6 +568,16 @@ extern Cpa32U modSizes[]; * up 100% CPU.*/ CpaStatus setCyPollInterval(Cpa32U interval); + +extern Cpa32U gcmAadLenInBytes_g; +extern Cpa32U ccmAadLenInBytes_g; +extern Cpa32U chachaPolyAadLenInBytes_g; +CpaStatus setGcmAadLen(Cpa32U aadLenInBytes); +CpaStatus setCcmAadLen(Cpa32U aadLenInBytes); +CpaStatus setChachaPolyAadLen(Cpa32U aadLenInBytes); +Cpa32U getGcmAadLen(void); +Cpa32U getCcmAadLen(void); +Cpa32U getChachaPolyAadLen(void); /* FreeBSD scheduler is not handling "busy loops" as effective as Linux * especially in multi-thread environment where few polling threads * can be assigned to single CPU core. To avoid thread starvation @@ -720,6 +741,10 @@ typedef struct symmetric_test_params_s CpaBoolean enableRoundOffPkt; /* Identify if the test is for SSL or TLS*/ CpaBoolean isTLS; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } symmetric_test_params_t; /** @@ -760,6 +785,10 @@ typedef struct asym_test_params_s CpaBoolean enableKPT; CpaCyKptHandle kptKeyHandle; #endif +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } asym_test_params_t; /** @@ -853,6 +882,10 @@ typedef struct ecdsa_test_params_s CpaBoolean enableKPT; CpaCyKptHandle kptKeyHandle; #endif +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } ecdsa_test_params_t; #ifdef SC_SM2_ENABLED @@ -894,6 +927,10 @@ typedef struct sm2_test_params_s CpaFlatBuffer *x2; CpaFlatBuffer *y2; CpaCyEcsm2VerifyOpData **verifyOp; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } sm2_test_params_t; /** @@ -1039,6 +1076,10 @@ typedef struct hkdf_test_params_s Cpa32U numBuffers; /* number of loops to be generated */ Cpa32U numLoops; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } hkdf_test_params_t; /** @@ -1107,6 +1148,10 @@ typedef struct ec_generic_test_params_s Cpa32U numLoops; /* EC Gen step */ ec_gen_step_t step; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + CpaInstanceResponseMode currentResponseMode; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } ec_generic_test_params_t; #endif /* CY_API_VERSION_AT_LEAST(3, 0) */ @@ -1194,10 +1239,30 @@ void processCallback(void *pCallbackTag); * startCyServices * * @description - * This function starts all Crypto services available on the system + * This function starts Crypto services available on the system *****************************************************************************/ CpaStatus startCyServices(void); +/** + ***************************************************************************** + * @ingroup cryptoThreads + * startSymServices + * + * @description + * This function starts Sym services available on the system + *****************************************************************************/ +CpaStatus startSymServices(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * startAsymServices + * + * @description + * This function starts Asym services available on the system + *****************************************************************************/ +CpaStatus startAsymServices(void); + /** ***************************************************************************** * @ingroup cryptoThreads @@ -2690,4 +2755,473 @@ CpaStatus dsaGenZ(CpaInstanceHandle instanceHandle, ******************************************************************************/ CpaStatus checkForChachapolySupport(void); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/* Core response mode configuration functions */ +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceResponseMode + * + * @description + * Sets the response mode for Crypto (CY) instances. This configures + * whether instances use polling mode (CPA_INST_RX_NOTIFY_NONE) or + * event-driven mode (CPA_INST_RX_NOTIFY_BY_EVENT). + * + * @param[in] responseMode The response mode to set for CY instances: + * CPA_INST_RX_NOTIFY_NONE - Traditional polling + * CPA_INST_RX_NOTIFY_BY_EVENT - Event-driven + * + * @retval CPA_STATUS_SUCCESS Response mode set successfully + * @retval CPA_STATUS_FAIL Failed to set response mode + * + * @pre + * CY instances must be initialized + * @post + * Response mode configuration is stored for later application + * + *****************************************************************************/ +CpaStatus setCyInstanceResponseMode(CpaInstanceResponseMode responseMode); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceResponseModeWithMask + * + * @description + * Sets the response mode for specific CY instances identified by a + * bitmask. Each bit in the mask corresponds to an instance index. + * + * @param[in] userMode User-specified mode value (0 for polling, + * 1 for event-driven) + * @param[in] mask 64-bit mask where each bit represents an + * instance (bit 0 = instance 0, etc.) + * + * @retval CPA_STATUS_SUCCESS Response mode set successfully for masked + * instances + * @retval CPA_STATUS_FAIL Failed to set response mode + * + * @pre + * CY instances must be initialized + * @post + * Response mode is configured for instances specified in mask + * + *****************************************************************************/ +CpaStatus setCyInstanceResponseModeWithMask(Cpa32U userMode, Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceResponseModeForRange + * + * @description + * Sets the response mode for a contiguous range of CY instances. + * Applies the mode to instances from startInst to endInst (inclusive). + * + * @param[in] userMode User-specified mode value (0 for polling, + * 1 for event-driven) + * @param[in] startInst Starting instance index (inclusive) + * @param[in] endInst Ending instance index (inclusive) + * + * @retval CPA_STATUS_SUCCESS Response mode set successfully for range + * @retval CPA_STATUS_FAIL Failed to set response mode or invalid range + * + * @pre + * CY instances must be initialized, startInst <= endInst + * @post + * Response mode is configured for specified instance range + * + *****************************************************************************/ +CpaStatus setCyInstanceResponseModeForRange(Cpa32U userMode, + Cpa16U startInst, + Cpa16U endInst); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyInstanceResponseMode + * + * @description + * Retrieves the currently configured response mode for CY instances. + * + * @retval CpaInstanceResponseMode - Current response mode: + * CPA_INST_RX_NOTIFY_NONE or + * CPA_INST_RX_NOTIFY_BY_EVENT + * + * @pre + * Response mode must have been previously configured + * @post + * none + * + *****************************************************************************/ +CpaInstanceResponseMode getCyInstanceResponseMode(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceResponseModeMask + * + * @description + * Sets the instance selection mask that determines which CY instances + * will have response mode configuration applied. + * + * @param[in] mask 64-bit mask where each bit represents an + * instance to be configured + * + * @retval + * none + * + * @pre + * none + * @post + * Instance mask is updated for future configuration operations + * + *****************************************************************************/ +void setCyInstanceResponseModeMask(Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyInstanceResponseModeMask + * + * @description + * Retrieves the current instance selection mask that identifies which + * CY instances are configured for response mode changes. + * + * @retval Cpa64U - 64-bit mask of configured instances + * + * @pre + * none + * @post + * none + * + *****************************************************************************/ +Cpa64U getCyInstanceResponseModeMask(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * configureCyInstanceResponseModeForAll + * + * @description + * Configures the specified response mode for all available CY instances + * in the system. This is a convenience function for system-wide + * configuration. + * + * @param[in] responseMode The response mode to apply to all instances: + * CPA_INST_RX_NOTIFY_NONE or + * CPA_INST_RX_NOTIFY_BY_EVENT + * + * @retval CPA_STATUS_SUCCESS Response mode configured for all instances + * @retval CPA_STATUS_FAIL Failed to configure one or more instances + * + * @pre + * CY instances must be initialized and started + * @post + * All CY instances are configured with the specified response mode + * + *****************************************************************************/ +CpaStatus configureCyInstanceResponseModeForAll( + CpaInstanceResponseMode responseMode); +/** + ***************************************************************************** + * @ingroup cryptoThreads + * configureCyInstanceResponseModeForHalf + * + * @description + * Configures the specified response mode for all available CY instances + * in the system. This is a convenience function for system-wide + * configuration. + * + * @param[in] responseMode The response mode to apply to all instances: + * CPA_INST_RX_NOTIFY_NONE or + * CPA_INST_RX_NOTIFY_BY_EVENT + * + * @retval CPA_STATUS_SUCCESS Response mode configured for all instances + * @retval CPA_STATUS_FAIL Failed to configure one or more instances + * + * @pre + * CY instances must be initialized and started + * @post + * Half CY instances are configured with the specified response mode + * + *****************************************************************************/ +CpaStatus configureCyInstanceResponseModeForHalf( + CpaInstanceResponseMode responseMode); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceResponseModeByValue + * + * @description + * Sets the response mode using a numeric value instead of the + * CpaInstanceResponseMode enum. Useful for command-line or + * configuration file inputs. + * + * @param[in] userMode Numeric mode value: + * 0 = CPA_INST_RX_NOTIFY_NONE (polling) + * 1 = CPA_INST_RX_NOTIFY_BY_EVENT (event-driven) + * + * @retval CPA_STATUS_SUCCESS Response mode set successfully + * @retval CPA_STATUS_FAIL Failed to set response mode or invalid value + * + * @pre + * CY instances must be initialized + * @post + * Response mode configuration is updated + * + *****************************************************************************/ +CpaStatus setCyInstanceResponseModeByValue(Cpa32U userMode); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * isCyInstanceResponseModeConfigured + * + * @description + * Checks whether any CY instance response mode configuration has been + * set and is pending application. + * + * @retval CPA_TRUE Response mode configuration exists + * @retval CPA_FALSE No configuration has been set + * + * @pre + * none + * @post + * none + * + *****************************************************************************/ +CpaBoolean isCyInstanceResponseModeConfigured(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * clearCyInstanceResponseModeConfiguration + * + * @description + * Clears all pending CY instance response mode configurations and + * resets to default state. Does not affect already-applied configurations. + * + * @retval CPA_STATUS_SUCCESS Configuration cleared successfully + * @retval CPA_STATUS_FAIL Failed to clear configuration + * + * @pre + * none + * @post + * All pending response mode configurations are removed + * + *****************************************************************************/ +CpaStatus clearCyInstanceResponseModeConfiguration(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * applyCyInstanceResponseModeConfiguration + * + * @description + * Applies previously configured response mode settings to all symmetric + * CY instances. This commits the configuration changes to the hardware. + * + * @retval CPA_STATUS_SUCCESS Configuration applied successfully to all + * instances + * @retval CPA_STATUS_FAIL Failed to apply configuration to one or more + * instances + * + * @pre + * Response mode must be configured via set functions + * CY instances must be started + * @post + * Symmetric CY instances operate in the configured response mode + * + *****************************************************************************/ +CpaStatus applyCyInstanceResponseModeConfiguration(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyResponseModeIterationCount + * + * @description + * Sets the iteration count for response mode testing. This is used + * in test scenarios to control how many times response mode switching + * is performed during validation. + * + * @param[in] count Number of iterations for response mode testing + * + * @retval CPA_STATUS_SUCCESS Iteration count set successfully + * @retval CPA_STATUS_FAIL Failed to set iteration count + * + * @pre + * CY instances must be initialized + * @post + * Iteration count is updated for test execution + * + *****************************************************************************/ +CpaStatus setCyResponseModeIterationCount(Cpa32U count); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyResponseModeIterationCount + * + * @description + * Retrieves the current iteration count configured for response mode + * testing. + * + * @param[out] count Pointer to store the current iteration count + * + * @retval CPA_STATUS_SUCCESS Iteration count retrieved successfully + * @retval CPA_STATUS_FAIL Failed to retrieve iteration count or NULL + * pointer + * + * @pre + * CY instances must be initialized + * @post + * count is populated with current iteration count value + * + *****************************************************************************/ +CpaStatus getCyResponseModeIterationCount(Cpa32U *count); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +/* CY interrupt coalescing-timer configuration functions. These require the + * driver APIs cpaInstanceSetIntCoalescingTimer() and + * cpaInstanceGetRxInterruptMetaData(), and are only available when + * SUPPORTED_FEAT_INT_COALESCING_TIMER is set. + * Covers symmetric (CRYPTO_SYM), asymmetric (CRYPTO_ASYM), and combined + * (CRYPTO) instances. */ + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceCoalescingTimer + * + * @description + * Sets the interrupt coalescing timer value (in nanoseconds) that will + * be applied to CY instances specified by the mask. Explicitly overrides + * the QAT library's default coalescing timer. + * + *****************************************************************************/ +CpaStatus setCyInstanceCoalescingTimer(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceCoalescingTimerWithMask + * + * @description + * Combined function that sets both the coalescing timer value and the + * instance mask in a single call. + * + *****************************************************************************/ +CpaStatus setCyInstanceCoalescingTimerWithMask(Cpa32U coalescingTimerInNs, + Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceCoalescingTimerForRange + * + * @description + * Convenience function to set the coalescing timer for a range of + * consecutive CY instances. + * + *****************************************************************************/ +CpaStatus setCyInstanceCoalescingTimerForRange(Cpa32U coalescingTimerInNs, + Cpa16U startInst, + Cpa16U endInst); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyInstanceCoalescingTimer + * + *****************************************************************************/ +Cpa32U getCyInstanceCoalescingTimer(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * isCyInstanceCoalescingTimerConfigured + * + *****************************************************************************/ +CpaBoolean isCyInstanceCoalescingTimerConfigured(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * clearCyInstanceCoalescingTimerConfiguration + * + *****************************************************************************/ +CpaStatus clearCyInstanceCoalescingTimerConfiguration(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * setCyInstanceCoalescingTimerMask + * + *****************************************************************************/ +void setCyInstanceCoalescingTimerMask(Cpa64U mask); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyInstanceCoalescingTimerMask + * + *****************************************************************************/ +Cpa64U getCyInstanceCoalescingTimerMask(void); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * configureCyInstanceCoalescingTimerForAll + * + *****************************************************************************/ +CpaStatus configureCyInstanceCoalescingTimerForAll(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * configureCyInstanceCoalescingTimerForHalf + * + *****************************************************************************/ +CpaStatus configureCyInstanceCoalescingTimerForHalf(Cpa32U coalescingTimerInNs); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * getCyInstanceRxInterruptMetaData + * + * @description + * Wrapper around cpaInstanceGetRxInterruptMetaData() for CY instances. + * Resolves the correct service type for combined CRYPTO instances + * (queried via the SYM service type) and pure SYM/ASYM instances. + * + *****************************************************************************/ +CpaStatus getCyInstanceRxInterruptMetaData( + CpaInstanceHandle instanceHandle, + CpaRxInterruptMetaData *pInterruptData); + +/** + ***************************************************************************** + * @ingroup cryptoThreads + * applyCyInstanceCoalescingTimerConfiguration + * + * @description + * Applies the configured coalescing timer value to the actual CY + * instances based on the current mask. Each instance is queried via + * cpaCyInstanceGetInfo2() so that the correct accelerationServiceType + * (CRYPTO / CRYPTO_SYM / CRYPTO_ASYM) is passed to the experimental API. + * After setting the timer on each masked instance the value is read + * back via cpaInstanceGetRxInterruptMetaData() and verified (taking the + * hardware-reported granularity into account). This should be called + * after CY services are started but before polling threads are created. + * + *****************************************************************************/ +CpaStatus applyCyInstanceCoalescingTimerConfiguration(void); +#endif /* USER_SPACE && SUPPORTED_FEAT_INT_COALESCING_TIMER && STV_TEST_CODE \ + */ + #endif /*_CRYPTO_UTILS_H_*/ diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dh_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dh_perf.c index 5c42d878..2c036967 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dh_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dh_perf.c @@ -1203,10 +1203,10 @@ void dhPerformance(single_thread_test_data_t *testSetup) dhSetup.performanceStats = testSetup->performanceStats; /*get the instance handles so that we can start our thread on the selected * instance*/ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { - PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n", + PRINT_ERR("cpaGetNumInstances error, status:%d, numInstanaces:%d\n", status, numInstances); dhSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1219,7 +1219,9 @@ void dhPerformance(single_thread_test_data_t *testSetup) dhSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } - if (cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS) + if (cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + numInstances, + cyInstances) != CPA_STATUS_SUCCESS) { PRINT_ERR("Failed to get instances\n"); dhSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1345,7 +1347,7 @@ CpaStatus setupDhTest(Cpa32U modSizeInBits, return CPA_STATUS_FAIL; } /*start crypto service if not already started*/ - if (CPA_STATUS_SUCCESS != startCyServices()) + if (CPA_STATUS_SUCCESS != startAsymServices()) { PRINT_ERR("Error starting Crypto Services\n"); return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dsa_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dsa_perf.c index 8fedf4fd..0acb7d38 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dsa_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_dsa_perf.c @@ -1783,7 +1783,7 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, dsaSetup.syncMode = params->syncMode; /*get the instance handles so that we can start our thread on the selected * instance */ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { PRINT_ERR("Could not get any instances\n"); @@ -1807,7 +1807,7 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } - cpaCyGetInstances(numInstances, cyInstances); + cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, numInstances, cyInstances); /* give our thread a logical crypto instance to use * use % to wrap around the max number of instances */ dsaSetup.cyInstanceHandle = @@ -1947,10 +1947,10 @@ static CpaStatus setupDsaTestGen(Cpa32U pLenInBits, return CPA_STATUS_FAIL; } - /*start crypto service if not already started */ - if (CPA_STATUS_SUCCESS != startCyServices()) + /*start Asym service if not already started */ + if (CPA_STATUS_SUCCESS != startAsymServices()) { - PRINT_ERR("Error starting Crypto Services\n"); + PRINT_ERR("Error starting Asym Services\n"); return CPA_STATUS_FAIL; } if (iaCycleCount_g) diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ecdsa_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ecdsa_perf.c index e11760a8..e6d9953d 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ecdsa_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ecdsa_perf.c @@ -1659,6 +1659,145 @@ CpaStatus ecdsaPerform(ecdsa_test_params_t *setup) } EXPORT_SYMBOL(ecdsaPerform); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +/*************************************************************************** + * @ingroup cryptoThreads + * + * @description + * ECDSA performance function with response mode iteration support + * Alternates between polling and event-driven modes across iterations + ***************************************************************************/ +static CpaStatus qatecdsaDataWithIteration(ecdsa_test_params_t *setup) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U iterationCount; + Cpa32U i; + + CpaInstanceResponseMode originalMode; + CpaInstanceResponseMode currentMode; + CpaInstanceResponseMode alternateMode; + + /* Get iteration count */ + status = getCyResponseModeIterationCount(&iterationCount); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Cy response mode iteration count\n"); + return status; + } + + /* Store original response mode */ + originalMode = setup->currentResponseMode; + + /* Determine alternate mode */ + if (originalMode == CPA_INST_RX_NOTIFY_NONE) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + + PRINT("Starting ECDSA response mode iteration: count=%d, initial=%d, " + "alternate=%d\n", + iterationCount, + originalMode, + alternateMode); + + /* Perform iterations with alternating response modes */ + for (i = 0; i < iterationCount && status == CPA_STATUS_SUCCESS; i++) + { + if (i % 2 == 0) + { + /* Even iterations: use original mode */ + currentMode = originalMode; + } + else + { + /* Odd iterations: use alternate mode */ + currentMode = alternateMode; + } + + /* Update the test parameters with current mode */ + setup->currentResponseMode = currentMode; + + /* Get instance type to determine correct service type */ + CpaInstanceInfo2 instInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &instInfo); + if (CPA_STATUS_SUCCESS != infoStatus) + { + PRINT_ERR("Failed to get instance info on iteration %d\n", i); + status = infoStatus; + break; + } + + CpaStatus modeStatus = + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + instInfo.accelerationServiceType, + currentMode); + if (CPA_STATUS_SUCCESS != modeStatus) + { + PRINT_ERR( + "Failed to set response mode %d on iteration %d, status: %d\n", + currentMode, + i, + modeStatus); + /* Continue with existing mode rather than failing completely */ + } + + switch (setup->step) + { + case (ECDSA_STEP_SIGNRS): + status = ecdsaPerformOnlySign(setup); + break; + case (ECDSA_STEP_VERIFY): + status = ecdsaPerform(setup); + break; + case (ECDSA_STEP_POINT_MULTIPLY): + status = ecdsaPerformPointMultiply(setup); + break; + default: + PRINT_ERR("Function not supported for step %d\n", setup->step); + status = CPA_STATUS_FAIL; + break; + } + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("ECDSA performance test failed on iteration %d with " + "status: %d\n", + i, + status); + break; + } + } + + /* Restore original response mode */ + CpaInstanceInfo2 restoreInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &restoreInfo); + if (CPA_STATUS_SUCCESS == infoStatus) + { + CpaStatus restoreStatus = + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + restoreInfo.accelerationServiceType, + originalMode); + if (CPA_STATUS_SUCCESS != restoreStatus) + { + PRINT_ERR("Failed to restore original response mode %d after " + "iterations, status: %d\n", + originalMode, + restoreStatus); + } + } + + return status; +} +#endif /* defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) */ + /*************************************************************************** * @ingroup cryptoThreads * @@ -1670,8 +1809,6 @@ static CpaStatus ecdsaPrintStats(thread_creation_data_t *data) ecdsa_test_params_t *params = (ecdsa_test_params_t *)data->setupPtr; if (ECDSA_STEP_SIGNRS == params->step) { -#if CY_API_VERSION_AT_LEAST(3, 0) -#ifdef SC_KPT2_ENABLED if (CPA_TRUE == params->enableKPT) { PRINT("KPT2 ECDSA SIGNRS\n"); @@ -1680,12 +1817,6 @@ static CpaStatus ecdsaPrintStats(thread_creation_data_t *data) { PRINT("ECDSA SIGNRS\n"); } -#else - PRINT("ECDSA SIGNRS\n"); -#endif -#else - PRINT("ECDSA SIGNRS\n"); -#endif } else if (ECDSA_STEP_VERIFY == params->step) { @@ -1749,10 +1880,10 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) ecdsaSetup.performanceStats = testSetup->performanceStats; /*get the instance handles so that we can start our thread on the selected * instance*/ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { - PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n", + PRINT_ERR("cpaGetNumInstances error, status:%d, numInstances:%d\n", status, numInstances); ecdsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1765,7 +1896,9 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) ecdsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } - if (cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS) + if (cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + numInstances, + cyInstances) != CPA_STATUS_SUCCESS) { PRINT_ERR("Failed to get instances\n"); ecdsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1828,6 +1961,59 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) memset(ecdsaSetup.performanceStats, 0, sizeof(perf_data_t)); ecdsaSetup.performanceStats->packageId = instanceInfo->physInstId.packageId; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(ecdsaSetup.cyInstanceHandle, + CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + &ecdsaSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + ecdsaSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + } + /* Check if this instance has been explicitly configured with override + */ + if (isCyInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getCyInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + ecdsaSetup.currentResponseMode = getCyInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + ecdsaSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT( + "Using library default response mode %d for instance %d\n", + ecdsaSetup.currentResponseMode, + instanceIndex); + } + } + } + /* Print the final response mode for this thread */ + PRINT("Thread %u using CY instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + ecdsaSetup.currentResponseMode, + (ecdsaSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (ecdsaSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ ecdsaSetup.threadID = testSetup->threadID; @@ -1844,6 +2030,37 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) #endif /*launch function that does all the work*/ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Check if response mode iteration is enabled */ + Cpa32U iterCount = 0; + status = getCyResponseModeIterationCount(&iterCount); + PRINT("ECDSA iterCount = %d\n", iterCount); + + if (iterCount > 1) + { + status = qatecdsaDataWithIteration(&ecdsaSetup); + } + else + { + switch (params->step) + { + case (ECDSA_STEP_SIGNRS): + status = ecdsaPerformOnlySign(&ecdsaSetup); + break; + case (ECDSA_STEP_VERIFY): + status = ecdsaPerform(&ecdsaSetup); + break; + case (ECDSA_STEP_POINT_MULTIPLY): + status = ecdsaPerformPointMultiply(&ecdsaSetup); + break; + default: + PRINT_ERR("Function not supported for step %d\n", params->step); + status = CPA_STATUS_FAIL; + break; + } + } +#else switch (params->step) { case (ECDSA_STEP_VERIFY): @@ -1854,6 +2071,7 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) status = CPA_STATUS_FAIL; break; } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (CPA_STATUS_SUCCESS != status) { #if CY_API_VERSION_AT_LEAST(3, 0) @@ -1913,9 +2131,9 @@ CpaStatus setupEcdsaTest(Cpa32U nLenInBits, return CPA_STATUS_FAIL; } /*start crypto service if not already started*/ - if (CPA_STATUS_SUCCESS != startCyServices()) + if (CPA_STATUS_SUCCESS != startAsymServices()) { - PRINT_ERR("Error starting Crypto Services\n"); + PRINT_ERR("Error starting Asym Services\n"); return CPA_STATUS_FAIL; } if (iaCycleCount_g) @@ -1926,6 +2144,16 @@ CpaStatus setupEcdsaTest(Cpa32U nLenInBits, timeStampTime_g = getTimeStampTime(); PRINT("timeStampTime_g %llu\n", timeStampTime_g); } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyCyInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying Cy instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (!poll_inline_g) { /* start polling threads if polling is enabled in the configuration file diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_dsa_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_dsa_perf.c index e93c3e56..2f4bd73b 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_dsa_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_dsa_perf.c @@ -491,7 +491,7 @@ static CpaStatus genDsaPara(dsa_test_params_t *setup, CpaFlatBuffer **ppdsaS) { Cpa32U i = 0; - Cpa32U status = 0; + CpaStatus status = CPA_STATUS_SUCCESS; /*DSA parameters */ /*DSA P parameter, this shall be populated by the hard coded P at the top diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_rsa_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_rsa_perf.c index 17312a36..66f8041c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_rsa_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_rsa_perf.c @@ -1162,13 +1162,9 @@ CpaStatus sampleRsaEncrypt(asym_test_params_t *setup, return status; } -/****************************************************************************** - * @ingroup sampleRSACode - * - * @description - * This functions performs RSA Encrypt using openssl library - * - * ****************************************************************************/ +#ifdef SC_KPT2_ENABLED +#endif + /****************************************************************************** * @ingroup sampleRSACode * @@ -1700,6 +1696,136 @@ EXPORT_SYMBOL(sampleRsaDecrypt); static CpaStatus sampleRsaEncryptPerform(asym_test_params_t *setup); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +static CpaStatus qatrsaDataWithIteration(asym_test_params_t *setup, + CpaBoolean performEncrypt) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U iterCount = 0; + Cpa32U iterNo = 0; + CpaInstanceResponseMode originalMode = CPA_INST_RX_NOTIFY_NONE; + CpaInstanceResponseMode alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + CpaInstanceInfo2 instanceInfo = { 0 }; + + /* Get the iteration count */ + if (CPA_STATUS_SUCCESS != getCyResponseModeIterationCount(&iterCount)) + { + PRINT_ERR("Failed to get iteration count\n"); + return CPA_STATUS_FAIL; + } + if (0 == iterCount) + { + PRINT_ERR("Invalid iteration count\n"); + return CPA_STATUS_FAIL; + } + + /* Get the current response mode from the instance */ + status = cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &instanceInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get instance info\n"); + return CPA_STATUS_FAIL; + } + + /* Determine original mode based on instance polling state */ + if (instanceInfo.isPolled) + { + originalMode = CPA_INST_RX_NOTIFY_NONE; + } + else + { + originalMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + + PRINT("Response mode iteration: starting with %s mode, %u iterations\n", + (originalMode == CPA_INST_RX_NOTIFY_NONE) ? "POLLING" : "EVENT", + iterCount); + + /* Determine the alternate mode */ + if (CPA_INST_RX_NOTIFY_NONE == originalMode) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + + /* Loop through iterations */ + for (iterNo = 0; iterNo < iterCount; iterNo++) + { + CpaInstanceResponseMode modeToSet; + + /* Set the response mode for this iteration */ + if (iterNo % 2 == 0) + { + /* Even iteration: use original mode */ + modeToSet = originalMode; + } + else + { + /* Odd iteration: use alternate mode */ + modeToSet = alternateMode; + } + + /* Get instance type to determine correct service type */ + CpaInstanceInfo2 instInfo = { 0 }; + status = cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &instInfo); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get instance info on iteration %u\n", iterNo); + break; + } + + status = cpaInstanceSetResponseMode(setup->cyInstanceHandle, + instInfo.accelerationServiceType, + modeToSet); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "Failed to set response mode for iteration %u (status=%d)\n", + iterNo, + status); + break; + } + + /* Perform the appropriate RSA operation */ + if (performEncrypt) + { + status = sampleRsaEncryptPerform(setup); + } + else + { + status = sampleRsaPerform(setup); + } + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("RSA operation failed in iteration %u\n", iterNo); + break; + } + } + + /* Restore the original response mode */ + PRINT("Restoring original response mode: %s\n", + (originalMode == CPA_INST_RX_NOTIFY_NONE) ? "POLLING" : "EVENT"); + + CpaInstanceInfo2 restoreInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &restoreInfo); + if (CPA_STATUS_SUCCESS == infoStatus) + { + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + restoreInfo.accelerationServiceType, + originalMode); + } + + return status; +} +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + /****************************************************************************** * @ingroup sampleRSACode * @@ -1948,10 +2074,10 @@ void sampleRsaThreadSetup(single_thread_test_data_t *testSetup) rsaTestSetup.performanceStats = testSetup->performanceStats; /*get the instance handles so that we can start our thread on the selected * instance*/ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { - PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n", + PRINT_ERR("cpaGetNumInstances error, status:%d, numInstanaces:%d\n", status, numInstances); rsaTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1964,7 +2090,9 @@ void sampleRsaThreadSetup(single_thread_test_data_t *testSetup) rsaTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; return; } - if (cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS) + if (cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + numInstances, + cyInstances) != CPA_STATUS_SUCCESS) { PRINT_ERR("Failed to get instances\n"); rsaTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -2016,6 +2144,59 @@ void sampleRsaThreadSetup(single_thread_test_data_t *testSetup) { packageIdCount_g = instanceInfo->physInstId.packageId; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(rsaTestSetup.cyInstanceHandle, + CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + &rsaTestSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + rsaTestSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + } + /* Check if this instance has been explicitly configured with override + */ + if (isCyInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getCyInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + rsaTestSetup.currentResponseMode = getCyInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + rsaTestSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT( + "Using library default response mode %d for instance %d\n", + rsaTestSetup.currentResponseMode, + instanceIndex); + } + } + } + /* Print the final response mode for this thread */ + PRINT("Thread %u using CY instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + rsaTestSetup.currentResponseMode, + (rsaTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (rsaTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ rsaTestSetup.modulusSizeInBytes = testSetup->packetSize; rsaTestSetup.rsaKeyRepType = params->rsaKeyRepType; rsaTestSetup.numBuffers = params->numBuffers; @@ -2027,16 +2208,41 @@ void sampleRsaThreadSetup(single_thread_test_data_t *testSetup) rsaTestSetup.enableKPT = params->enableKPT; #endif #endif +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Initialize response mode to polling mode as default */ + rsaTestSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ /*launch function that does all the work*/ if (params->performEncrypt) { +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + Cpa32U iterCount = 0; + if (CPA_STATUS_SUCCESS == getCyResponseModeIterationCount(&iterCount) && + iterCount > 1) + { + status = qatrsaDataWithIteration(&rsaTestSetup, CPA_TRUE); + } + else +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ { status = sampleRsaEncryptPerform(&rsaTestSetup); } } else { +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + Cpa32U iterCount = 0; + if (CPA_STATUS_SUCCESS == getCyResponseModeIterationCount(&iterCount) && + iterCount > 1) + { + status = qatrsaDataWithIteration(&rsaTestSetup, CPA_FALSE); + } + else +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ { status = sampleRsaPerform(&rsaTestSetup); } @@ -2091,8 +2297,6 @@ CpaStatus printRsaCrtPerfData(thread_creation_data_t *data) } else { -#if CY_API_VERSION_AT_LEAST(3, 0) -#ifdef SC_KPT2_ENABLED if (CPA_TRUE == params->enableKPT) { PRINT("KPT RSA CRT DECRYPT\n"); @@ -2101,12 +2305,6 @@ CpaStatus printRsaCrtPerfData(thread_creation_data_t *data) { PRINT("RSA CRT DECRYPT\n"); } -#else - PRINT("RSA CRT DECRYPT\n"); -#endif -#else - PRINT("RSA CRT DECRYPT\n"); -#endif } PRINT("Modulus Size %19u\n", data->packetSize * NUM_BITS_IN_BYTE); return (printAsymStatsAndStopServices(data)); @@ -2122,8 +2320,6 @@ CpaStatus printRsaCrtPerfData(thread_creation_data_t *data) *****************************************************************************/ CpaStatus printRsaPerfData(thread_creation_data_t *data) { -#if CY_API_VERSION_AT_LEAST(3, 0) -#ifdef SC_KPT2_ENABLED asym_test_params_t *params = (asym_test_params_t *)data->setupPtr; if (CPA_TRUE == params->enableKPT) { @@ -2133,12 +2329,6 @@ CpaStatus printRsaPerfData(thread_creation_data_t *data) { PRINT("RSA DECRYPT\n"); } -#else - PRINT("RSA DECRYPT\n"); -#endif -#else - PRINT("RSA DECRYPT\n"); -#endif PRINT("Modulus Size %19u\n", data->packetSize * NUM_BITS_IN_BYTE); return (printAsymStatsAndStopServices(data)); } @@ -2174,10 +2364,10 @@ CpaStatus setupRsaTest(Cpa32U modulusSize, PRINT_ERR(" Max is %d\n", MAX_THREAD_VARIATION); return CPA_STATUS_FAIL; } - /*start crypto service if not already started*/ - if (CPA_STATUS_SUCCESS != startCyServices()) + /*start Asym service if not already started*/ + if (CPA_STATUS_SUCCESS != startAsymServices()) { - PRINT_ERR("Error starting Crypto Services\n"); + PRINT_ERR("Error starting Asym Service\n"); return CPA_STATUS_FAIL; } if (iaCycleCount_g) @@ -2188,6 +2378,16 @@ CpaStatus setupRsaTest(Cpa32U modulusSize, timeStampTime_g = getTimeStampTime(); PRINT("timeStampTime_g %llu\n", timeStampTime_g); } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyCyInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying Cy instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (!poll_inline_g) { /* start polling threads if polling is enabled in the configuration diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sm2_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sm2_perf.c index 5a9ed1d1..57dd91f1 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sm2_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sm2_perf.c @@ -589,6 +589,59 @@ void sm2Performance(single_thread_test_data_t *testSetup) { packageIdCount_g = instanceInfo.physInstId.packageId; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(sm2Setup.cyInstanceHandle, + CPA_ACC_SVC_TYPE_CRYPTO_ASYM, + &sm2Setup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + sm2Setup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + } + + /* Check if this instance has been explicitly configured with override + */ + if (isCyInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getCyInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + sm2Setup.currentResponseMode = getCyInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + sm2Setup.currentResponseMode, + instanceIndex); + } + else + { + PRINT( + "Using library default response mode %d for instance %d\n", + sm2Setup.currentResponseMode, + instanceIndex); + } + } + } + /* Print the final response mode for this thread */ + PRINT("Thread %u using CY instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + sm2Setup.currentResponseMode, + (sm2Setup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) ? "polling" + : (sm2Setup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ sm2Setup.nLenInBytes = params->nLenInBytes; sm2Setup.fieldType = params->fieldType; @@ -691,6 +744,16 @@ CpaStatus setupSm2Test(Cpa32U nLenInBits, timeStampTime_g = getTimeStampTime(); PRINT("timeStampTime_g %llu\n", timeStampTime_g); } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyCyInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying Cy instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (!poll_inline_g) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf.c index 9f2b8a8a..f570ac38 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf.c @@ -255,6 +255,24 @@ static CpaStatus symmetricSetupSession(CpaCySymCbFunc pSymCb, setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = KEY_SIZE_128_IN_BYTES; } + else if (CPA_CY_SYM_CIPHER_AES_GCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + gcmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_AES_CCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + ccmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_CHACHA == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + chachaPolyAadLenInBytes_g; + } else { setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = 0; @@ -432,15 +450,17 @@ static CpaStatus symmetricPerformOpDataSetup(CpaCySymSessionCtx pSessionCtx, return CPA_STATUS_FAIL; } memset(pOpdata[createCount]->pAdditionalAuthData, - 0xAA, + AAD_INIT_PATTERN, KEY_SIZE_128_IN_BYTES); } - else if (((setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_AES_CCM) || - (setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_AES_GCM)) && - (setup->setupData.hashSetupData.hashAlgorithm != - CPA_CY_SYM_HASH_AES_GMAC)) + else if ((((setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_AES_CCM) || + (setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_AES_GCM)) && + (setup->setupData.hashSetupData.hashAlgorithm != + CPA_CY_SYM_HASH_AES_GMAC)) || + (setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_CHACHA)) { /*must allocate to the nearest block size required (above 18 bytes)*/ @@ -471,20 +491,10 @@ static CpaStatus symmetricPerformOpDataSetup(CpaCySymSessionCtx pSessionCtx, #endif case CPA_CY_SYM_CIPHER_SM4_ECB: case CPA_CY_SYM_CIPHER_SM4_CBC: + case CPA_CY_SYM_CIPHER_SM4_CTR: - if (setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_ZUC_EEA3 && - setup->setupData.cipherSetupData.cipherKeyLenInBytes == - KEY_SIZE_256_IN_BYTES) - { - pOpdata[createCount]->ivLenInBytes = - IV_LEN_FOR_24_BYTE_BLOCK_CIPHER; - } - else - { - pOpdata[createCount]->ivLenInBytes = - IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; - } + pOpdata[createCount]->ivLenInBytes = + IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; /* If 0 use default else use value passed. */ if (0 != setup->ivLength) { @@ -1280,6 +1290,110 @@ CpaStatus sampleSymmetricPerform(symmetric_test_params_t *setup) return status; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +static CpaStatus qatsymDataWithIteration(symmetric_test_params_t *setup) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U iterationCount; + Cpa32U i; + + CpaInstanceResponseMode originalMode; + CpaInstanceResponseMode currentMode; + CpaInstanceResponseMode alternateMode; + /* Get iteration count */ + status = getCyResponseModeIterationCount(&iterationCount); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Cy response mode iteration count\n"); + return status; + } + /* Store original response mode */ + originalMode = setup->currentResponseMode; + /* Determine alternate mode */ + if (originalMode == CPA_INST_RX_NOTIFY_NONE) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + PRINT("Starting response mode iteration: count=%d, initial=%d, " + "alternate=%d\n", + iterationCount, + originalMode, + alternateMode); + /* Perform iterations with alternating response modes */ + for (i = 0; i < iterationCount && status == CPA_STATUS_SUCCESS; i++) + { + if (i % 2 == 0) + { + /* Even iterations: use original mode */ + currentMode = originalMode; + } + else + { + /* Odd iterations: use alternate mode */ + currentMode = alternateMode; + } + /* Update the test parameters with current mode */ + setup->currentResponseMode = currentMode; + /* Get instance type to determine correct service type */ + CpaInstanceInfo2 instInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &instInfo); + if (CPA_STATUS_SUCCESS != infoStatus) + { + PRINT_ERR("Failed to get instance info on iteration %d\n", i); + status = infoStatus; + break; + } + CpaStatus modeStatus = + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + instInfo.accelerationServiceType, + currentMode); + if (CPA_STATUS_SUCCESS != modeStatus) + { + PRINT_ERR( + "Failed to set response mode %d on iteration %d, status: %d\n", + currentMode, + i, + modeStatus); + /* Continue with existing mode rather than failing completely */ + } + status = sampleSymmetricPerform(setup); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Symmetric performance test failed on iteration %d with " + "status: %d\n", + i, + status); + break; + } + } + /* Restore original response mode */ + CpaInstanceInfo2 restoreInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &restoreInfo); + if (CPA_STATUS_SUCCESS == infoStatus) + { + CpaStatus restoreStatus = + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + restoreInfo.accelerationServiceType, + originalMode); + if (CPA_STATUS_SUCCESS != restoreStatus) + { + PRINT_ERR("Failed to restore original response mode %d after " + "iterations, status: %d\n", + originalMode, + restoreStatus); + } + } + return status; +} +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + /** ***************************************************************************** * @ingroup sampleSymmetricPerf @@ -1328,10 +1442,10 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) symTestSetup.performanceStats = testSetup->performanceStats; /*get the instance handles so that we can start our thread on the selected * instance*/ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { - PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n", + PRINT_ERR("cpaGetNumInstances error, status:%d, numInstances:%d\n", status, numInstances); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -1344,20 +1458,14 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; return; } - if (cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS) + if (cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, + numInstances, + cyInstances) != CPA_STATUS_SUCCESS) { PRINT_ERR("Failed to get instances\n"); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; goto exit; } - if (testSetup->logicalQaInstance > numInstances) - { - PRINT_ERR("%u is Invalid Logical QA Instance, max is: %u\n", - testSetup->logicalQaInstance, - numInstances); - symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; - goto exit; - } #if defined(SC_WITH_QAT22) while (testSetup->logicalQaInstance < numInstances) @@ -1397,6 +1505,61 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) { packageIdCount_g = instanceInfo->physInstId.packageId; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(symTestSetup.cyInstanceHandle, + CPA_ACC_SVC_TYPE_CRYPTO_SYM, + &symTestSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + symTestSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + } + + /* Check if this instance has been explicitly configured with override + */ + if (isCyInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getCyInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + symTestSetup.currentResponseMode = getCyInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + symTestSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT( + "Using library default response mode %d for instance %d\n", + symTestSetup.currentResponseMode, + instanceIndex); + } + } + } + + /* Print the final response mode for this thread */ + PRINT("Thread %u using CY instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + symTestSetup.currentResponseMode, + (symTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (symTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ pPacketSize = qaeMemAlloc(sizeof(Cpa32U) * pSetup->numBuffLists); if (NULL == pPacketSize) @@ -1476,9 +1639,12 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) if (CPA_TRUE != checkCapability(cyInstances[testSetup->logicalQaInstance], &symTestSetup)) { - PRINT("\nThread %u Invalid test.Capability check failed for the " - "requested algorithm on the configured instance\n", - testSetup->threadID); + if (verboseOutput) + { + PRINT("\nThread %u Invalid test.Capability check failed for the " + "requested algorithm on the configured instance\n", + testSetup->threadID); + } testSetup->statsPrintFunc = (stats_print_func_t)printSymmetricPerfDataAndStopCyService; symTestSetup.performanceStats->threadReturnStatus = @@ -1488,6 +1654,24 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) goto exit; } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Check if response mode iteration is enabled */ + Cpa32U iterCount = 0; + status = getCyResponseModeIterationCount(&iterCount); + PRINT("iterCount = %d\n", iterCount); + if (iterCount > 1) + { + status = qatsymDataWithIteration(&symTestSetup); + if (CPA_STATUS_SUCCESS != status) + { + printSymTestType(&symTestSetup); + PRINT("Test %u FAILED\n", testSetup->threadID); + symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; + } + } + else + { status = sampleSymmetricPerform(&symTestSetup); if (CPA_STATUS_SUCCESS != status) { @@ -1495,6 +1679,8 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) PRINT("Test %u FAILED\n", testSetup->threadID); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; } + } +#else /*launch function that does all the work*/ status = sampleSymmetricPerform(&symTestSetup); if (CPA_STATUS_SUCCESS != status) @@ -1503,15 +1689,16 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) PRINT("Test %u FAILED\n", testSetup->threadID); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; } - else +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ + if (CPA_STATUS_SUCCESS == status && + symTestSetup.performanceStats->threadReturnStatus != CPA_STATUS_FAIL) { /*set the print function that can be used to print stats at the end of * the test*/ testSetup->statsPrintFunc = (stats_print_func_t)printSymmetricPerfDataAndStopCyService; } - if ((CPA_STATUS_SUCCESS != status) || - (symTestSetup.performanceStats->threadReturnStatus == CPA_STATUS_FAIL)) + else { /* Stop Cy Service function should be called after all threads * complete their execution. This function will be called from @@ -1590,7 +1777,7 @@ CpaStatus setupSymmetricTest(CpaCySymOp opType, } /*start crypto service if not already started*/ - if (CPA_STATUS_SUCCESS != startCyServices()) + if (CPA_STATUS_SUCCESS != startSymServices()) { PRINT_ERR("Failed to start Crypto services\n"); return CPA_STATUS_FAIL; @@ -1601,6 +1788,16 @@ CpaStatus setupSymmetricTest(CpaCySymOp opType, enablePollInline(); #endif } +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Apply any configured response mode overrides before creating polling + * threads */ + if (CPA_STATUS_SUCCESS != applyCyInstanceResponseModeConfiguration()) + { + PRINT_ERR("Error applying Cy instance response mode configuration\n"); + return CPA_STATUS_FAIL; + } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ if (!poll_inline_g) { @@ -1670,6 +1867,11 @@ CpaStatus setupSymmetricTest(CpaCySymOp opType, } } } + if ((CPA_CY_SYM_CIPHER_ZUC_EEA3 == cipherAlg) && + (KEY_SIZE_256_IN_BYTES == cipherKeyLengthInBytes)) + { + symmetricSetup->ivLength = IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; + } // check which kind of hash mode is selected if (CPA_CY_SYM_HASH_MODE_NESTED == hashMode) @@ -1761,6 +1963,13 @@ CpaStatus setupSymmetricTest(CpaCySymOp opType, } symmetricSetup->digestAppend = digestAppend; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Initialize response mode to library default (will be queried per-thread) + */ + symmetricSetup->currentResponseMode = + CPA_INST_RX_NOTIFY_NONE; /* Fallback value */ +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ return CPA_STATUS_SUCCESS; } diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf_dp.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf_dp.c index f7624779..d5e1fd60 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf_dp.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_perf_dp.c @@ -591,9 +591,26 @@ static CpaStatus symmetricDpSetupSession(CpaCySymDpCbFunc pSymCb, setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = KEY_SIZE_128_IN_BYTES; } + else if (CPA_CY_SYM_CIPHER_AES_GCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + gcmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_AES_CCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + ccmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_CHACHA == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = + chachaPolyAadLenInBytes_g; + } else { - /* For AES-CCM, AAD(additional auth data) is optional.*/ setup->setupData.hashSetupData.authModeSetupData.aadLenInBytes = 0; } @@ -798,8 +815,14 @@ static CpaStatus symmetricDpPerformOpDataSetup( SYM_AUTH_INIT_VALUE, KEY_SIZE_128_IN_BYTES); } /*End of if(CPA_CY_SYM_HASH_SNOW3G_UIA2 == ... */ - else if (setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_AES_CCM) + else if ((((setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_AES_CCM) || + (setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_AES_GCM)) && + (setup->setupData.hashSetupData.hashAlgorithm != + CPA_CY_SYM_HASH_AES_GMAC)) || + (setup->setupData.cipherSetupData.cipherAlgorithm == + CPA_CY_SYM_CIPHER_CHACHA)) { /*must allocate to the nearest block size required (above 18 bytes)*/ @@ -815,7 +838,7 @@ static CpaStatus symmetricDpPerformOpDataSetup( memset(pOpdata[createCount]->pAdditionalAuthData, 0, AES_CCM_MIN_AAD_ALLOC_LENGTH); - } /* End of else if(setup->setupData.cipherSetupData.cipherAlgorithm .*/ + } /* in this code we always allocate the IV, but it is not always used * this reduces the if/else logic when trying to cater for as many @@ -841,21 +864,12 @@ static CpaStatus symmetricDpPerformOpDataSetup( || setup->setupData.cipherSetupData.cipherAlgorithm == CPA_CY_SYM_CIPHER_SM4_CBC || setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_SM4_CTR) + CPA_CY_SYM_CIPHER_SM4_CTR + ) { - if (setup->setupData.cipherSetupData.cipherAlgorithm == - CPA_CY_SYM_CIPHER_ZUC_EEA3 && - setup->setupData.cipherSetupData.cipherKeyLenInBytes == - KEY_SIZE_256_IN_BYTES) - { - pOpdata[createCount]->ivLenInBytes = - IV_LEN_FOR_24_BYTE_BLOCK_CIPHER; - } - else - { - pOpdata[createCount]->ivLenInBytes = - IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; - } + pOpdata[createCount]->ivLenInBytes = + IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; + /* If 0 use default else use value passed. */ if (0 != setup->ivLength) { @@ -1233,7 +1247,8 @@ static CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, */ if ((insideLoopCount % maxRequestNum == 0) || ((insideLoopCount == setup->numBuffLists - 1) && - (outsideLoopCount == numOfLoops - 1))) + (outsideLoopCount == numOfLoops - 1)) + ) { performNowFlag = CPA_TRUE; } @@ -2244,10 +2259,10 @@ void sampleSymmetricDpPerformance(single_thread_test_data_t *testSetup) symTestSetup.performanceStats = testSetup->performanceStats; /*get the instance handles so that we can start our thread on the selected * instance*/ - status = cpaCyGetNumInstances(&numInstances); + status = cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, &numInstances); if (CPA_STATUS_SUCCESS != status || numInstances == 0) { - PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n", + PRINT_ERR("cpaGetNumInstances error, status:%d, numInstanaces:%d\n", status, numInstances); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; @@ -2260,20 +2275,14 @@ void sampleSymmetricDpPerformance(single_thread_test_data_t *testSetup) symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; return; } - if (cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS) + if (cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, + numInstances, + cyInstances) != CPA_STATUS_SUCCESS) { PRINT_ERR("Failed to get instances\n"); symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; goto exit; } - if (testSetup->logicalQaInstance > numInstances) - { - PRINT_ERR("%u is Invalid Logical QA Instance, max is: %u\n", - testSetup->logicalQaInstance, - numInstances); - symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; - goto exit; - } /* give our thread a logical crypto instance to use*/ symTestSetup.cyInstanceHandle = cyInstances[testSetup->logicalQaInstance]; @@ -2399,9 +2408,12 @@ void sampleSymmetricDpPerformance(single_thread_test_data_t *testSetup) if (CPA_TRUE != checkCapability(cyInstances[testSetup->logicalQaInstance], &symTestSetup)) { - PRINT("\nThread %u Invalid test.Capability check failed for the " - "requested algorithm on the configured instance\n", - testSetup->threadID); + if (verboseOutput) + { + PRINT("\nThread %u Invalid test.Capability check failed for the " + "requested algorithm on the configured instance\n", + testSetup->threadID); + } testSetup->statsPrintFunc = (stats_print_func_t)printSymmetricPerfDataAndStopCyService; symTestSetup.performanceStats->threadReturnStatus = @@ -2509,10 +2521,10 @@ CpaStatus setupSymmetricDpTest( return CPA_STATUS_FAIL; } - /*start crypto service if not already started*/ - if (CPA_STATUS_SUCCESS != startCyServices()) + /*start Sym service if not already started*/ + if (CPA_STATUS_SUCCESS != startSymServices()) { - PRINT_ERR("Failed to start Crypto services\n"); + PRINT_ERR("Failed to start Sym service\n"); return CPA_STATUS_FAIL; } @@ -2583,6 +2595,11 @@ CpaStatus setupSymmetricDpTest( symmetricSetup->ivLength = CPA_CIPHER_SPC_IV_SIZE; } } + if ((CPA_CY_SYM_CIPHER_ZUC_EEA3 == cipherAlg) && + (KEY_SIZE_256_IN_BYTES == cipherKeyLengthInBytes)) + { + symmetricSetup->ivLength = IV_LEN_FOR_16_BYTE_BLOCK_CIPHER; + } if (((hashAlg == CPA_CY_SYM_HASH_KASUMI_F9) || (hashAlg == CPA_CY_SYM_HASH_SNOW3G_UIA2)) && diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_main.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_main.c index 913c7bbb..7b66db95 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_main.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_main.c @@ -34,6 +34,171 @@ CpaStatus cipherNewPerformanceTest(CpaBoolean mode, Cpa32U numLoops); void qatSymmetricPerformance(single_thread_test_data_t *testSetup); +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +static CpaStatus qatsymDataWithIteration(symmetric_test_params_t *setup, + CpaCySymOpData *encryptOpData, + CpaCySymOpData *decryptOpData, + CpaBufferList *srcBufferListArray) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + Cpa32U iterationCount; + Cpa32U i; + Cpa32U numLoops; + + CpaInstanceResponseMode originalMode; + CpaInstanceResponseMode currentMode; + CpaInstanceResponseMode alternateMode; + + /* Get iteration count */ + status = getCyResponseModeIterationCount(&iterationCount); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Cy response mode iteration count\n"); + return status; + } + + /* Store original response mode */ + originalMode = setup->currentResponseMode; + /* Determine alternate mode */ + if (originalMode == CPA_INST_RX_NOTIFY_NONE) + { + alternateMode = CPA_INST_RX_NOTIFY_BY_EVENT; + } + else + { + alternateMode = CPA_INST_RX_NOTIFY_NONE; + } + PRINT("Starting response mode iteration: count=%d, initial=%d, " + "alternate=%d\n", + iterationCount, + originalMode, + alternateMode); + /* Perform iterations with alternating response modes */ + for (i = 0; i < iterationCount && status == CPA_STATUS_SUCCESS; i++) + { + if (i % 2 == 0) + { + /* Even iterations: use original mode */ + currentMode = originalMode; + } + else + { + /* Odd iterations: use alternate mode */ + currentMode = alternateMode; + } + /* Update the test parameters with current mode */ + setup->currentResponseMode = currentMode; + /* Get instance type to determine correct service type */ + CpaInstanceInfo2 instInfo = { 0 }; + CpaStatus infoStatus = + cpaCyInstanceGetInfo2(setup->cyInstanceHandle, &instInfo); + if (CPA_STATUS_SUCCESS != infoStatus) + { + PRINT_ERR("Failed to get instance info on iteration %d\n", i); + status = infoStatus; + break; + } + CpaStatus modeStatus = + cpaInstanceSetResponseMode(setup->cyInstanceHandle, + instInfo.accelerationServiceType, + currentMode); + if (CPA_STATUS_SUCCESS != modeStatus) + { + PRINT_ERR( + "Failed to set response mode %d on iteration %d, status: %d\n", + currentMode, + i, + modeStatus); + /* Continue with existing mode rather than failing completely */ + } + if (setup->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT && + reliability_g == CPA_FALSE) + { + status = qatSymPerform(setup, encryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "qatSymPerform for encryptOpData returned status %d\n", + status); + } + } + else if (setup->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT && + reliability_g == CPA_FALSE) + { + /*copy numLoops, set setup->numLoops to 1 to compress data, then + * restore setup->numLoops to measure decompress performance*/ + numLoops = setup->numLoops; + setup->numLoops = 1; + + status = qatSymPerform(setup, encryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS == status) + { + /*restore setup->NumLoops*/ + setup->numLoops = numLoops; + status = + qatSymPerform(setup, decryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "qatSymPerform for decryptOpData returned status %d\n", + status); + } + } + } + else if (setup->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT && + reliability_g == CPA_TRUE) + { + /*copy numLoops, set setup->numLoops to 1 to do repeated + * compress-swdecompress for numLoops times*/ + numLoops = setup->numLoops; + setup->numLoops = 1; + for (i = 0; i < numLoops; i++) + { + status = + qatSymPerform(setup, encryptOpData, srcBufferListArray); + + // now i need to decrypt + if (CPA_STATUS_SUCCESS == status) + { + status = + qatSymPerform(setup, decryptOpData, srcBufferListArray); + + if (CPA_STATUS_SUCCESS == status) + { + /*3rd param is compression setup struct, need to + resolve status = qatCmpBuffers(srcBufferListArray, + copyBufferListArray, + setup);*/ + } + } + if (CPA_STATUS_SUCCESS != status) + { + break; + } + } + } + } + /* Restore original mode on both instance and test parameters */ + setup->currentResponseMode = originalMode; + + CpaStatus restoreStatus = cpaInstanceSetResponseMode( + setup->cyInstanceHandle, CPA_ACC_SVC_TYPE_CRYPTO, originalMode); + if (CPA_STATUS_SUCCESS != restoreStatus) + { + PRINT_ERR("Failed to restore original response mode %d after " + "iterations, status: %d\n", + originalMode, + restoreStatus); + /* Log error but don't fail the overall operation */ + } + return status; +} + +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ /*allocates buffers store a file for compression. The buffers are sent to * hardware, performance is recorded and stored in the setup parameter @@ -145,6 +310,103 @@ static CpaStatus scSymPoc(symmetric_test_params_t *setup_sym) // encrypt or decrypt the data if (CPA_STATUS_SUCCESS == status) { +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Check if response mode iteration is enabled */ + Cpa32U iterCount = 0; + status = getCyResponseModeIterationCount(&iterCount); + PRINT("iterCount = %d\n", iterCount); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Failed to get Cy response mode iteration count in " + "qatSymPerform\n"); + return status; + } + if (iterCount > 1) + { + qatsymDataWithIteration( + setup_sym, encryptOpData, decryptOpData, srcBufferListArray); + } + else + { + if (setup_sym->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT && + reliability_g == CPA_FALSE) + { + status = + qatSymPerform(setup_sym, encryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "qatSymPerform for encryptOpData returned status %d\n", + status); + } + } + + else if (setup_sym->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_DECRYPT && + reliability_g == CPA_FALSE) + { + /*copy numLoops, set setup->numLoops to 1 to compress data, then + * restore setup->numLoops to measure decompress performance*/ + numLoops = setup_sym->numLoops; + setup_sym->numLoops = 1; + + status = + qatSymPerform(setup_sym, encryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS == status) + { + /*restore setup->NumLoops*/ + setup_sym->numLoops = numLoops; + status = qatSymPerform( + setup_sym, decryptOpData, srcBufferListArray); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("qatSymPerform for decryptOpData returned " + "status %d\n", + status); + } + } + } + + else if (setup_sym->setupData.cipherSetupData.cipherDirection == + CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT && + reliability_g == CPA_TRUE) + { + + /*copy numLoops, set setup->numLoops to 1 to do repeated + * compress-swdecompress for numLoops times*/ + numLoops = setup_sym->numLoops; + setup_sym->numLoops = 1; + for (i = 0; i < numLoops; i++) + { + + status = qatSymPerform( + setup_sym, encryptOpData, srcBufferListArray); + + // now i need to decrypt + + if (CPA_STATUS_SUCCESS == status) + { + status = qatSymPerform( + setup_sym, decryptOpData, srcBufferListArray); + + if (CPA_STATUS_SUCCESS == status) + { + /*3rd param is compression setup struct, need to + resolve status = qatCmpBuffers(srcBufferListArray, + copyBufferListArray, + setup_sym);*/ + } + } + if (CPA_STATUS_SUCCESS != status) + { + break; + } + } + } + } +#else // USER_SPACE && SUPPORTED_FEAT_EPOLL not active if (setup_sym->setupData.cipherSetupData.cipherDirection == CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT && reliability_g == CPA_FALSE) @@ -192,7 +454,8 @@ static CpaStatus scSymPoc(symmetric_test_params_t *setup_sym) /*copy numLoops, set setup->numLoops to 1 to do repeated * compress-swdecompress for numLoops times*/ - PRINT("Starting repeated compress-decompress for %d times\n", setup_sym->numLoops); + PRINT("Starting repeated compress-decompress for %d times\n", + setup_sym->numLoops); numLoops = setup_sym->numLoops; setup_sym->numLoops = 1; for (i = 0; i < numLoops; i++) @@ -222,6 +485,7 @@ static CpaStatus scSymPoc(symmetric_test_params_t *setup_sym) } } } +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ } // SYMMETRIC @@ -449,7 +713,66 @@ void qatSymmetricPerformance(single_thread_test_data_t *testSetup) symTestSetup.isDpApi = pSetup->isDpApi; symTestSetup.cryptoSrcOffset = pSetup->cryptoSrcOffset; symTestSetup.digestAppend = pSetup->digestAppend; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + /* Determine the response mode for this instance */ + Cpa16U instanceIndex = (testSetup->logicalQaInstance) % numInstances; + { + CpaStatus responseStatus; + + /* First get the actual default response mode from the instance */ + responseStatus = + cpaInstanceGetResponseMode(symTestSetup.cyInstanceHandle, + CPA_ACC_SVC_TYPE_CRYPTO_SYM, + &symTestSetup.currentResponseMode); + if (CPA_STATUS_SUCCESS != responseStatus) + { + /* Fallback to assumed default if query fails */ + symTestSetup.currentResponseMode = CPA_INST_RX_NOTIFY_NONE; + PRINT( + "Failed to query instance response mode, using fallback: %d\n", + responseStatus); + } + + /* Check if this instance has been explicitly configured with override + */ + if (isCyInstanceResponseModeConfigured()) + { + Cpa64U instanceMask = getCyInstanceResponseModeMask(); + + /* Check if this instance is in the configured mask */ + if ((instanceIndex < 64) && + (instanceMask & (1ULL << instanceIndex))) + { + /* Override with explicitly configured mode */ + symTestSetup.currentResponseMode = getCyInstanceResponseMode(); + PRINT("Using explicit response mode %d for instance %d\n", + symTestSetup.currentResponseMode, + instanceIndex); + } + else + { + PRINT( + "Using library default response mode %d for instance %d\n", + symTestSetup.currentResponseMode, + instanceIndex); + } + } + } + + /* Print the final response mode for this thread */ + PRINT("Thread %u using sym instance %u with response mode: %d (%s)\n", + testSetup->threadID, + instanceIndex, + symTestSetup.currentResponseMode, + (symTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_NONE) + ? "polling" + : (symTestSetup.currentResponseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + ? "event" + : "unknown"); +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ /*launch function that does all the work*/ + if (CPA_TRUE != checkCapability(cyInstances[testSetup->logicalQaInstance], &symTestSetup)) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_utils.c index 9250469b..7cb3772c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/qat_sym_utils.c @@ -253,6 +253,21 @@ CpaStatus qatSymSessionInit(symmetric_test_params_t *setup, { authModeSetupData->aadLenInBytes = KEY_SIZE_128_IN_BYTES; } + else if (CPA_CY_SYM_CIPHER_AES_GCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + authModeSetupData->aadLenInBytes = gcmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_AES_CCM == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + authModeSetupData->aadLenInBytes = ccmAadLenInBytes_g; + } + else if (CPA_CY_SYM_CIPHER_CHACHA == + setup->setupData.cipherSetupData.cipherAlgorithm) + { + authModeSetupData->aadLenInBytes = chachaPolyAadLenInBytes_g; + } else { authModeSetupData->aadLenInBytes = 0; @@ -551,9 +566,10 @@ CpaStatus qatSymOpDataSetup(symmetric_test_params_t *pSetup, memset( pOpdata[idx].pAdditionalAuthData, 0xAA, KEY_SIZE_128_IN_BYTES); } - else if (((CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm) || - (CPA_CY_SYM_CIPHER_AES_GCM == cipherAlgorithm)) && - (CPA_CY_SYM_HASH_AES_GMAC != hashAlgorithm)) + else if ((((CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm) || + (CPA_CY_SYM_CIPHER_AES_GCM == cipherAlgorithm)) && + (CPA_CY_SYM_HASH_AES_GMAC != hashAlgorithm)) || + (CPA_CY_SYM_CIPHER_CHACHA == cipherAlgorithm)) { /* must allocate to the nearest block size required * (above 18 bytes) */ diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.c b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.c index 258be9f8..221a1256 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.c @@ -189,12 +189,12 @@ volatile CpaBoolean dataIntegrityVerify_g = CPA_FALSE; volatile CpaBoolean hwVerify_g = CPA_FALSE; volatile CpaBoolean keyCorrupt_g = CPA_FALSE; volatile CpaBoolean enableReadInstance_g = CPA_FALSE; - +Cpa16U numDecompInstances_g = 0; /* DC chaining specific variable to enable S/W write chaining operation */ volatile CpaBoolean swWrite_g = CPA_FALSE; volatile CpaBoolean isNsRequest_g = CPA_FALSE; -int verboseOutput = 1; +int verboseOutput = 0; CpaStatus setHwVerify(CpaBoolean val); CpaStatus setSwWrite(CpaBoolean val); @@ -215,6 +215,22 @@ CpaStatus setDcNsFlag(CpaBoolean val) } EXPORT_SYMBOL(isNsRequest_g); EXPORT_SYMBOL(setDcNsFlag); +volatile CpaBoolean decompServiceRequest_g = CPA_FALSE; +CpaStatus setDecompServiceRequest(CpaBoolean val) +{ + if (val == 1) + { + decompServiceRequest_g = CPA_TRUE; + } + else + { + decompServiceRequest_g = CPA_FALSE; + } + return CPA_STATUS_SUCCESS; +} +EXPORT_SYMBOL(decompServiceRequest_g); +EXPORT_SYMBOL(setDecompServiceRequest); + CpaStatus setDataIntegrity(CpaBoolean val) { dataIntegrity_g = val; @@ -1378,6 +1394,14 @@ void freeInstanceMapping(void) { qaeMemFree((void **)&dcInst_g); } + if (NULL != decompInst_g) + { + qaeMemFree((void **)&decompInst_g); + } + if (NULL != decompInstMap_g) + { + qaeMemFree((void **)&decompInstMap_g); + } if (NULL != cyInstMap_g) { qaeMemFree((void **)&cyInstMap_g); @@ -1465,8 +1489,6 @@ CpaStatus getCryptoInstanceMapping(void) { packageIdCount_g = info.physInstId.packageId; } - if (verboseOutput) - { PRINT("Inst %u, Affin: %u, Dev: %u, Accel %u, " "BDF %02X:%02X:%02X\n", i, @@ -1476,7 +1498,6 @@ CpaStatus getCryptoInstanceMapping(void) (Cpa8U)((info.physInstId.busAddress) >> 8), (Cpa8U)((info.physInstId.busAddress) & 0xFF) >> 3, (Cpa8U)((info.physInstId.busAddress) & 7)); - } if (info.isPolled) cyInstMap_g[i] = coreAffinity; else @@ -1757,8 +1778,6 @@ CpaStatus getCompressionInstanceMapping(void) { packageIdCount_g = info.physInstId.packageId; } - if (verboseOutput) - { PRINT("Inst %u, Affin: %u, Dev: %u, Accel %u, " "BDF %02X:%02X:%02X\n", i, @@ -1768,7 +1787,6 @@ CpaStatus getCompressionInstanceMapping(void) (Cpa8U)((info.physInstId.busAddress) >> 8), (Cpa8U)((info.physInstId.busAddress) & 0xFF) >> 3, (Cpa8U)((info.physInstId.busAddress) & 7)); - } if (info.isPolled) dcInstMap_g[i] = coreAffinity; else @@ -1793,6 +1811,111 @@ CpaStatus getCompressionInstanceMapping(void) EXPORT_SYMBOL(getCompressionInstanceMapping); #endif +/*get the instance to core affinity mapping of the Decompression instances and + * populate the InstMap structure*/ +CpaStatus getDecompressionInstanceMapping(void) +{ + CpaStatus status = CPA_STATUS_FAIL; + Cpa32U i = 0; + Cpa32U coreAffinity = 0; + CpaInstanceInfo2 info = { 0 }; + + /*get the number of decompression instances*/ + status = + cpaGetNumInstances(CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, &numInst_g); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcGetNumInstances failed with status: %d\n", status); + freeInstanceMapping(); + return CPA_STATUS_FAIL; + } + if (numInst_g > 0) + { + /* use single instance for latency and COO */ + if (singleInstRequired_g) + { + numInst_g = 1; + } + /*allocate memory to store the instance handles*/ + dcInst_g = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInst_g); + if (dcInst_g == NULL) + { + PRINT_ERR("Failed to allocate memory for instances\n"); + freeInstanceMapping(); + return CPA_STATUS_FAIL; + } + /*get the instances handles and place in allocated memory*/ + status = cpaGetInstances( + CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION, numInst_g, dcInst_g); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcGetInstances failed with status: %d\n", status); + freeInstanceMapping(); + return status; + } + /*allocate memory for the instance core mapping*/ + dcInstMap_g = qaeMemAlloc(sizeof(Cpa32U) * numInst_g); + if (dcInstMap_g == NULL) + { + PRINT_ERR("Failed to allocate memory for instance mapping\n"); + freeInstanceMapping(); + return CPA_STATUS_FAIL; + } + + for (i = 0; i < numInst_g; i++) + { + status = cpaDcInstanceGetInfo2(dcInst_g[i], &info); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("could not get instance info\n"); + freeInstanceMapping(); + return status; + } + if (CPA_STATUS_SUCCESS == + getCoreAffinity(dcInst_g[i], &coreAffinity, COMPRESSION)) + { + if ((packageIdCount_g < info.physInstId.packageId) && + (info.operState == CPA_OPER_STATE_UP) && + CPA_FALSE == devicesCounted_g) + { + packageIdCount_g = info.physInstId.packageId; + } + if (verboseOutput) + { + PRINT("Inst %u, Affin: %u, Dev: %u, Accel %u, " + "EE %u, BDF %02X:%02X:%02X\n", + i, + coreAffinity, + info.physInstId.packageId, + info.physInstId.acceleratorId, + info.physInstId.executionEngineId, + (Cpa8U)((info.physInstId.busAddress) >> 8), + (Cpa8U)((info.physInstId.busAddress) & 0xFF) >> 3, + (Cpa8U)((info.physInstId.busAddress) & 7)); + } + if (info.isPolled) + dcInstMap_g[i] = coreAffinity; + else + dcInstMap_g[i] = coreAffinity + 1; + } + else + { + freeInstanceMapping(); + return CPA_STATUS_FAIL; + } + } + devicesCounted_g = CPA_TRUE; + } + else + { + PRINT("There are no decompression instances\n"); + freeInstanceMapping(); + return CPA_STATUS_FAIL; + } + return status; +} +EXPORT_SYMBOL(getDecompressionInstanceMapping); + CpaStatus createStartandWaitForCompletionCrypto(Cpa32U instType) { CpaStatus status = CPA_STATUS_FAIL; @@ -1823,6 +1946,7 @@ CpaStatus createStartandWaitForCompletion(Cpa32U instType) Cpa16U nAsymInstances = 0; if ((instType != COMPRESSION) + && (instType != DECOMPRESSION) ) { cpaGetNumInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, &nSymInstances); @@ -1913,6 +2037,17 @@ CpaStatus createStartandWaitForCompletion(Cpa32U instType) numInst = numInst_g; } break; + case DECOMPRESSION: + { + if (CPA_STATUS_SUCCESS != getDecompressionInstanceMapping()) + { + PRINT_ERR("Could not get Decompression Instance mapping\n"); + return CPA_STATUS_FAIL; + } + instMap = dcInstMap_g; + numInst = numInst_g; + } + break; #endif default: { @@ -1938,12 +2073,20 @@ CpaStatus createStartandWaitForCompletion(Cpa32U instType) return status; } #if CY_API_VERSION_AT_LEAST(3, 0) - if ((isSymAsymConf == CPA_TRUE) && (instType == SYM || instType == ASYM)) + if (isSymAsymConf == CPA_TRUE) { - - qatModifyCyThreadLogicalQaInstance( - 0, cyInst_g, sym_asymInst, numInst_g); - isChangingThreadQaInstanceRequired_g = CPA_FALSE; + if (instType == SYM) + { + qatModifyCyThreadLogicalQaInstance( + 0, symCyInst_g, sym_asymInst, nSymInstances); + isChangingThreadQaInstanceRequired_g = CPA_FALSE; + } + else if (instType == ASYM) + { + qatModifyCyThreadLogicalQaInstance( + 0, asymCyInst_g, sym_asymInst, nAsymInstances); + isChangingThreadQaInstanceRequired_g = CPA_FALSE; + } } #endif status = startThreads(); diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.h b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.h index d54640eb..b3d130fc 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/cpa_sample_code_framework.h @@ -79,6 +79,7 @@ #define COMPRESSION (2) #define SYM (3) #define ASYM (4) +#define DECOMPRESSION (5) #define MAX_RETRY (10) #define SLEEP_ONE_SEC (1) #define SLEEP_ONE_HUNDRED_MILLISEC (100) @@ -174,12 +175,17 @@ extern volatile CpaBoolean hwVerify_g; extern volatile CpaBoolean swWrite_g; extern volatile CpaBoolean keyCorrupt_g; extern volatile CpaBoolean enableReadInstance_g; +extern Cpa16U numDecompInstances_g; +extern Cpa16U numDcInstances_g; CpaStatus setReliability(CpaBoolean val); CpaStatus setUnalignedBuffer(CpaBoolean val); CpaStatus setUseStaticPrime(int val); CpaStatus setDcNsFlag(CpaBoolean val); extern volatile CpaBoolean isNsRequest_g; +CpaStatus setDecompServiceRequest(CpaBoolean val); +extern volatile CpaBoolean decompServiceRequest_g; + CpaStatus setDataIntegrity(CpaBoolean val); CpaStatus setDataIntegrityVerify(CpaBoolean val); CpaStatus printReliability(void); @@ -676,6 +682,8 @@ extern CpaInstanceHandle *cyInst_g; extern CpaInstanceHandle *symCyInst_g; extern CpaInstanceHandle *asymCyInst_g; extern CpaInstanceHandle *dcInst_g; +extern CpaInstanceHandle *decompInst_g; +extern Cpa32U *decompInstMap_g; extern Cpa32U *cyInstMap_g; extern Cpa32U *symCyInstMap_g; extern Cpa32U *asymCyInstMap_g; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.c index bd895f9a..c80b6178 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.c @@ -66,6 +66,10 @@ extern CpaBoolean cy_service_started_g; extern volatile Cpa32U numThreadsAtBarrier_g; +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +long pollingThreadsInterval_g = 1000; +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ extern volatile CpaBoolean error_flag_g; Cpa32U cpu_freq_g = 0; @@ -1215,35 +1219,466 @@ void sampleCodeCyEventPoll(CpaInstanceHandle instanceHandle) } } +#if defined(USER_SPACE) && !defined(SC_EPOLL_DISABLED) +#ifdef DO_CRYPTO +CpaStatus trySetupCyLegacyEventPoll(CpaInstanceHandle instanceHandle, + performance_func_t *pollFn) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + int fd = -1; + + status = icp_sal_CyGetFileDescriptor(instanceHandle, &fd); + if (CPA_STATUS_SUCCESS == status) + { + *pollFn = sampleCodeCyEventPoll; + icp_sal_CyPutFileDescriptor(instanceHandle, fd); + return CPA_STATUS_SUCCESS; + } + else if (CPA_STATUS_FAIL == status) + { + return CPA_STATUS_FAIL; + } + /* else feature is unsupported */ + return CPA_STATUS_UNSUPPORTED; +} +#endif /* DO_CRYPTO */ + +CpaStatus trySetupDcLegacyEventPoll(CpaInstanceHandle instanceHandle, + performance_func_t *pollFn) +{ + CpaStatus status = CPA_STATUS_SUCCESS; + int fd = -1; + + status = icp_sal_DcGetFileDescriptor(instanceHandle, &fd); + if (CPA_STATUS_SUCCESS == status) + { + *pollFn = sampleCodeDcEventPoll; + icp_sal_DcPutFileDescriptor(instanceHandle, fd); + return CPA_STATUS_SUCCESS; + } + else if (CPA_STATUS_FAIL == status) + { + return CPA_STATUS_FAIL; + } + /* else feature is unsupported */ + return CPA_STATUS_UNSUPPORTED; +} +#endif /* USER_SPACE && !SC_EPOLL_DISABLED */ + /* Wrapper function that returns function pointer for DC dynamic polling */ -void sampleCodeDcDynamicPollWrapper(void* instanceHandle) +void sampleCodeDcDynamicPollWrapper(void *instanceHandle) { sampleCodeDynamicPoll((CpaInstanceHandle)instanceHandle, - CPA_ACC_SVC_TYPE_DATA_COMPRESSION); + CPA_ACC_SVC_TYPE_DATA_COMPRESSION); } /* Wrapper function that returns function pointer for CY SYM dynamic polling */ -void sampleCodeSymDynamicPollWrapper(void* instanceHandle) +void sampleCodeSymDynamicPollWrapper(void *instanceHandle) { sampleCodeDynamicPoll((CpaInstanceHandle)instanceHandle, - CPA_ACC_SVC_TYPE_CRYPTO_SYM); + CPA_ACC_SVC_TYPE_CRYPTO_SYM); } /* Wrapper function that returns function pointer for CY ASYM dynamic polling */ -void sampleCodeAsymDynamicPollWrapper(void* instanceHandle) +void sampleCodeAsymDynamicPollWrapper(void *instanceHandle) { sampleCodeDynamicPoll((CpaInstanceHandle)instanceHandle, - CPA_ACC_SVC_TYPE_CRYPTO_ASYM); + CPA_ACC_SVC_TYPE_CRYPTO_ASYM); } void sampleCodeDynamicPoll(CpaInstanceHandle instanceHandle, CpaAccelerationServiceType serviceType) { #ifndef SC_EPOLL_DISABLED +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) + int fd = -1; /* Service file descriptor for epoll */ + int efd = -1; /* Epoll file descriptor */ + int n = 0; /* Number of epoll events returned */ + struct epoll_event event; /* Single epoll event for setup */ + struct epoll_event *events = NULL; /* Array of epoll events */ + struct timespec reqTime, remTime; /* Sleep time for polling mode */ + CpaStatus status = CPA_STATUS_FAIL; + CpaInstanceResponseMode defaultResponseMode = CPA_INST_RX_NOTIFY_NONE; + + CpaInstanceResponseMode responseMode = CPA_INST_RX_NOTIFY_NONE; + CpaInstanceResponseMode previousResponseMode = + CPA_INST_RX_NOTIFY_NONE; /* Track previous mode for change detection */ + CpaBoolean needModeRestore = + CPA_FALSE; /* Track if we need to restore mode */ + CpaBoolean volatile *pServiceStarted = NULL; + CpaInstanceInfo2 + instanceInfo; /* Instance info to get actual service type */ + CpaAccelerationServiceType + actualServiceType; /* Actual service type from instance */ + + /* Function pointers for service-specific operations */ + typedef CpaStatus (*GetFileDescriptorFn)(CpaInstanceHandle, int *); + typedef CpaStatus (*PutFileDescriptorFn)(CpaInstanceHandle, int); + typedef CpaStatus (*PollInstanceFn)(CpaInstanceHandle, Cpa32U); + GetFileDescriptorFn getFileDescriptorFn = NULL; + PutFileDescriptorFn putFileDescriptorFn = NULL; + PollInstanceFn pollInstanceFn = NULL; + + /* Query the instance to get the actual service type instead of relying on + * parameter */ + memset(&instanceInfo, 0, sizeof(CpaInstanceInfo2)); + /* Use the appropriate API based on the provided service type hint */ + if (serviceType == CPA_ACC_SVC_TYPE_DATA_COMPRESSION || + serviceType == CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION) + { + status = cpaDcInstanceGetInfo2(instanceHandle, &instanceInfo); + } +#ifdef DO_CRYPTO + else + { + /* Default to crypto API for CRYPTO, CRYPTO_SYM, CRYPTO_ASYM types */ + status = cpaCyInstanceGetInfo2(instanceHandle, &instanceInfo); + } +#endif /* DO_CRYPTO */ + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("Warning:Failed to get instance info (status %d), using " + "provided service type %d\n", + status, + serviceType); + actualServiceType = serviceType; /* Fallback to provided type */ + } + else + { + actualServiceType = instanceInfo.accelerationServiceType; + } + + /* Initialize polling sleep interval */ + reqTime.tv_sec = 0; + reqTime.tv_nsec = pollingThreadsInterval_g; + + /* Select service-specific functions and EPOLL mode based on ACTUAL service + * type from instance */ + switch (actualServiceType) + { +#ifdef DO_CRYPTO + case CPA_ACC_SVC_TYPE_CRYPTO: + case CPA_ACC_SVC_TYPE_CRYPTO_SYM: + case CPA_ACC_SVC_TYPE_CRYPTO_ASYM: + /* CRYPTO (combined), SYM and ASYM all use the same CY (crypto) + * infrastructure */ + getFileDescriptorFn = icp_sal_CyGetFileDescriptor; + putFileDescriptorFn = icp_sal_CyPutFileDescriptor; + pollInstanceFn = icp_sal_CyPollInstance; + pServiceStarted = &cy_service_started_g; + break; +#endif /* DO_CRYPTO */ + + case CPA_ACC_SVC_TYPE_DATA_COMPRESSION: + case CPA_ACC_SVC_TYPE_DATA_DECOMPRESSION: + /* Both COMPRESSION and DECOMPRESSION use DC infrastructure */ + getFileDescriptorFn = icp_sal_DcGetFileDescriptor; + putFileDescriptorFn = icp_sal_DcPutFileDescriptor; + pollInstanceFn = icp_sal_DcPollInstance; + pServiceStarted = &dc_service_started_g; + break; + + default: + PRINT_ERR( + "Unsupported actual service type %d for dynamic polling\n", + actualServiceType); + return; + } + + /* Sanity check - ensure all function pointers are initialized */ + if (getFileDescriptorFn == NULL || putFileDescriptorFn == NULL || + pollInstanceFn == NULL || pServiceStarted == NULL) + { + PRINT_ERR( + "Failed to initialize function pointers for service type %d\n", + serviceType); + return; + } + + /* Get the current (default) response mode of the instance using appropriate + * service type for API */ + CpaAccelerationServiceType apiServiceType; + + /* Use provided serviceType for API calls when instance is CRYPTO (combined) + * type */ + if (actualServiceType == CPA_ACC_SVC_TYPE_CRYPTO) + { + apiServiceType = serviceType; /* Use SYM or ASYM from wrapper */ + } + else + { + apiServiceType = + actualServiceType; /* Use actual type for non-combined instances */ + } + + status = cpaInstanceGetResponseMode( + instanceHandle, apiServiceType, &defaultResponseMode); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Error getting instance response mode: %d\n", status); + error_flag_g = CPA_TRUE; + return; + } + + /* + * If instance is not in event mode, temporarily switch to event mode + * to obtain file descriptor for epoll setup. We'll revert later. + * Use appropriate API service type to ensure compatibility with instance + * configuration. + */ + if (defaultResponseMode != CPA_INST_RX_NOTIFY_BY_EVENT) + { + status = cpaInstanceSetResponseMode( + instanceHandle, actualServiceType, CPA_INST_RX_NOTIFY_BY_EVENT); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR( + "Error setting instance response mode to event-based: %d\n", + status); + error_flag_g = CPA_TRUE; + goto cleanup_and_exit; + } + needModeRestore = CPA_TRUE; + } + + /* Get file descriptor for epoll operations */ + if (CPA_STATUS_SUCCESS != getFileDescriptorFn(instanceHandle, &fd)) + { + PRINT_ERR("Error getting file descriptor for epoll instance\n"); + goto cleanup_and_exit; + } + + /* Create epoll instance for event monitoring */ + efd = epoll_create1(0); + if (-1 == efd) + { + PRINT_ERR("Error creating epoll file descriptor\n"); + goto cleanup_and_exit; + } + + /* Configure epoll event structure and add FD to epoll interest list */ + event.data.fd = fd; + event.events = EPOLLIN | EPOLLET; /* Edge-triggered input events */ + if (-1 == epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event)) + { + PRINT_ERR("Error adding file descriptor to epoll (errno: %d)\n", errno); + goto cleanup_and_exit; + } + + /* Allocate memory for epoll event array */ + events = qaeMemAlloc(EPOLL_MAX_EVENTS * sizeof(event)); + if (NULL == events) + { + PRINT_ERR("Error allocating memory for epoll events array\n"); + goto cleanup_and_exit; + } + + /* + * Restore original response mode if we changed it. + * This allows the main loop to dynamically switch between modes. + * Use actualServiceType for Set (supports CRYPTO), apiServiceType for Get + * (requires SYM/ASYM). + */ + if (needModeRestore) + { + status = cpaInstanceSetResponseMode( + instanceHandle, actualServiceType, defaultResponseMode); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Error restoring instance response mode to default\n"); + goto cleanup_and_exit; + } + needModeRestore = CPA_FALSE; + /* Note: Keep FD valid as mode may change to event during main loop */ + } + + /* + * Main polling loop - dynamically switches between polling modes: + * - CPA_INST_RX_NOTIFY_NONE: Traditional busy-wait polling with sleep + * - CPA_INST_RX_NOTIFY_BY_EVENT: Event-driven polling using epoll + */ + previousResponseMode = + defaultResponseMode; /* Initialize with default mode */ + /* Main polling loop - continue until service is stopped */ + while (*pServiceStarted == CPA_TRUE) + { + /* Check current response mode (may change dynamically during runtime) + * using appropriate API service type */ + status = cpaInstanceGetResponseMode( + instanceHandle, apiServiceType, &responseMode); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Error getting current instance response mode in polling " + "loop\n"); + error_flag_g = CPA_TRUE; + break; + } + + /* Print response mode change if it differs from previous mode */ + if (responseMode != previousResponseMode) + { + PRINT( + "Dynamic Poll: Response mode changed from %d (%s) to %d (%s)\n", + previousResponseMode, + (previousResponseMode == CPA_INST_RX_NOTIFY_NONE) ? "polling" + : "event", + responseMode, + (responseMode == CPA_INST_RX_NOTIFY_NONE) ? "polling" + : "event"); + previousResponseMode = responseMode; + if (responseMode == CPA_INST_RX_NOTIFY_BY_EVENT) + { + /* Switched to event-driven mode */ + PRINT("Switched to event-driven polling for service type %d\n", + serviceType); + previousResponseMode = responseMode; + } + else + { + /* Switched to polling mode */ + PRINT("Switched to traditional polling for service type %d\n", + serviceType); + previousResponseMode = responseMode; + } + } + + /* Execute appropriate polling based on current mode */ + if (CPA_INST_RX_NOTIFY_NONE == responseMode) + { + /* + * Traditional polling mode - busy wait with sleep intervals + * Poll with 0 timeout processes all available packets immediately + */ + status = pollInstanceFn(instanceHandle, 0); + if (CPA_STATUS_SUCCESS == status || CPA_STATUS_RETRY == status) + { + /* Sleep for configured interval to reduce CPU usage */ + nanosleep(&reqTime, &remTime); + } + else + { + PRINT_ERR( + "Polling failed with status %d in traditional poll mode\n", + status); + error_flag_g = CPA_TRUE; + break; + } + } + else /*CPA_INST_RX_NOTIFY_EVENT*/ + { + /* Event-driven mode: Wait for EPOLL events */ + n = epoll_wait(efd, events, EPOLL_MAX_EVENTS, EPOLL_TIMEOUT_MS); + + if (n < 0) + { + if (errno == EINTR) + { + /* Interrupted by signal, continue */ + continue; + } + PRINT_ERR("epoll_wait failed with errno: %d\n", errno); + error_flag_g = CPA_TRUE; + break; + } + + /* Poll when events occur, or periodically on timeout to catch edge + * cases */ + if (n >= 0) /* Always try at least once (events or timeout) */ + { + /* Keep polling until no more responses (for edge-triggered + * epoll) */ + do + { + status = pollInstanceFn(instanceHandle, 0); + if ((CPA_STATUS_SUCCESS != status) && + (CPA_STATUS_RETRY != status)) + { + if (status != + CPA_STATUS_FAIL) /* Ignore benign failures */ + { + PRINT_ERR( + "Polling failed with status %d in event mode\n", + status); + error_flag_g = CPA_TRUE; + break; + } + break; /* No more responses */ + } + } while (status == CPA_STATUS_SUCCESS); + } + /* Break outer loop if inner loop detected error */ + if (error_flag_g == CPA_TRUE) + { + break; + } + } + } +cleanup_and_exit: + /* Cleanup resources in reverse order of allocation */ + + /* Remove file descriptor from epoll interest list */ + if (efd != -1 && fd != -1) + { + if (-1 == epoll_ctl(efd, EPOLL_CTL_DEL, fd, &event)) + { + PRINT_ERR("Warning: Error removing file descriptor from epoll " + "during cleanup\n"); + error_flag_g = CPA_TRUE; + } + } + /* Free allocated memory for events array */ + if (events != NULL) + { + qaeMemFree((void **)&events); + events = NULL; + } + /* Release file descriptor only if instance is still in event mode */ + if (fd != -1) + { + CpaInstanceResponseMode currentMode = CPA_INST_RX_NOTIFY_NONE; + status = cpaInstanceGetResponseMode( + instanceHandle, apiServiceType, ¤tMode); + if (status == CPA_STATUS_SUCCESS && + currentMode == CPA_INST_RX_NOTIFY_BY_EVENT) + { + if (CPA_STATUS_SUCCESS != putFileDescriptorFn(instanceHandle, fd)) + { + PRINT_ERR("Warning: Failed to release epoll file descriptor " + "during cleanup\n"); + error_flag_g = CPA_TRUE; + } + } + /* If mode is polling, FD is already invalidated by driver - no release + * needed */ + } + /* Close epoll file descriptor */ + if (efd != -1) + { + close(efd); + } + + /* Restore original response mode if we changed it and didn't restore yet - + * use actualServiceType for Set */ + if (needModeRestore) + { + status = cpaInstanceSetResponseMode( + instanceHandle, actualServiceType, defaultResponseMode); + if (status != CPA_STATUS_SUCCESS) + { + PRINT_ERR("Warning: Failed to restore original response mode " + "during cleanup\n"); + } + } + return; + +#else /*USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ PRINT_ERR("EPOLL feature not supported - dynamic polling unavailable\n"); error_flag_g = CPA_TRUE; return; -#else /* SC_EPOLL_DISABLED */ +#endif /* USER_SPACE && SUPPORTED_FEAT_EPOLL && STV_TEST_CODE */ +#else /* SC_EPOLL_DISABLED */ PRINT_ERR("EPOLL disabled at compile time\n"); error_flag_g = CPA_TRUE; return; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.h b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.h index 83168606..0f75826b 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/framework/linux/user_space/cpa_sample_code_utils.h @@ -79,7 +79,24 @@ typedef sem_t *sample_code_semaphore_t; #define DEFAULT_SIGN_OF_LIFE (0) #define USE_V1_CONFIG_FILE (1) #define USE_V2_CONFIG_FILE (2) -#define MAX_NUMOPT (18) +/* + * MAX_NUMOPT defines the maximum number of options for command-line parsing. + */ +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_INT_COALESCING_TIMER) && \ + defined(STV_TEST_CODE) +#define _MAX_NUMOPT_COALESCING_ADD (2) +#else +#define _MAX_NUMOPT_COALESCING_ADD (0) +#endif +#if defined(USER_SPACE) && defined(SUPPORTED_FEAT_EPOLL) && \ + defined(STV_TEST_CODE) +#define MAX_NUMOPT (18 + _MAX_NUMOPT_COALESCING_ADD) +#else +#define MAX_NUMOPT (16 + _MAX_NUMOPT_COALESCING_ADD) +#endif + +/*This is used to define a pointer to a function*/ +typedef void (*performance_func_t)(void *); typedef struct option_s { @@ -386,7 +403,6 @@ void sample_code_wait_threads_arrived(Cpa32U sleepTimeout, Cpa32U maxRetries); void sampleCodeDynamicPoll(CpaInstanceHandle instanceHandle, CpaAccelerationServiceType serviceType); - /** ***************************************************************************** * @ingroup sampleCode @@ -408,7 +424,7 @@ void sampleCodeDynamicPoll(CpaInstanceHandle instanceHandle, * Polling continues until DC service is stopped * *****************************************************************************/ -void sampleCodeDcDynamicPollWrapper(void* instanceHandle); +void sampleCodeDcDynamicPollWrapper(void *instanceHandle); /** ***************************************************************************** @@ -431,7 +447,7 @@ void sampleCodeDcDynamicPollWrapper(void* instanceHandle); * Polling continues until CY service is stopped * *****************************************************************************/ -void sampleCodeSymDynamicPollWrapper(void* instanceHandle); +void sampleCodeSymDynamicPollWrapper(void *instanceHandle); /** ***************************************************************************** @@ -454,6 +470,56 @@ void sampleCodeSymDynamicPollWrapper(void* instanceHandle); * Polling continues until CY service is stopped * *****************************************************************************/ -void sampleCodeAsymDynamicPollWrapper(void* instanceHandle); +void sampleCodeAsymDynamicPollWrapper(void *instanceHandle); + +#ifdef DO_CRYPTO +/** + ***************************************************************************** + * @ingroup sampleCode + * trySetupCyLegacyEventPoll + * + * @description + * Try to set up legacy event-based polling for Crypto instances + * + * @param[in] instanceHandle Instance handle for crypto service + * @param[out] pollFn Pointer to polling function pointer + * + * @retval CPA_STATUS_SUCCESS Event polling successfully configured + * @retval CPA_STATUS_FAIL Error occurred during setup + * @retval CPA_STATUS_UNSUPPORTED Feature not supported + * + * @pre + * Crypto instance must be initialized + * @post + * Event polling configured if supported + * + *****************************************************************************/ +CpaStatus trySetupCyLegacyEventPoll(CpaInstanceHandle instanceHandle, + performance_func_t *pollFn); +#endif /* DO_CRYPTO */ + +/** + ***************************************************************************** + * @ingroup sampleCode + * trySetupDcLegacyEventPoll + * + * @description + * Try to set up legacy event-based polling for Data Compression instances + * + * @param[in] instanceHandle Instance handle for DC service + * @param[out] pollFn Pointer to polling function pointer + * + * @retval CPA_STATUS_SUCCESS Event polling successfully configured + * @retval CPA_STATUS_FAIL Error occurred during setup + * @retval CPA_STATUS_UNSUPPORTED Feature not supported + * + * @pre + * DC instance must be initialized + * @post + * Event polling configured if supported + * + *****************************************************************************/ +CpaStatus trySetupDcLegacyEventPoll(CpaInstanceHandle instanceHandle, + performance_func_t *pollFn); #endif diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/kernel_space/qae_mem_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/kernel_space/qae_mem_utils.c deleted file mode 100644 index 94aa7dac..00000000 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/qae/linux/kernel_space/qae_mem_utils.c +++ /dev/null @@ -1,171 +0,0 @@ -/*************************************************************************** - * - * SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2007-2026 Intel Corporation - * - * These contents may have been developed with support from one or more - * Intel-operated generative artificial intelligence solutions. - * - ***************************************************************************/ -/** -***************************************************************************** -* @file qae_mem_utils.c -* -* This file provides linux kernel memory allocation for quick assist API -* -*****************************************************************************/ - -#include "qae_mem_utils.h" -#ifdef SAL_IOMMU_CODE -#include -#endif -#include -#include -#include -#include -#include - -/* Maximum memory can be allocated by kmalloc*/ -#define QAE_MEM_SIZE_LIMIT (1024 * 4096) - -/* return amount of padding based on padSize a and alignment b*/ -#define MEM_PADDING(a, b) ((b - (a % b)) % b) - -#define IS_VMALLOC_ADDR(addr) \ - (((QAE_UINT)(addr) >= VMALLOC_START) && ((QAE_UINT)(addr) < VMALLOC_END)) - -Cpa32U numaAllocations_g = 0; -Cpa32U normalAllocations_g = 0; - -/************************************** - * Memory functions - *************************************/ -void *qaeMemAlloc(Cpa32U memsize) -{ - if (memsize > QAE_MEM_SIZE_LIMIT) - { - return (vmalloc(memsize)); - } - normalAllocations_g++; - return (kmalloc(memsize, GFP_KERNEL)); -} - -void *qaeMemAllocNUMA(Cpa32U size, Cpa32U node, Cpa32U alignment) -{ - void *ptr = NULL; - uint64_t phys_ptr = 0; - void *pRet = NULL; - Cpa32U alignment_offset = 0; - - qae_mem_alloc_info_t memInfo = {0}; - - if (size == 0 || alignment < 1) - { - printk(" size or alignment are zero \n"); - return NULL; - } - /*alignment should be 1,2,4,8....*/ - if (alignment & (alignment - 1)) - { - printk("Expecting alignment of a power of \ - two but did not get one\n"); - return NULL; - } - - // add the alignment and the struct size to the buffer size - memInfo.mSize = size + alignment + sizeof(qae_mem_alloc_info_t); -#ifdef SAL_IOMMU_CODE - memInfo.mSize = icp_sal_iommu_get_remap_size(memInfo.mSize); -#endif - - /*allocate contiguous memory*/ - ptr = kmalloc_node(memInfo.mSize, GFP_KERNEL, node); - - if (ptr == NULL) - { - printk("failed to allocate memory\n"); - return NULL; - } - - // store the base address into the struct - memInfo.mAllocMemPtr = ptr; - phys_ptr = virt_to_phys(ptr); -#ifdef SAL_IOMMU_CODE - if (icp_sal_iommu_map(phys_ptr, phys_ptr, memInfo.mSize)) - { - printk("failed to iommu remap\n"); - kfree(ptr); - return NULL; - } -#endif - // add the size of the struct to the return pointer - pRet = (char *)memInfo.mAllocMemPtr + sizeof(qae_mem_alloc_info_t); - // compute the offset from the lignement - alignment_offset = (QAE_UINT)pRet % alignment; - // in order to obtain the pointer to the buffer add the alignment and - // subtract the offset, now we have the return pointer aligned - pRet = (char *)pRet + (alignment - alignment_offset); - // copy the struct immediately before the buffer pointer - memcpy((void *)((char *)pRet - sizeof(qae_mem_alloc_info_t)), - (void *)(&memInfo), - sizeof(qae_mem_alloc_info_t)); - // increment the NUMA allocations counter - numaAllocations_g++; - - return pRet; -} - -void qaeMemFreeNUMA(void **ptr) -{ - qae_mem_alloc_info_t *memInfo = NULL; - if (ptr == NULL || *ptr == NULL) - { - return; - } - memInfo = - (qae_mem_alloc_info_t *)((Cpa8S *)*ptr - sizeof(qae_mem_alloc_info_t)); - - if (memInfo->mSize == 0 || memInfo->mAllocMemPtr == NULL) - { - printk("Detected the corrupted data: memory leak!\n"); - printk("Size: %d, memPtr: %p\n", memInfo->mSize, memInfo->mAllocMemPtr); - return; - } -#ifdef SAL_IOMMU_CODE - if (icp_sal_iommu_unmap(virt_to_phys(memInfo->mAllocMemPtr), - memInfo->mSize)) - { - printk("failed to iommu unmap\n"); - } -#endif - kfree(memInfo->mAllocMemPtr); - numaAllocations_g--; - *ptr = NULL; -} - -void qaeMemFree(void **ptr) -{ - if (ptr == NULL || *ptr == NULL) - { - return; - } - if (IS_VMALLOC_ADDR(*ptr)) - { - vfree(*ptr); - return; - } - kfree(*ptr); - normalAllocations_g--; - *ptr = NULL; -} - -QAE_PHYS_ADDR qaeVirtToPhysNUMA(void *ptr) -{ - return (QAE_PHYS_ADDR)(QAE_UINT)virt_to_phys(ptr); -} - -void printMemAllocations() -{ - printk("NUMA Allocations %d\n", numaAllocations_g); - printk("Normal Allocations %d\n", normalAllocations_g); -} diff --git a/quickassist/lookaside/access_layer/src/user/sal_user.c b/quickassist/lookaside/access_layer/src/user/sal_user.c index 126afa1c..d79596dc 100644 --- a/quickassist/lookaside/access_layer/src/user/sal_user.c +++ b/quickassist/lookaside/access_layer/src/user/sal_user.c @@ -30,7 +30,6 @@ #include "icp_adf_user_proxy.h" #include "icp_adf_transport.h" #include "icp_adf_cfg.h" -#include "icp_adf_debug.h" /* FW includes */ #include "icp_qat_fw_la.h" diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw.h b/quickassist/lookaside/firmware/include/icp_qat_fw.h index 2624a819..55e59f18 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_fw.h +++ b/quickassist/lookaside/firmware/include/icp_qat_fw.h @@ -887,6 +887,16 @@ typedef struct icp_qat_fw_comn_resp_s * Constant value indicating Src&Dst Buffer Pointer type is SGL type * If Batch and Pack mode is enabled, only applies to Destination buffer.*/ +#define QAT_COMN_KPT_SERVICES_BITPOS 1 +/**< @ingroup icp_qat_fw_comn + * Common Request Flags - Starting bit position indicating + * the control bits for KPT services. */ + +#define QAT_COMN_KPT_SERVICES_MASK 0x1 +/**< @ingroup icp_qat_fw_comn + * Common Request Flags - Bit mask for the width of the control bit for + * KPT services.*/ + /* ========================================================================= */ /* CD Field Flag definitions */ /* ========================================================================= */ @@ -898,6 +908,13 @@ typedef struct icp_qat_fw_comn_resp_s /**< @ingroup icp_qat_fw_comn * Constant value indicating CD Field contains 16 bytes of setup data */ +/* ========================================================================= */ +/* KPT Services Definitions */ +/* ========================================================================= */ +#define QAT_COMN_KPT_SERVICE_FLAG 0x1 +/**< @ingroup icp_qat_fw_comn + * Constant value to indicate KPT services is enabled for this request. */ + /** ****************************************************************************** * @ingroup icp_qat_fw_comn @@ -1149,6 +1166,21 @@ typedef struct icp_qat_fw_comn_resp_s QAT_COMN_RESP_CRYPTO_STATUS_BITPOS, \ QAT_COMN_RESP_CRYPTO_STATUS_MASK) +/** +****************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Macro for setting KPT service flag in the target field. +* +* @param flags Flags in which at services bits will be set +* @param val Value of the at services bits to be set in flags +* +*****************************************************************************/ +#define ICP_QAT_FW_COMN_KPT_SERVICES_SET(flags, val) \ + QAT_FIELD_SET( \ + flags, val, QAT_COMN_KPT_SERVICES_BITPOS, QAT_COMN_KPT_SERVICES_MASK) + /** ****************************************************************************** * @ingroup icp_qat_fw_comn diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw_comp.h b/quickassist/lookaside/firmware/include/icp_qat_fw_comp.h index 25fcf1bf..b14577e7 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_fw_comp.h +++ b/quickassist/lookaside/firmware/include/icp_qat_fw_comp.h @@ -54,6 +54,24 @@ typedef enum } icp_qat_fw_comp_cmd_id_t; +/** +***************************************************************************** +* @ingroup icp_qat_fw_comp +* Definition of the additional QAT5.1 Compression command types +* @description +* Enumeration which is used to indicate the ids of functions +* that are exposed by the Compression QAT FW service +* +*****************************************************************************/ +typedef enum +{ + ICP_QAT_FW_COMP_51_CMD_ZSTD_COMPRESS = 10, + /*!< ZSTD Compress Request */ + + ICP_QAT_FW_COMP_51_CMD_ZSTD_DECOMPRESS = 11, + /*!< ZSTD Decompress Request */ +} icp_qat_fw_comp_51_cmd_id_t; + /* * REQUEST FLAGS IN COMMON COMPRESSION * In common message it is named as SERVICE SPECIFIC FLAGS. @@ -178,7 +196,6 @@ typedef enum /**< @ingroup icp_qat_fw_comp * Three Least Significant Bytes mask for the dictionary length in the dictionary parameters received in the compression request parameters. */ - /** ****************************************************************************** * @ingroup icp_qat_fw_comp @@ -987,6 +1004,8 @@ typedef struct icp_qat_fw_comp_cd_hdr_s } icp_qat_fw_comp_cd_hdr_t; +#define ICP_QAT_FW_COMP_RAM_BANK_FLAGS(p) ((p)->ram_bank_flags) + #define COMP_CPR_INITIAL_CRC 0 #define COMP_CPR_INITIAL_ADLER 1 @@ -1092,6 +1111,15 @@ typedef struct icp_qat_fw_comp_req_s } asb_threshold; + struct + { + uint32_t reserved; + /**< LW 22 \n Reserved - not used */ + + uint32_t dictionary_id; + /**< LW 23 \n Dictionary ID value for config_qword8 HI */ + + } zstd_dict_id; } u3; /**< LWs 24-29 */ @@ -1194,7 +1222,6 @@ typedef enum ICP_QAT_FW_COMP_DICT_TYPE_COMPRESSED = 2, /*!< Compressed Dictionary */ - ICP_QAT_FW_COMP_DICT_TYPE_DELIMITER /**< Delimiter type */ diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw_kpt_pro.h b/quickassist/lookaside/firmware/include/icp_qat_fw_kpt_pro.h new file mode 100644 index 00000000..c46be859 --- /dev/null +++ b/quickassist/lookaside/firmware/include/icp_qat_fw_kpt_pro.h @@ -0,0 +1,109 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + ***************************************************************************** + * @file icp_qat_fw_kpt_pro.h + * @defgroup icp_qat_fw_kpt_pro ICP QAT FW KPT Provision Processing + * Definitions + * @ingroup icp_qat_fw + * + * @description + * This file documents the external interfaces that the QAT FW running + * on the QAT Acceleration Engine provides to clients wanting to + * perform KPT provision services. + * + *****************************************************************************/ + +#ifndef _ICP_QAT_FW_KPT_PRO_H_ +#define _ICP_QAT_FW_KPT_PRO_H_ + +/* +**************************************************************************** +* Include local header files +**************************************************************************** +*/ +#include "icp_qat_fw_pke.h" + +/** + *************************************************************************** + * @ingroup icp_qat_fw_kpt_pro + * Request data for QAT messages + * + * @description + * This structure defines the request data format for KPT provision + * messages. This is used to store data which is known when the message + * is sent and which we wish to retrieve when the response message is + * processed. + * + **************************************************************************/ +typedef struct icp_qat_fw_kpt_pro_request_s +{ + uint8_t resrvd0; + uint8_t cmd_id; + /**< KPT provision command id */ + uint8_t service_type; + /**< KPT provision service type */ + uint8_t resrvd1 : 7; + uint8_t valid : 1; + /**< 'Valid' flag */ + uint16_t serv_specif_flags; + /**< Common Request service-specific flags, this field is not used in KPT + * provision, but a placeholder for PKE Tx request backward compatibility + * */ + uint8_t comn_req_flags; + /**< Common Request Flags, this field is not used in KPT provision, but a + * placeholder for PKE Tx request backward compatibility */ + uint8_t resrvd2; + uint64_t src_addr; + /**< Physical address of eSWK, length is fixed to 384 bytes */ + uint64_t key_handle; + /**< KPT provision key handle */ + uint64_t opaque_data; + /**< Opaque data passed unmodified from the request to response messages by + * firmware (fw) */ + uint64_t dst_addr; + /**< Physical address of destination buffer, length is fixed to 776 bytes */ + uint8_t resrvd3[24]; +} icp_qat_fw_kpt_pro_request_t; + +/** + ***************************************************************************** + * @ingroup icp_qat_fw_kpt_pro + * Response data for QAT messages + * @description + * Define the KPT provision response format + * + *****************************************************************************/ +typedef struct icp_qat_fw_kpt_pro_resp_data_s +{ + uint8_t resrvd0; + uint8_t cmd_id; + /**< KPT provision request command id, copied from the request + * to the response */ + uint8_t service_type; + /**< KPT provision response service type, copied from the + * request to the response */ + uint8_t resrvd1 : 7; + uint8_t valid : 1; + /**< 'Valid' flag */ + icp_qat_fw_pke_resp_status_t rsp_status; + /**< KPT provision request operation result */ + uint16_t resrvd2; + /**< KPT provision key handle */ + uint64_t opaque_data; + /**< Opaque data pointer, it's a copy of the callback data + * passed when the request was created */ + uint64_t key_handle; + /**< KPT provision key handle */ + uint64_t dst_addr; + /**< Physical address of destination flat buffer, copied from the request to + * the response */ +} icp_qat_fw_kpt_pro_resp_data_t; + +#endif /* _ICP_QAT_FW_KPT_PRO_H_ */ diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw_la.h b/quickassist/lookaside/firmware/include/icp_qat_fw_la.h index 10730f07..e09b5433 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_fw_la.h +++ b/quickassist/lookaside/firmware/include/icp_qat_fw_la.h @@ -1111,6 +1111,55 @@ typedef struct icp_qat_fw_cipher_cd_ctrl_hdr_s } icp_qat_fw_cipher_cd_ctrl_hdr_t; +/** + ***************************************************************************** + * @ingroup icp_qat_fw_la + * Cipher content descriptor control block (header) for Gen6 device + * @description + * Definition of the service-specific cipher control block header + * structure. This header forms part of the content descriptor + * block incorporating LWs 27-31, as defined by the common base + * parameters structure. + * + *****************************************************************************/ +typedef struct icp_qat_fw_51_cipher_cd_ctrl_hdr_s +{ + /**< LW 27 */ + uint8_t cipher_state_sz; + /**< State size in quad words of the cipher algorithm used in this session. + * Set to zero if the algorithm does not provide any state */ + + uint8_t cipher_key_sz; + /**< Key size in quad words of the cipher algorithm used in this session */ + + uint8_t cipher_cfg_offset; + /**< Quad word offset from the content descriptor parameters address i.e. + * (content_address + (cd_hdr_sz << 3)) to the parameters for the cipher + * processing */ + + uint8_t resrvd1; + /**< reserved */ + + /**< LW 28 */ + uint8_t resrvd2; + /**< reserved */ + + uint8_t resrvd3; + /**< reserved */ + + uint8_t crc_cfg_offset; + /**< CRC configuration offset in quad words */ + + uint8_t resrvd4; + /**< Reserved bytes to bring the struct to the word boundary, used by + * authentication. MUST be set to 0 */ + + /**< LWs 29-31 */ + uint32_t resrvd5[ICP_QAT_FW_NUM_LONGWORDS_3]; + /**< Reserved bytes used by authentication. MUST be set to 0 */ + +} icp_qat_fw_51_cipher_cd_ctrl_hdr_t; + /** ***************************************************************************** * @ingroup icp_qat_fw_la @@ -1672,6 +1721,9 @@ typedef struct icp_qat_fw_la_auth_req_params_s uint64_t aad_adr; /**< Address of the AAD info in DRAM. Used for the CCM and GCM * protocols */ + uint64_t hmac_key_addr; + /**< Address of the HMAC key in DRAM */ + } u1; /**< LWs 24-25 */ @@ -1687,6 +1739,9 @@ typedef struct icp_qat_fw_la_auth_req_params_s uint8_t aad_sz; /**< Size in bytes of padded AAD data to prefix to the packet for CCM * or GCM processing */ + uint8_t hmac_key_sz; + /**< Size in bytes of HMAC key */ + } u2; uint8_t resrvd1; diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw_mmp.h b/quickassist/lookaside/firmware/include/icp_qat_fw_mmp.h index 458cfbff..8a88f014 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_fw_mmp.h +++ b/quickassist/lookaside/firmware/include/icp_qat_fw_mmp.h @@ -33,7 +33,7 @@ * Local constants ************************************************************************** */ -#define ICP_QAT_FW_PKE_INPUT_COUNT_MAX 7 +#define ICP_QAT_FW_PKE_INPUT_COUNT_MAX 8 /**< @ingroup icp_qat_fw_pke * Maximum number of input parameters in all PKE request */ #define ICP_QAT_FW_PKE_OUTPUT_COUNT_MAX 5 @@ -248,6 +248,90 @@ typedef struct icp_qat_fw_mmp_ecsm2_keyex_p2_input_s uint64_t yp; /**< yP = affine coordinate X of public key PB (4 qwords)*/ } icp_qat_fw_mmp_ecsm2_keyex_p2_input_t; +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for ECC P384 Variable Point Multiplication [k]P with + * DPA Protection , to be used when icp_qat_fw_pke_request_s::functionalityId + * is PKE_DPA_EC_POINT_MULTIPLICATION_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_s +{ + uint64_t xp; /**< xP = affine coordinate X of point P (6 qwords)*/ + uint64_t yp; /**< yP = affine coordinate Y of point P (6 qwords)*/ + uint64_t k; /**< k = scalar (6 qwords)*/ + uint64_t r; /**< cryptographically secure randomness (12 qwords)*/ +} icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for ECC P384 Generator Point Multiplication [k]G with + * DPA Protection , to be used when icp_qat_fw_pke_request_s::functionalityId + * is PKE_DPA_EC_GENERATOR_MULTIPLICATION_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_input_s +{ + uint64_t k; /**< k = scalar (6 qwords)*/ + uint64_t r; /**< cryptographically secure randomness (12 qwords)*/ +} icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for ECC P384 ECDSA Sign RS with DPA Protection , + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * PKE_DPA_ECDSA_SIGN_RS_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_s +{ + uint64_t k; /**< k = random value, > 0 and < n (order of G for P384) (6 + qwords)*/ + uint64_t e; /**< e = digest of the message to be signed (6 qwords)*/ + uint64_t d; /**< d = private key, 1 <= d <= n-1 (6 qwords)*/ + uint64_t rnd; /**< cryptographically secure randomness (6 qwords)*/ +} icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for RSA 3072 Decryption with DPA Protection , + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * PKE_DPA_RSA_DP1_3072. + */ +typedef struct icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s +{ + uint64_t c; /**< cipher text representative, < (p*q) (48 qwords)*/ + uint64_t d; /**< RSA private key (48 qwords)*/ + uint64_t e; /**< RSA public key, must be odd, >= 3 and <= (p*q)-1, with + GCD(e, p-1, q-1) = 1 (48 qwords)*/ + uint64_t p; /**< RSA parameter, prime, 2^1535 < p < 2^1536 (24 qwords)*/ + uint64_t q; /**< RSA parameter, prime, 2^1535 < q < 2^1536 (24 qwords)*/ + uint64_t r; /**< cryptographically secure randomness, + 4608 bits (72 qwords)*/ +} icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for RSA 3072 Decryption with DPA Protection with + * CRT, to be used when icp_qat_fw_pke_request_s::functionalityId is + * PKE_DPA_RSA_DP2_3072. + */ +typedef struct icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s +{ + uint64_t c; /**< cipher text representative, < (p*q) (48 qwords)*/ + uint64_t e; /**< RSA public key, must be odd, >= 3 and <= (p*q)-1, with + GCD(e, p-1, q-1) = 1 (48 qwords)*/ + uint64_t p; /**< RSA parameter, prime, 2^1535 < p < 2^1536 (24 qwords)*/ + uint64_t q; /**< RSA parameter, prime, 2^1535 < q < 2^1536 (24 qwords)*/ + uint64_t dp; /**< RSA parameter, < p-1 (24 qwords)*/ + uint64_t dq; /**< RSA parameter, < q-1 (24 qwords)*/ + uint64_t qinv; /**< RSA parameter, < p (24 qwords)*/ + uint64_t r; /**< cryptographically secure randomness, + 4608 bits (72 qwords)*/ +} icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t; + /** * @ingroup icp_qat_fw_mmp * @brief @@ -2889,6 +2973,244 @@ typedef struct icp_qat_fw_generator_multiplication_ed448_input_s uint64_t k; /**< k = scalar (8 qwords)*/ } icp_qat_fw_generator_multiplication_ed448_input_t; +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT ECC P521 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P521. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_s +{ + uint64_t kpt_wrapped; /**< (42 qwords) */ + uint64_t kpt_wrapping_context; /**< unwrap context (8 qwords) */ + uint64_t e; /**< (6 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT ECC P384 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P384. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_s +{ + uint64_t kpt_wrapped; /**< (42 qwords) */ + uint64_t kpt_wrapping_context; /**< unwrap context (8 qwords) */ + uint64_t e; /**< (6 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT ECC P256 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P256. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_s +{ + uint64_t kpt_wrapped; /**< (28 qwords) */ + uint64_t key_unwrap_context; /**< unwrap context (8 qwords) */ + uint64_t e; /**< (4 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 512 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_512. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_512_input_s +{ + uint64_t c; /**< cipher text representative, n (8 qwords) */ + uint64_t kpt_wrapped; /**< (16 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 1024 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_1024. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_s +{ + uint64_t c; /**< cipher text representative, n (16 qwords) */ + uint64_t kpt_wrapped; /**< (32 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 1536 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_1536. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_s +{ + uint64_t c; /**< cipher text representative, n (24 qwords) */ + uint64_t kpt_wrapped; /**< (48 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 2048 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_2048. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_s +{ + uint64_t c; /**< cipher text representative, n (32 qwords) */ + uint64_t kpt_wrapped; /**< (64 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 3072 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_3072. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_s +{ + uint64_t c; /**< cipher text representative, n (48 qwords) */ + uint64_t kpt_wrapped; /**< (96 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 4096 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_4096. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_s +{ + uint64_t c; /**< cipher text representative, n (64 qwords) */ + uint64_t kpt_wrapped; /**< (128 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 8192 decryption, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP1_8192. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_s +{ + uint64_t c; /**< cipher text representative, n (128 qwords) */ + uint64_t kpt_wrapped; /**< (256 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 512 decryption second form, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_512. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_512_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (8 qwords) */ + uint64_t kpt_wrapped; /**< (28 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_512_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 1024 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_1024. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (16 qwords) */ + uint64_t kpt_wrapped; /**< (56 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 1536 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_1536. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (24 qwords) */ + uint64_t kpt_wrapped; /**< (84 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 2048 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_2048. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (32 qwords) */ + uint64_t kpt_wrapped; /**< (112 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 3072 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_3072. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (48 qwords) */ + uint64_t kpt_wrapped; /**< (168 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 4096 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_4096. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (64 qwords) */ + uint64_t kpt_wrapped; /**< (224 qwords) */ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Input parameter list for KPT RSA 8192 decryption with CRT, + * to be used when icp_qat_fw_pke_request_s::functionalityId is + * #PKE_KPT_RSA_DP2_8192. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_s +{ + uint64_t c; /**< cipher text representative, (p*q) (128 qwords) */ + uint64_t kpt_wrapped; /**< (448 qwords)*/ + uint64_t kpt_unwrap_context; /**< unwrap context (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_t; + /** * @ingroup icp_qat_fw_mmp * @brief @@ -2954,6 +3276,23 @@ typedef union icp_qat_fw_mmp_input_param_u { /** ECC P256 ECDSA Sign RS */ icp_qat_fw_mmp_ecdsa_sign_rs_p256_input_t mmp_ecdsa_sign_rs_p256; + /** ECC P384 Variable Point Multiplication [k]P with DPA Protection */ + icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_t + mmp_dpa_ec_point_multiplication_p384; + + /** ECC P384 Generator Point Multiplication [k]G with DPA Protection */ + icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_input_t + mmp_dpa_ec_generator_multiplication_p384; + + /** ECC P384 ECDSA Sign RS with DPA Protection */ + icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_t mmp_dpa_ecdsa_sign_rs_p384; + + /** RSA 3072 Decryption with DPA Protection */ + icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_t mmp_dpa_rsa_dp1_3072; + + /** RSA 3072 Decryption with DPA Protection with CRT */ + icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_t mmp_dpa_rsa_dp2_3072; + /** Diffie-Hellman Modular exponentiation base 2 for 768-bit numbers */ icp_qat_fw_mmp_dh_g2_768_input_t mmp_dh_g2_768; @@ -3531,6 +3870,57 @@ typedef union icp_qat_fw_mmp_input_param_u { icp_qat_fw_generator_multiplication_ed448_input_t generator_multiplication_ed448; + /** KPT ECC P521 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_t mmp_kpt_ecdsa_sign_rs_p521; + + /** KPT ECC P384 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_t mmp_kpt_ecdsa_sign_rs_p384; + + /** KPT ECC 256 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_t mmp_kpt_ecdsa_sign_rs_p256; + + /** KPT RSA 512 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_512_input_t mmp_kpt_rsa_dp1_512; + + /** KPT RSA 1024 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_t mmp_kpt_rsa_dp1_1024; + + /** KPT RSA 1536 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_t mmp_kpt_rsa_dp1_1536; + + /** KPT RSA 2048 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_t mmp_kpt_rsa_dp1_2048; + + /** KPT RSA 3072 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_t mmp_kpt_rsa_dp1_3072; + + /** KPT RSA 4096 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_t mmp_kpt_rsa_dp1_4096; + + /** KPT RSA 8192 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_t mmp_kpt_rsa_dp1_8192; + + /** KPT RSA 512 decryption second form */ + icp_qat_fw_mmp_kpt_rsa_dp2_512_input_t mmp_kpt_rsa_dp2_512; + + /** KPT RSA 1024 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_t mmp_kpt_rsa_dp2_1024; + + /** KPT RSA 1536 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_t mmp_kpt_rsa_dp2_1536; + + /** KPT RSA 2048 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_t mmp_kpt_rsa_dp2_2048; + + /** KPT RSA 3072 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_t mmp_kpt_rsa_dp2_3072; + + /** KPT RSA 4096 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_t mmp_kpt_rsa_dp2_4096; + + /** KPT RSA 8192 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_t mmp_kpt_rsa_dp2_8192; + } icp_qat_fw_mmp_input_param_t; /** @@ -3730,6 +4120,70 @@ typedef struct icp_qat_fw_mmp_ecsm2_keyex_p2_output_s uint64_t yus; /**< yus = affine coordinate X of point (xU,yU) (4 qwords)*/ } icp_qat_fw_mmp_ecsm2_keyex_p2_output_t; +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for ECC P384 Variable Point Multiplication [k]P with + * DPA Protection, to be used when icp_qat_fw_pke_response_s::functionalityId + * is PKE_DPA_EC_POINT_MULTIPLICATION_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_output_s +{ + uint64_t xr; /**< xR = affine coordinate X of point [k]P (6 qwords)*/ + uint64_t yr; /**< yR = affine coordinate Y of point [k]P (6 qwords)*/ +} icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for ECC P384 Generator Point Multiplication [k]G + * with DPA Protection , to be used when + * icp_qat_fw_pke_response_s::functionalityId is + * PKE_DPA_EC_GENERATOR_MULTIPLICATION_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_output_s +{ + uint64_t xr; /**< xR = affine coordinate X of point [k]G (6 qwords)*/ + uint64_t yr; /**< yR = affine coordinate Y of point [k]G (6 qwords)*/ +} icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for ECC P384 ECDSA Sign RS with DPA Protection , + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * PKE_DPA_ECDSA_SIGN_RS_P384. + */ +typedef struct icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_output_s +{ + uint64_t r; /**< ECDSA signature r (6 qwords)*/ + uint64_t s; /**< ECDSA signature s (6 qwords)*/ +} icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for RSA 3072 Decryption with DPA Protection , + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * PKE_DPA_RSA_DP1_3072. + */ +typedef struct icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_s +{ + uint64_t m; /**< message representative, < n (48 qwords)*/ +} icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for RSA 3072 Decryption with DPA Protection with + * CRT, to be used when icp_qat_fw_pke_response_s::functionalityId is + * PKE_DPA_RSA_DP2_3072. + */ +typedef struct icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_s +{ + uint64_t m; /**< message representative, < n (48 qwords)*/ +} icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_t; + /** * @ingroup icp_qat_fw_mmp * @brief @@ -6011,6 +6465,213 @@ typedef struct icp_qat_fw_generator_multiplication_ed448_output_s (8 qwords)*/ } icp_qat_fw_generator_multiplication_ed448_output_t; +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT ECC P521 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P521. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_output_s +{ + uint64_t r; /**< ECDSA signature r (6 qwords) */ + uint64_t s; /**< ECDSA signature s (6 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT ECC P384 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P384. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_output_s +{ + uint64_t r; /**< ECDSA signature r (6 qwords) */ + uint64_t s; /**< ECDSA signature s (6 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT ECC P256 ECDSA Sign RS, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_ECDSA_SIGN_RS_P256. + */ +typedef struct icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_output_s +{ + uint64_t r; /**< ECDSA signature r (4 qwords) */ + uint64_t s; /**< ECDSA signature s (4 qwords) */ +} icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 512 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_512. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_512_output_s +{ + uint64_t m; /**< message representative, n (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_512_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 1024 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_1024. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_1024_output_s +{ + uint64_t m; /**< message representative, n (16 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_1024_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 1536 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_1536. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_1536_output_s +{ + uint64_t m; /**< message representative, n (24 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_1536_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 2048 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_2048. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_2048_output_s +{ + uint64_t m; /**< message representative, n (32 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_2048_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 3072 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_3072. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_3072_output_s +{ + uint64_t m; /**< message representative, n (48 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_3072_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 4096 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_4096. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_4096_output_s +{ + uint64_t m; /**< message representative, n (64 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_4096_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 8192 decryption, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP1_8192. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp1_8192_output_s +{ + uint64_t m; /**< message representative, n (128 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp1_8192_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 512 decryption second form, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_512. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_512_output_s +{ + uint64_t m; /**< message representative, (p*q) (8 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_512_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 1024 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_1024. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_1024_output_s +{ + uint64_t m; /**< message representative, (p*q) (16 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_1024_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 1536 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_1536. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_1536_output_s +{ + uint64_t m; /**< message representative, (p*q) (24 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_1536_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 2048 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_2048. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_2048_output_s +{ + uint64_t m; /**< message representative, (p*q) (32 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_2048_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 3072 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_3072. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_3072_output_s +{ + uint64_t m; /**< message representative, (p*q) (48 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_3072_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 4096 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_4096. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_4096_output_s +{ + uint64_t m; /**< message representative, (p*q) (64 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_4096_output_t; + +/** + * @ingroup icp_qat_fw_mmp + * @brief + * Output parameter list for KPT RSA 8192 decryption with CRT, + * to be used when icp_qat_fw_pke_response_s::functionalityId is + * #PKE_KPT_RSA_DP2_8192. + */ +typedef struct icp_qat_fw_mmp_kpt_rsa_dp2_8192_output_s +{ + uint64_t m; /**< message representative, (p*q) (128 qwords) */ +} icp_qat_fw_mmp_kpt_rsa_dp2_8192_output_t; + /** * @ingroup icp_qat_fw_mmp * @brief @@ -6051,6 +6712,23 @@ typedef union icp_qat_fw_mmp_output_param_u { /** ECC SM2 key exchange phase2 */ icp_qat_fw_mmp_ecsm2_keyex_p2_output_t mmp_ecsm2_keyex_p2; + /** ECC P384 Variable Point Multiplication [k]P with DPA Protection */ + icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_output_t + mmp_dpa_ec_point_multiplication_p384; + + /** ECC P384 Generator Point Multiplication [k]G with DPA Protection */ + icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_output_t + mmp_dpa_ec_generator_multiplication_p384; + + /** ECC P384 ECDSA Sign RS with DPA Protection */ + icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_output_t mmp_dpa_ecdsa_sign_rs_p384; + + /** RSA 3072 Decryption with DPA Protection */ + icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_t mmp_dpa_rsa_dp1_3072; + + /** RSA 3072 Decryption with DPA Protection with CRT */ + icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_t mmp_dpa_rsa_dp2_3072; + /** Initialisation sequence */ icp_qat_fw_mmp_init_output_t mmp_init; @@ -6653,6 +7331,57 @@ typedef union icp_qat_fw_mmp_output_param_u { icp_qat_fw_generator_multiplication_ed448_output_t generator_multiplication_ed448; + /** KPT ECC P521 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_output_t mmp_kpt_ecdsa_sign_rs_p521; + + /** KPT ECC P384 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_output_t mmp_kpt_ecdsa_sign_rs_p384; + + /** KPT ECC P256 ECDSA Sign RS */ + icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_output_t mmp_kpt_ecdsa_sign_rs_p256; + + /** KPT RSA 512 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_512_output_t mmp_kpt_rsa_dp1_512; + + /** KPT RSA 1024 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_1024_output_t mmp_kpt_rsa_dp1_1024; + + /** KPT RSA 1536 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_1536_output_t mmp_kpt_rsa_dp1_1536; + + /** KPT RSA 2048 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_2048_output_t mmp_kpt_rsa_dp1_2048; + + /** KPT RSA 3072 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_3072_output_t mmp_kpt_rsa_dp1_3072; + + /** KPT RSA 4096 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_4096_output_t mmp_kpt_rsa_dp1_4096; + + /** KPT RSA 8192 decryption */ + icp_qat_fw_mmp_kpt_rsa_dp1_8192_output_t mmp_kpt_rsa_dp1_8192; + + /** KPT RSA 512 decryption second form */ + icp_qat_fw_mmp_kpt_rsa_dp2_512_output_t mmp_kpt_rsa_dp2_512; + + /** KPT RSA 1024 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_1024_output_t mmp_kpt_rsa_dp2_1024; + + /** KPT RSA 1536 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_1536_output_t mmp_kpt_rsa_dp2_1536; + + /** KPT RSA 2048 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_2048_output_t mmp_kpt_rsa_dp2_2048; + + /** KPT RSA 3072 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_3072_output_t mmp_kpt_rsa_dp2_3072; + + /** KPT RSA 4096 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_4096_output_t mmp_kpt_rsa_dp2_4096; + + /** KPT RSA 8192 decryption with CRT */ + icp_qat_fw_mmp_kpt_rsa_dp2_8192_output_t mmp_kpt_rsa_dp2_8192; + } icp_qat_fw_mmp_output_param_t; #endif /* __ICP_QAT_FW_MMP__ */ diff --git a/quickassist/lookaside/firmware/include/icp_qat_fw_mmp_ids.h b/quickassist/lookaside/firmware/include/icp_qat_fw_mmp_ids.h index 6445ba6e..abd69d4a 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_fw_mmp_ids.h +++ b/quickassist/lookaside/firmware/include/icp_qat_fw_mmp_ids.h @@ -1926,6 +1926,251 @@ * @li 2 output parameters : @link icp_qat_fw_mmp_ecsm2_keyex_p2_output_s::xus * xus @endlink @link icp_qat_fw_mmp_ecsm2_keyex_p2_output_s::yus yus @endlink */ +#define PKE_DPA_EC_POINT_MULTIPLICATION_P384 0x000f0fd0 +/**< Functionality ID for ECC P384 Variable Point Multiplication [k]P with DPA + * Protection + * @li 4 input parameters : + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_s::xp xp + * @endlink + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_s::yp yp + * @endlink + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_s::k k + * @endlink + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_input_s::r r + * @endlink + * @li 2 output parameters : + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_output_s::xr xr + * @endlink + * @link icp_qat_fw_mmp_dpa_ec_point_multiplication_p384_output_s::yr yr + * @endlink + */ +#define PKE_DPA_EC_GENERATOR_MULTIPLICATION_P384 0x000f0fc0 +/**< Functionality ID for ECC P384 Generator Point Multiplication [k]G with DPA + * Protection + * @li 2 input parameters : + * @link icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_input_s::k k + * @endlink + * @link icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_input_s::r r + * @endlink + * @li 2 output parameters : + * @link icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_output_s::xr + * xr @endlink + * @link icp_qat_fw_mmp_dpa_ec_generator_multiplication_p384_output_s::yr + * yr @endlink + */ +#define PKE_DPA_ECDSA_SIGN_RS_P384 0x000f0fb0 +/**< Functionality ID for ECC P384 ECDSA Sign RS with DPA Protection + * @li 4 input parameters : + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_s::k k @endlink + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_s::e e @endlink + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_s::d d @endlink + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_input_s::rnd rnd @endlink + * @li 2 output parameters : + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_output_s::r r @endlink + * @link icp_qat_fw_mmp_dpa_ecdsa_sign_rs_p384_output_s::s s @endlink + */ +#define PKE_DPA_RSA_DP1_3072 0x000f0ff0 +/**< Functionality ID for RSA 3072 Decryption with DPA Protection + * @li 6 input parameters : + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::c c @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::d d @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::e e @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::p p @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::q q @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_input_s::r r @endlink + * @li 1 output parameters : + * @link icp_qat_fw_mmp_dpa_rsa_dp1_3072_output_s::m m @endlink + */ +#define PKE_DPA_RSA_DP2_3072 0x000f0fe0 +/**< Functionality ID for RSA 3072 Decryption with DPA Protection with CRT + * @li 8 input parameters : + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::c c @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::e e @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::p p @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::q q @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::dp dp @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::dq dq @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::qinv qinv @endlink + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_input_s::r r @endlink + * @li 1 output parameters : + * @link icp_qat_fw_mmp_dpa_rsa_dp2_3072_output_s::m m @endlink + */ +#define PKE_KPT_ECDSA_SIGN_RS_P521 0xb6563896 +/**< Functionality ID for ECC P521 ECDSA Sign RS + * @li 3 input parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_s::kpt_wrapped kpt_wrapped + * @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_s::kpt_wrapping_context + * kpt_wrapping_context @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_input_s::e e @endlink + * @li 2 output parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_output_s::r r @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p521_output_s::s s @endlink + */ +#define PKE_KPT_ECDSA_SIGN_RS_P384 0x22143876 +/**< Functionality ID for ECC P384 ECDSA Sign RS + * @li 3 input parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_s::kpt_wrapped kpt_wrapped + * @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_s::kpt_wrapping_context + * kpt_wrapping_context @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_input_s::e e @endlink + * @li 2 output parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_output_s::r r @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p384_output_s::s s @endlink + */ +#define PKE_KPT_ECDSA_SIGN_RS_P256 0x8d153856 +/**< Functionality ID for ECC KPT P256 ECDSA Sign RS + * @li 3 input parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_s::kpt_wrapped kpt_wrapped + * @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_s::key_unwrap_context + * key_unwrap_context @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_input_s::e e @endlink + * @li 2 output parameters : @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_output_s::r r @endlink @link + * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_p256_output_s::s s @endlink + */ +#define PKE_KPT_RSA_DP1_512 0x1b1c3696 +/**< Functionality ID for KPT RSA 512 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_512_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_512_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_512_input_s::kpt_unwrap_context kpt_unwrap_context + * @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_512_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_1024 0x2d1d36b6 +/**< Functionality ID for KPT RSA 1024 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_1024_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_1024_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_1536 0x451d36d6 +/**< Functionality ID for KPT RSA 1536 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_1536_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_1536_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_2048 0x661936f6 +/**< Functionality ID for KPT RSA 2048 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_2048_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_2048_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_3072 0x751d3716 +/**< Functionality ID for KPT RSA 3072 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_3072_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_3072_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_4096 0x9d1d3736 +/**< Functionality ID for KPT RSA 4096 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_4096_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_4096_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP1_8192 0xbe203756 +/**< Functionality ID for KPT RSA 8192 Decryption + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp1_8192_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp1_8192_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_512 0x241d3776 +/**< Functionality ID for RSA 512 decryption second form + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_512_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_512_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_512_input_s::kpt_unwrap_context kpt_unwrap_context + * @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_512_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_1024 0x4e1d3796 +/**< Functionality ID for RSA 1024 Decryption with CRT + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_1024_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_1024_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_1536 0x762b37b6 +/**< Functionality ID for KPT RSA 1536 Decryption with CRT + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_1536_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_1536_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_2048 0xa41a37d6 +/**< Functionality ID for RSA 2048 Decryption with CRT + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_2048_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_2048_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_3072 0xd41a37f6 +/**< Functionality ID for + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_3072_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_3072_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_4096 0xd22a3816 +/**< Functionality ID for RSA 4096 Decryption with CRT + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_4096_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_4096_output_s::m m + * @endlink + */ +#define PKE_KPT_RSA_DP2_8192 0xae383836 +/**< Functionality ID for RSA 8192 Decryption with CRT + * @li 3 input parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_s::c c + * @endlink @link icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_s::kpt_wrapped + * kpt_wrapped @endlink @link + * icp_qat_fw_mmp_kpt_rsa_dp2_8192_input_s::kpt_unwrap_context + * kpt_unwrap_context @endlink + * @li 1 output parameters : @link icp_qat_fw_mmp_kpt_rsa_dp2_8192_output_s::m m + * @endlink + */ #define PKE_LIVENESS 0x00000001 /**< Functionality ID for PKE_LIVENESS * @li 0 input parameter(s) diff --git a/quickassist/lookaside/firmware/include/icp_qat_hw.h b/quickassist/lookaside/firmware/include/icp_qat_hw.h index df2998ac..49d97b2d 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_hw.h +++ b/quickassist/lookaside/firmware/include/icp_qat_hw.h @@ -542,25 +542,15 @@ typedef struct icp_qat_hw_auth_setup_s #define ICP_QAT_HW_SHA3_STATEFUL_STATE1_SZ 200 /** <@ingroup icp_cpm_hw_defs * State1 block size for stateful SHA3 processing*/ -#define ICP_QAT_HW_ZUC_256_MAC_32_STATE1_SZ 16 +#define ICP_QAT_HW_ZUC_256_MAC_32_STATE1_SZ 8 /**< @ingroup icp_cpm_hw_defs * State1 block size for ZUC-256 with 32-bit MAC */ -#define ICP_QAT_HW_ZUC_256_MAC_64_STATE1_SZ 16 +#define ICP_QAT_HW_ZUC_256_MAC_64_STATE1_SZ 8 /**< @ingroup icp_cpm_hw_defs * State1 block size for ZUC-256 with 64-bit MAC */ #define ICP_QAT_HW_ZUC_256_MAC_128_STATE1_SZ 16 /**< @ingroup icp_cpm_hw_defs * State1 block size for ZUC-256 with 128-bit MAC */ -#define ICP_QAT_HW_ZUC_256_MAC_32_UPDATE_STATE1_SZ 8 -/**< @ingroup icp_cpm_hw_defs - * State1 block size for updated ZUC-256 with 32-bit MAC (Gen6). - * This macro is added for Gen6 and marked as _UPDATE_ since - * its value differs from the one maintained for older devices */ -#define ICP_QAT_HW_ZUC_256_MAC_64_UPDATE_STATE1_SZ 8 -/**< @ingroup icp_cpm_hw_defs - * State1 block size for updated ZUC-256 with 64-bit MAC (Gen6). - * This macro is added for Gen6 and marked as _UPDATE_ since - * its value differs from the one maintained for older devices */ #define ICP_QAT_HW_AES_CMAC_STATE1_SZ 16 /**< @ingroup icp_cpm_hw_defs * State1 block size for AES-128/192/256 CMAC */ @@ -646,7 +636,7 @@ typedef struct icp_qat_hw_auth_setup_s #define ICP_QAT_HW_SM3_STATE2_SZ 32 /**< @ingroup icp_qat_hw_defs * State2 block size for SM3 */ -#define ICP_QAT_HW_ZUC_256_STATE2_SZ 56 +#define ICP_QAT_HW_ZUC_256_STATE2_SZ 48 /**< @ingroup icp_qat_hw_defs * State2 block size for ZUC-256 with 32/64/128 bit MAC */ #define ICP_QAT_HW_AES_128_CMAC_STATE2_SZ 16 @@ -661,9 +651,6 @@ typedef struct icp_qat_hw_auth_setup_s #define ICP_QAT_HW_NIAX_STATE2_SZ 48 /**< @ingroup icp_cpm_hw_defs * State2 block size for NIAx (SNOW5G, AES-256, ZUC-256) */ -#define ICP_QAT_HW_ZUC_256_UPDATE_STATE2_SZ 48 -/**< @ingroup icp_cpm_hw_defs - * State2 block size for updated ZUC-256 MAC-32/64/128 (Gen6) */ /* ************************************************************************* */ /* ************************************************************************* */ @@ -1153,9 +1140,10 @@ typedef enum { #define ICP_QAT_HW_ZUC_256_KEY_SZ 32 /**< @ingroup icp_cpm_hw_defs * Define the key size for ZUC-256 */ -#define ICP_QAT_HW_ZUC_256_IV_SZ 24 +#define ICP_QAT_HW_ZUC_256_IV_SZ 16 /**< @ingroup icp_cpm_hw_defs - * Define the iv size for ZUC-256 */ + * Define the iv size for ZUC-256 (CPM5.1w) + */ /* SNOW5G */ #define ICP_QAT_HW_SNOW_5G_KEY_SZ 32 /**< @ingroup icp_cpm_hw_defs @@ -1164,9 +1152,6 @@ typedef enum { #define ICP_QAT_HW_SNOW_5G_IV_SZ 16 /**< @ingroup icp_cpm_hw_defs * Define the iv size for SNOW_5G */ -#define ICP_QAT_HW_ZUC_256_UPDATE_IV_SZ 16 -/**< @ingroup icp_cpm_hw_defs - * Define the iv size for updated ZUC-256 (Gen6) */ /* * SHRAM constants definitions diff --git a/quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h b/quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h index 0fd89e50..98c8a223 100644 --- a/quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h +++ b/quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h @@ -157,6 +157,10 @@ typedef enum * @ingroup icp_qat_hw_defs * @description * Enumeration of possible LBMS field values + * Note, this enum is reflected on the QuickAssist API and the library + * depends on both having the same values. So the existing values must + * never change and if this enum is extended then CpaDcCompLZ4BlockMaxSize + * and icp_qat_hw_comp_51_bms_t must also be extended. *****************************************************************************/ typedef enum { diff --git a/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp.h b/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp.h new file mode 100644 index 00000000..3f995ee0 --- /dev/null +++ b/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp.h @@ -0,0 +1,207 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ + +/** + ***************************************************************************** + * @file icp_qat_hw_51_comp.h + * @defgroup ICP QAT HW accessors for using the for 5.1 Compression Slice + * definitions + * @ingroup icp_qat_hw_51_comp + * @description + * This file documents definitions for the QAT5.1 HW COMP SLICE + * + *****************************************************************************/ + +#ifndef _ICP_QAT_HW_51_COMP_H_ +#define _ICP_QAT_HW_51_COMP_H_ + +#include "icp_qat_hw_51_comp_defs.h" /* For HW definitions */ +#include "icp_qat_fw.h" /* For Set Field Macros. */ + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Definition of the HW config CSR. This representation has to be further +* processed by the corresponding config build function. +* +*****************************************************************************/ +typedef struct icp_qat_hw_comp_51_config_csr_lower_s +{ + /* Fields programmable directly by the SW. */ + icp_qat_hw_comp_51_abd_t abd; + icp_qat_hw_comp_51_lllbd_ctrl_t lllbd; + icp_qat_hw_comp_51_search_depth_t sd; + /* Advanced HW control (set to default values) */ + icp_qat_hw_comp_51_min_match_control_t mmctrl; + icp_qat_hw_comp_51_lz4_block_checksum_t lbc; +} icp_qat_hw_comp_51_config_csr_lower_t; + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Build the longword as expected by the HW +* +*****************************************************************************/ +static inline uint32_t ICP_QAT_FW_COMP_51_BUILD_CONFIG_LOWER( + icp_qat_hw_comp_51_config_csr_lower_t csr) +{ + uint32_t val32 = 0; + + /* Programmable values */ + QAT_FIELD_SET(val32, + csr.abd, + ICP_QAT_HW_COMP_51_CONFIG_CSR_ABD_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_ABD_MASK); + + QAT_FIELD_SET(val32, + csr.lllbd, + ICP_QAT_HW_COMP_51_CONFIG_CSR_LLLBD_CTRL_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_LLLBD_CTRL_MASK); + + QAT_FIELD_SET(val32, + csr.sd, + ICP_QAT_HW_COMP_51_CONFIG_CSR_SEARCH_DEPTH_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_SEARCH_DEPTH_MASK); + + QAT_FIELD_SET(val32, + csr.mmctrl, + ICP_QAT_HW_COMP_51_CONFIG_CSR_MIN_MATCH_CONTROL_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_MIN_MATCH_CONTROL_MASK); + + QAT_FIELD_SET(val32, + csr.lbc, + ICP_QAT_HW_COMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_MASK); + + return val32; +} + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Definition of the HW config CSR. This representation has to be further +* processed by the corresponding config build function. +* +*****************************************************************************/ +typedef struct icp_qat_hw_comp_51_config_csr_upper_s +{ + icp_qat_hw_comp_51_dmm_algorithm_t edmm; + icp_qat_hw_comp_51_bms_t bms; + icp_qat_hw_comp_51_scb_mode_reset_mask_t scb_mode_reset; +} icp_qat_hw_comp_51_config_csr_upper_t; + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Build the longword as expected by the HW +* +*****************************************************************************/ +static inline uint32_t ICP_QAT_FW_COMP_51_BUILD_CONFIG_UPPER( + icp_qat_hw_comp_51_config_csr_upper_t csr) +{ + uint32_t val32 = 0; + + QAT_FIELD_SET(val32, + csr.edmm, + ICP_QAT_HW_COMP_51_CONFIG_CSR_DMM_ALGORITHM_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_DMM_ALGORITHM_MASK); + + QAT_FIELD_SET(val32, + csr.bms, + ICP_QAT_HW_COMP_51_CONFIG_CSR_BMS_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_BMS_MASK); + + QAT_FIELD_SET(val32, + csr.scb_mode_reset, + ICP_QAT_HW_COMP_51_CONFIG_CSR_SCB_MODE_RESET_MASK_BITPOS, + ICP_QAT_HW_COMP_51_CONFIG_CSR_SCB_MODE_RESET_MASK_MASK); + + return val32; +} + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Definition of the HW config CSR. This representation has to be further +* processed by the corresponding config build function. +* +*****************************************************************************/ +typedef struct icp_qat_hw_decomp_51_config_csr_lower_s +{ + /* Advanced HW control (set to default values) */ + icp_qat_hw_decomp_51_lz4_block_checksum_t lbc; +} icp_qat_hw_decomp_51_config_csr_lower_t; + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Build the longword as expected by the HW +* +*****************************************************************************/ +static inline uint32_t ICP_QAT_FW_DECOMP_51_BUILD_CONFIG_LOWER( + icp_qat_hw_decomp_51_config_csr_lower_t csr) +{ + uint32_t val32 = 0; + + QAT_FIELD_SET(val32, + csr.lbc, + ICP_QAT_HW_DECOMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_BITPOS, + ICP_QAT_HW_DECOMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_MASK); + + return val32; +} + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Definition of the HW config CSR. This representation has to be further +* processed by the corresponding config build function. +* +*****************************************************************************/ +typedef struct icp_qat_hw_decomp_51_config_csr_upper_s +{ + /* Advanced HW control (set to default values) */ + icp_qat_hw_decomp_51_bms_t bms; +} icp_qat_hw_decomp_51_config_csr_upper_t; + +/** +***************************************************************************** +* @ingroup icp_qat_fw_comn +* +* @description +* Build the longword as expected by the HW +* +*****************************************************************************/ +static inline uint32_t ICP_QAT_FW_DECOMP_51_BUILD_CONFIG_UPPER( + icp_qat_hw_decomp_51_config_csr_upper_t csr) +{ + uint32_t val32 = 0; + + QAT_FIELD_SET(val32, + csr.bms, + ICP_QAT_HW_DECOMP_51_CONFIG_CSR_BMS_BITPOS, + ICP_QAT_HW_DECOMP_51_CONFIG_CSR_BMS_MASK); + + return val32; +} + +#endif /* ICP_QAT_HW_51_COMP_H_ */ diff --git a/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp_defs.h b/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp_defs.h new file mode 100644 index 00000000..b5e9508c --- /dev/null +++ b/quickassist/lookaside/firmware/include/icp_qat_hw_51_comp_defs.h @@ -0,0 +1,753 @@ +/* + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + */ +/* + **************************************************************************** + * @file icp_qat_hw_51_comp_defs.h, (autogenerated at 07-27-23 23:18) + * @defgroup icp_qat_hw_comp_51 + * @ingroup icp_qat_hw_comp_51 + * @description + * This file represents the HW configuration CSR definitions + **************************************************************************** + */ + +#ifndef _ICP_QAT_HW_51_COMP_DEFS_H +#define _ICP_QAT_HW_51_COMP_DEFS_H + +/*****************************************************************************/ +/* Slice Operation Mode (SOM) - located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SOM_CONTROL_BITPOS 28 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SOM_CONTROL_MASK 0x3 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SOM_CONTROL field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SOM_CONTROL_NORMAL_MODE = 0x0, + /* Normal mode. */ + ICP_QAT_HW_COMP_51_SOM_CONTROL_DICTIONARY_MODE = 0x1, + /* Dictionary mode */ + ICP_QAT_HW_COMP_51_SOM_CONTROL_INPUT_CRC = 0x2, + /* Input CRC Mode */ + ICP_QAT_HW_COMP_51_SOM_CONTROL_RESERVED_MODE = 0x3, + /* Reserved. */ +} icp_qat_hw_comp_51_som_control_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SOM_CONTROL_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SOM_CONTROL_NORMAL_MODE + +/*****************************************************************************/ +/* Skip Hash Read, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_RD_CONTROL_BITPOS 27 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_RD_CONTROL_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SKIP_HASH_RD_CONTROL field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SKIP_HASH_RD_CONTROL_NO_SKIP = 0x0, + /* When set to 0, hash reads are not skipped. */ + ICP_QAT_HW_COMP_51_SKIP_HASH_RD_CONTROL_SKIP_HASH_READS = 0x1, + /* Hash reads are skipped. */ +} icp_qat_hw_comp_51_skip_hash_rd_control_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_RD_CONTROL_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SKIP_HASH_RD_CONTROL_NO_SKIP + +/*****************************************************************************/ +/* Bypass Compression, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYPASS_COMPRESSION_BITPOS 25 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYPASS_COMPRESSION_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible BYPASS_COMPRESSION field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_BYPASS_COMPRESSION_DISABLED = 0x0, + /* 0 - CnV slice is used to process a compression job */ + ICP_QAT_HW_COMP_51_BYPASS_COMPRESSION_ENABLED = 0x1, + /* 0 - CnV slice is used to process a decompression job */ +} icp_qat_hw_comp_51_bypass_compression_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYPASS_COMPRESSION_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_BYPASS_COMPRESSION_DISABLED + +/*****************************************************************************/ +/* Delayed Match Mode Algorithm, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_DMM_ALGORITHM_BITPOS 22 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_DMM_ALGORITHM_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible DMM_ALGORITHM field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_EDMM_ENABLED = 0x0, + /* 0 - EXTENDED_DELAY_MATCH_MODE enabled */ + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_ZSTD_DMM_LITE = 0x1, + /* 1 - ZSTD DMM-Lite enabled */ +} icp_qat_hw_comp_51_dmm_algorithm_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_DMM_ALGORITHM_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_DMM_ALGORITHM_EDMM_ENABLED + +/*****************************************************************************/ +/* CHKN_BIT: Disable Token Fusion (INTERNAL_ONLY), located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_TOKEN_FUSION_INTERNAL_ONLY_BITPOS 21 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_TOKEN_FUSION_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible TOKEN_FUSION_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_TOKEN_FUSION_INTERNAL_ONLY_ENABLED = 0x0, + /* 0 - Token Fusion is enabled */ + ICP_QAT_HW_COMP_51_TOKEN_FUSION_INTERNAL_ONLY_DISABLED = 0x1, + /* 0 - Token Fusion is disabled */ +} icp_qat_hw_comp_51_token_fusion_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_TOKEN_FUSION_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_TOKEN_FUSION_INTERNAL_ONLY_ENABLED + +/*****************************************************************************/ +/* Block Maximum Size (BMS), located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BMS_BITPOS 19 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BMS_MASK 0x3 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible BMS field values + * Note, this enum is reflected on the QuickAssist API and the library + * depends on both having the same values. So the existing values must + * never change and if this enum is extended then CpaDcCompLZ4BlockMaxSize + * and icp_qat_hw_comp_20_lbms_t must also be extended. + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_BMS_BMS_64KB = 0x0, + /* Block Max Size (BMS) == 64 KB - LZ4, ZSTD, ILZ77, LZ4s=don't care */ + ICP_QAT_HW_COMP_51_BMS_BMS_256KB = 0x1, + /* Block Max Size (BMS) == 256 KB - LZ4 only */ + ICP_QAT_HW_COMP_51_BMS_BMS_1MB = 0x2, + /* Block Max Size (BMS) == 1 MB - LZ4 only */ + ICP_QAT_HW_COMP_51_BMS_BMS_4MB = 0x3, + /* Block Max Size (BMS) == 4 MB - LZ4 only */ +} icp_qat_hw_comp_51_bms_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BMS_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_BMS_BMS_64KB + +/*****************************************************************************/ +/* SCB Mode Reset Mask, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SCB_MODE_RESET_MASK_BITPOS 18 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SCB_MODE_RESET_MASK_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SCB_MODE_RESET_MASK field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SCB_MODE_RESET_MASK_DO_NOT_RESET_HB_HT = 0x0, + /* Do not reset HB, HT at the block boundary */ + ICP_QAT_HW_COMP_51_SCB_MODE_RESET_MASK_RESET_HB_HT = 0x1, + /* Reset HB, HT at the block boundary */ +} icp_qat_hw_comp_51_scb_mode_reset_mask_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SCB_MODE_RESET_MASK_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SCB_MODE_RESET_MASK_DO_NOT_RESET_HB_HT + +/*****************************************************************************/ +/* ZSTD Frame Gen/Decode Enable, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_BITPOS 2 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible ZSTD_FRAME_GEN_DEC_EN field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_DISABLE = 0x0, + /* ZSTD Frame header and content checksum generation/decode disabled */ + ICP_QAT_HW_COMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_ENABLE = 0x1, + /* ZSTD Frame header and content checksum generation/decode enabled */ +} icp_qat_hw_comp_51_zstd_frame_gen_dec_en_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_ENABLE + +/*****************************************************************************/ +/* CnV Disable, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_CNV_DISABLE_BITPOS 1 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_CNV_DISABLE_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible CNV_DISABLE field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_CNV_DISABLE_CNV_ENABLED = 0x0, + /* CNV is enabled */ + ICP_QAT_HW_COMP_51_CNV_DISABLE_CNV_DISABLED = 0x1, + /* CNV is disabled */ +} icp_qat_hw_comp_51_cnv_disable_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_CNV_DISABLE_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_CNV_DISABLE_CNV_ENABLED + +/*****************************************************************************/ +/* Auto Select Best Disable, located in upper 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ASB_DISABLE_BITPOS 0 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ASB_DISABLE_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible ASB_DISABLE field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_ASB_DISABLE_ASB_ENABLED = 0x0, + /* ASB is enabled */ + ICP_QAT_HW_COMP_51_ASB_DISABLE_ASB_DISABLED = 0x1, + /* ASB is disabled */ +} icp_qat_hw_comp_51_asb_disable_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ASB_DISABLE_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_ASB_DISABLE_ASB_ENABLED + +/*****************************************************************************/ +/* CHKN_BIT: Speculative Decoder Disable (INTERNAL_ONLY), located in lower 32 + * bit + */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_BITPOS 21 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SPEC_DECODER_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SPEC_DECODER_INTERNAL_ONLY_NORMAL = 0x0, + /* 0 - Normal Mode using Speculative Decoder */ + ICP_QAT_HW_COMP_51_SPEC_DECODER_INTERNAL_ONLY_DISABLED = 0x1, + /* 1 - Speculative Decoder disabled */ +} icp_qat_hw_comp_51_spec_decoder_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SPEC_DECODER_INTERNAL_ONLY_NORMAL + +/*****************************************************************************/ +/* CHKN_BIT: Mini XCAM Disable (INTERNAL_ONLY), located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_BITPOS 20 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible MINI_XCAM_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_MINI_XCAM_INTERNAL_ONLY_NORMAL = 0x0, + /* 0 - Normal Mode using Speculative Decoder */ + ICP_QAT_HW_COMP_51_MINI_XCAM_INTERNAL_ONLY_DISABLED = 0x1, + /* 1 - Speculative Decoder disabled */ +} icp_qat_hw_comp_51_mini_xcam_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_MINI_XCAM_INTERNAL_ONLY_NORMAL + +/*****************************************************************************/ +/* CHKN_BIT: Disable ZSTD Repeated_Offset encoding (INTERNAL_ONLY), located in + * lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_REP_OFF_ENC_INTERNAL_ONLY_BITPOS 19 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_REP_OFF_ENC_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible REP_OFF_ENC_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_REP_OFF_ENC_INTERNAL_ONLY_ENABLED = 0x0, + /* 0 - Repeated_Offset encoding is enabled */ + ICP_QAT_HW_COMP_51_REP_OFF_ENC_INTERNAL_ONLY_DISABLED = 0x1, + /* 1 - Repeated_Offset encoding is disabled */ +} icp_qat_hw_comp_51_rep_off_enc_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_REP_OFF_ENC_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_REP_OFF_ENC_INTERNAL_ONLY_ENABLED + +/*****************************************************************************/ +/* Enable Programmable Block Drop (INTERNAL_ONLY), located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_PROG_BLOCK_DROP_INTERNAL_ONLY_BITPOS 18 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_PROG_BLOCK_DROP_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible PROG_BLOCK_DROP_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_PROG_BLOCK_DROP_INTERNAL_ONLY_DISABLE = 0x0, + /* 0 - Disable Programmable Block Drop */ + ICP_QAT_HW_COMP_51_PROG_BLOCK_DROP_INTERNAL_ONLY_ENABLE = 0x1, + /* 1 - Enable Programmable Block Drop */ +} icp_qat_hw_comp_51_prog_block_drop_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_PROG_BLOCK_DROP_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_PROG_BLOCK_DROP_INTERNAL_ONLY_DISABLE + +/*****************************************************************************/ +/* CHKN_BIT: Enable skip hash override (INTERNAL_ONLY), located in lower 32 bit + */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_BITPOS 17 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SKIP_HASH_OVERRIDE_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_DETERMINE_HASH_PARAMS = + 0x0, + /* 0 - HW will determine param values based on SD and algo */ + ICP_QAT_HW_COMP_51_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_OVERRIDE_HASH_PARAMS = + 0x1, + /* 1 - HW will use the override values provided in cfg register */ +} icp_qat_hw_comp_51_skip_hash_override_internal_only_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SKIP_HASH_OVERRIDE_INTERNAL_ONLY_DETERMINE_HASH_PARAMS + +/*****************************************************************************/ +/* History Buffer Size, located in lower 32 bit + */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_HBS_BITPOS 14 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_HBS_MASK 0x7 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible HBS field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_HBS_32KB = 0x0, + /* 000b - 32KB (DEFLATE) */ + ICP_QAT_HW_COMP_51_HBS_64KB = 0x1, + /* 001b - 64KB (LZ4, LZ4s, ZSTD) */ +} icp_qat_hw_comp_51_hbs_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_HBS_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_HBS_32KB + +/*****************************************************************************/ +/* Adaptive Block Drop Disable, located in lower 32 bit + */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ABD_BITPOS 13 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ABD_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible ABD field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_ABD_ABD_ENABLED = 0x0, + /* 0b - Feature enabled. */ + ICP_QAT_HW_COMP_51_ABD_ABD_DISABLED = 0x1, + /* 1b - Feature disabled. */ +} icp_qat_hw_comp_51_abd_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_ABD_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_ABD_ABD_ENABLED + +/*****************************************************************************/ +/* Literal+Length Limit Block Drop Disable , located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LLLBD_CTRL_BITPOS 12 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LLLBD_CTRL_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible LLLBD_CTRL field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_LLLBD_CTRL_LLLBD_ENABLED = 0x0, + /* 0b - Feature enabled. */ + ICP_QAT_HW_COMP_51_LLLBD_CTRL_LLLBD_DISABLED = 0x1, + /* 1b - Feature disabled. */ +} icp_qat_hw_comp_51_lllbd_ctrl_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LLLBD_CTRL_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_LLLBD_CTRL_LLLBD_ENABLED + +/*****************************************************************************/ +/* Search Depth (SD), located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SEARCH_DEPTH_BITPOS 8 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SEARCH_DEPTH_MASK 0xf +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SEARCH_DEPTH field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_1 = 0x1, + /* 0001b - Level 1 (search depth = 2^1 = 2) */ + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_6 = 0x3, + /* 0011b - Level 6 (search depth = 2^3 = 8) */ + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_9 = 0x4, + /* 0100b - Level 9, non-deflate algos (search depth = 2^4 = 16) */ + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_10 = 0x4, + /* 0100b - Level 10, deflate only (search depth = 2^4 = 16) */ +} icp_qat_hw_comp_51_search_depth_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SEARCH_DEPTH_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SEARCH_DEPTH_LEVEL_1 + +/*****************************************************************************/ +/* Compression Format (Also See CMD ID), located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_FORMAT_BITPOS 5 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_FORMAT_MASK 0x7 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible FORMAT field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_FORMAT_ILZ77 = 0x1, + /* iLZ77 (Deflate) */ + ICP_QAT_HW_COMP_51_FORMAT_LZ4 = 0x2, + /* LZ4 */ + ICP_QAT_HW_COMP_51_FORMAT_LZ4s = 0x3, + /* LZ4s */ + ICP_QAT_HW_COMP_51_FORMAT_ZSTD = 0x4, + /* ZSTD */ +} icp_qat_hw_comp_51_format_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_FORMAT_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_FORMAT_ILZ77 + +/*****************************************************************************/ +/* Min Match, located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MIN_MATCH_CONTROL_BITPOS 4 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MIN_MATCH_CONTROL_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible MIN_MATCH_CONTROL field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_MIN_MATCH_CONTROL_MATCH_3B = 0x0, + /* 0 - Match 3 B */ + ICP_QAT_HW_COMP_51_MIN_MATCH_CONTROL_MATCH_4B = 0x1, + /* 1 - Match 4 B */ +} icp_qat_hw_comp_51_min_match_control_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_MIN_MATCH_CONTROL_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_MIN_MATCH_CONTROL_MATCH_3B + +/*****************************************************************************/ +/* Skip Hash Collision, located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_COLLISION_BITPOS 3 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_COLLISION_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SKIP_HASH_COLLISION field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SKIP_HASH_COLLISION_ALLOW = 0x0, + /* When set to 0, hash collisions are allowed. */ + ICP_QAT_HW_COMP_51_SKIP_HASH_COLLISION_DONT_ALLOW = 0x1, + /* When set to 0, hash collisions are allowed. */ +} icp_qat_hw_comp_51_skip_hash_collision_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_COLLISION_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SKIP_HASH_COLLISION_ALLOW + +/*****************************************************************************/ +/* Skip Hash Update, located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_UPDATE_BITPOS 2 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_UPDATE_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SKIP_HASH_UPDATE field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_SKIP_HASH_UPDATE_ALLOW = 0x0, + /* 0 - hash updates are not skipped. */ + ICP_QAT_HW_COMP_51_SKIP_HASH_UPDATE_DONT_ALLOW = 0x1, + /* 1 - hash updates are skipped. */ +} icp_qat_hw_comp_51_skip_hash_update_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_SKIP_HASH_UPDATE_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_SKIP_HASH_UPDATE_ALLOW + +/*****************************************************************************/ +/* 3-Byte Match Skip, located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYTE_SKIP_BITPOS 1 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYTE_SKIP_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible BYTE_SKIP field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_BYTE_SKIP_3BYTE_TOKEN = 0x0, + /* 0 - Use 3-byte token */ + ICP_QAT_HW_COMP_51_BYTE_SKIP_3BYTE_LITERAL = 0x1, + /* 0 - Use 3-byte literal */ +} icp_qat_hw_comp_51_byte_skip_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_BYTE_SKIP_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_BYTE_SKIP_3BYTE_TOKEN + +/*****************************************************************************/ +/* LZ4 Block Checksum Present, located in lower 32 bit */ +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_BITPOS 0 +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible LZ4_BLOCK_CHECKSUM field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_COMP_51_LZ4_BLOCK_CHECKSUM_ABSENT = 0x0, + /* the LZ4 Block does not contain the 4-byte checksum */ + ICP_QAT_HW_COMP_51_LZ4_BLOCK_CHECKSUM_PRESENT = 0x1, + /* LZ4 Block contains a 4-byte checksum. */ +} icp_qat_hw_comp_51_lz4_block_checksum_t; + +#define ICP_QAT_HW_COMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_DEFAULT_VAL \ + ICP_QAT_HW_COMP_51_LZ4_BLOCK_CHECKSUM_ABSENT + +/*****************************************************************************/ +/* Discard Decompression Output Data, located in upper 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_DISCARD_DATA_BITPOS 26 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_DISCARD_DATA_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible DISCARD_DATA field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_DISCARD_DATA_DISABLED = 0x0, + /* 0 - Decompression produces output data i.e cleartext */ + ICP_QAT_HW_DECOMP_51_DISCARD_DATA_ENABLED = 0x1, + /* 0 - Decompression does not produce output data */ +} icp_qat_hw_decomp_51_discard_data_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_DISCARD_DATA_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_DISCARD_DATA_DISABLED + +/*****************************************************************************/ +/* Block Maximum Size (BMS), located in upper 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_BMS_BITPOS 19 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_BMS_MASK 0x3 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible BMS field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_BMS_BMS_64KB = 0x0, + /* Block Max Size (BMS) == 64 KB - LZ4, ZSTD, ILZ77, LZ4s=don't care */ + ICP_QAT_HW_DECOMP_51_BMS_BMS_256KB = 0x1, + /* Block Max Size (BMS) == 256 KB - LZ4 only */ + ICP_QAT_HW_DECOMP_51_BMS_BMS_1MB = 0x2, + /* Block Max Size (BMS) == 1 MB - LZ4 only */ + ICP_QAT_HW_DECOMP_51_BMS_BMS_4MB = 0x3, + /* Block Max Size (BMS) == 4 MB - LZ4 only */ +} icp_qat_hw_decomp_51_bms_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_BMS_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_BMS_BMS_64KB + +/*****************************************************************************/ +/* ZSTD Frame Gen/Decode Enable, located in upper 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_BITPOS 2 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible ZSTD_FRAME_GEN_DEC_EN field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_DISABLE = 0x0, + /* ZSTD Frame header and content checksum generation/decode disabled */ + ICP_QAT_HW_DECOMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_ENABLE = 0x1, + /* ZSTD Frame header and content checksum generation/decode enabled */ +} icp_qat_hw_decomp_51_zstd_frame_gen_dec_en_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_ZSTD_FRAME_GEN_DEC_EN_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_ZSTD_FRAME_GEN_DEC_EN_ZSTD_FRAME_HDR_ENABLE + +/*****************************************************************************/ +/* CHKN_BIT: Speculative Decoder Disable (INTERNAL_ONLY), located in lower 32 + * bit + */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_BITPOS 21 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible SPEC_DECODER_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_SPEC_DECODER_INTERNAL_ONLY_NORMAL = 0x0, + /* 0 - Normal Mode using Speculative Decoder */ + ICP_QAT_HW_DECOMP_51_SPEC_DECODER_INTERNAL_ONLY_DISABLED = 0x1, + /* 1 - Speculative Decoder disabled */ +} icp_qat_hw_decomp_51_spec_decoder_internal_only_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_SPEC_DECODER_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_SPEC_DECODER_INTERNAL_ONLY_NORMAL + +/*****************************************************************************/ +/* CHKN_BIT: Mini XCAM Disable (INTERNAL_ONLY), located in lower 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_BITPOS 20 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible MINI_XCAM_INTERNAL_ONLY field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_MINI_XCAM_INTERNAL_ONLY_NORMAL = 0x0, + /* 0 - Normal Mode using Speculative Decoder */ + ICP_QAT_HW_DECOMP_51_MINI_XCAM_INTERNAL_ONLY_DISABLED = 0x1, + /* 1 - Speculative Decoder disabled */ +} icp_qat_hw_decomp_51_mini_xcam_internal_only_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_MINI_XCAM_INTERNAL_ONLY_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_MINI_XCAM_INTERNAL_ONLY_NORMAL + +/*****************************************************************************/ +/* History Buffer Size, located in lower 32 bit + */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_HBS_BITPOS 14 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_HBS_MASK 0x7 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible HBS field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_HBS_32KB = 0x0, + /* 000b - 32KB (DEFLATE) */ + ICP_QAT_HW_DECOMP_51_HBS_64KB = 0x1, + /* 001b - 64KB (LZ4, LZ4s, ZSTD) */ +} icp_qat_hw_decomp_51_hbs_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_HBS_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_HBS_32KB + +/*****************************************************************************/ +/* Compression Format (Also See CMD ID), located in lower 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_FORMAT_BITPOS 5 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_FORMAT_MASK 0x7 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible FORMAT field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_FORMAT_ILZ77 = 0x1, + /* iLZ77 (Deflate) */ + ICP_QAT_HW_DECOMP_51_FORMAT_LZ4 = 0x2, + /* LZ4 */ + ICP_QAT_HW_DECOMP_51_FORMAT_RESERVED = 0x3, + /* reserved */ + ICP_QAT_HW_DECOMP_51_FORMAT_ZSTD = 0x4, + /* ZSTD */ +} icp_qat_hw_decomp_51_format_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_FORMAT_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_FORMAT_ILZ77 + +/*****************************************************************************/ +/* LZ4 Block Checksum Present, located in lower 32 bit */ +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_BITPOS 0 +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_MASK 0x1 +/* + **************************************************************************** + * @ingroup icp_qat_hw_defs + * @description + * Enumeration of possible LZ4_BLOCK_CHECKSUM field values + *****************************************************************************/ +typedef enum +{ + ICP_QAT_HW_DECOMP_51_LZ4_BLOCK_CHECKSUM_ABSENT = 0x0, + /* the LZ4 Block does not contain the 4-byte checksum */ + ICP_QAT_HW_DECOMP_51_LZ4_BLOCK_CHECKSUM_PRESENT = 0x1, + /* LZ4 Block contains a 4-byte checksum. */ +} icp_qat_hw_decomp_51_lz4_block_checksum_t; + +#define ICP_QAT_HW_DECOMP_51_CONFIG_CSR_LZ4_BLOCK_CHECKSUM_DEFAULT_VAL \ + ICP_QAT_HW_DECOMP_51_LZ4_BLOCK_CHECKSUM_ABSENT + +#endif /* _ICP_QAT_HW_51_COMP_DEFS_H */ diff --git a/quickassist/utilities/apps/sla_mgr/README.md b/quickassist/utilities/apps/sla_mgr/README.md new file mode 100644 index 00000000..6b54d017 --- /dev/null +++ b/quickassist/utilities/apps/sla_mgr/README.md @@ -0,0 +1,41 @@ + + + + + + +# QAT Rate Limiting Configuration Tools + +The QAT in-tree driver implements rate limiting configuration via the [sysfs interface](https://docs.kernel.org/admin-guide/abi-testing-files.html#abi-file-testing-sysfs-driver-qat-rl). This utility provides command-line wrappers built on top of that sysfs layer. For full documentation on QAT rate limiting, see the [Programmer's Guide](https://intel.github.io/quickassist/PG/infrastructure_ratelimiting.html). + +## qat_sla_mgr + +`qat_sla_mgr` is the supported command-line interface for managing rate limiting Service Level Agreements (SLAs). It requires root access and operates on PF and host-side VF addresses (VFs passed through to a guest are not supported). All throughput values (CIR, PIR) are expressed in **Mbps**. Both `qat_sla_mgr` and `qat_sla_rl.py` must reside in the same directory. + +**CIR** (Committed Information Rate) is the guaranteed minimum throughput for an SLA. **PIR** (Peak Information Rate) is the maximum allowed throughput. PIR must be greater than or equal to CIR. Both values must be positive. + +> **Note:** The device operates internally in permille units (0–1000) representing a fraction of the service's maximum capacity. CIR and PIR values specified in Mbps are converted to this internal scale and may be rounded down to the nearest supported granularity. As a result, the effective values reported by `list` or `get` may be lower than what was requested. The granularity depends on the device and service type — for example, a service with a 45000 Mbps maximum has a step size of 45 Mbps. + +**Usage** + +| Operation | Command | +| --------- | ------- | +| Create SLA | `./qat_sla_mgr create ` | + +The `create` command assigns an SLA covering all ring-pairs of the given service type on the specified VF. If you need an SLA that spans multiple VFs, or separate SLAs on individual ring-pairs within a VF, use `qat_sla_rl.py` or the sysfs interface directly. + +The `create` command prints the assigned SLA ID on success. Use this ID with the PF address for subsequent `update` and `delete` operations. SLAs are managed at the PF level — the VF address is only needed at creation time to derive the ring-pair mask. + +| Update SLA | `./qat_sla_mgr update ` | +| Delete SLA | `./qat_sla_mgr delete ` | +| Delete all SLAs | `./qat_sla_mgr delete_all ` | +| List all SLAs | `./qat_sla_mgr list ` | +| Device capacity | `./qat_sla_mgr caps ` | + +**Output details** + +- **create**: prints the assigned SLA ID. +- **update**: no output on success. +- **delete / delete_all**: no output on success. +- **list**: prints all configured SLAs with their ID, CIR, PIR (in Mbps), service type, ring-pair mask, and VF address (if SR-IOV is enabled). SLAs created directly via the sysfs interface are included, but the displayed VF address is derived from the ring-pair mask and may be incomplete for SLAs that span multiple VFs. +- **caps**: prints the maximum and remaining capacity (in Mbps) for every service configured on the device. diff --git a/quickassist/utilities/apps/sla_mgr/qat_sla_mgr b/quickassist/utilities/apps/sla_mgr/qat_sla_mgr new file mode 100755 index 00000000..8e72fc68 --- /dev/null +++ b/quickassist/utilities/apps/sla_mgr/qat_sla_mgr @@ -0,0 +1,116 @@ +#!/usr/bin/env bash +#***************************************************************************** +# +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2007-2026 Intel Corporation +# +# These contents may have been developed with support from one or more +# Intel-operated generative artificial intelligence solutions. +# +#*****************************************************************************/ + +SCRIPT_DIR="$(dirname "$(realpath "$0")")" +RL_PY="$SCRIPT_DIR/qat_sla_rl.py" + +if [[ $# -lt 1 ]]; then + echo "Usage: $0 ..." + echo "Use: $0 help - for more info" + exit 1 +fi + +if [[ ! -f "$RL_PY" ]]; then + echo "Error: qat_sla_rl.py not found at $RL_PY" + exit 1 +fi + +# Verify we are running with the in-tree QAT driver +if [[ ! -d /sys/module/intel_qat ]]; then + if lsmod | grep -q qat; then + echo "This is the qat_sla_mgr script for the QAT in-tree stack." + echo "You appear to be using an out-of-tree kernel driver." + echo "The qat_sla_mgr utility for the OOT stack can be found in the QAT package here:" + echo "https://www.intel.com/content/www/us/en/developer/topic-technology/open/quick-assist-technology/overview.html" + else + echo "No QAT kernel driver is loaded." + fi + exit 1 +fi + +function help() +{ + printf " + Commands: + Create SLA \t\t\t ./qat_sla_mgr create + Update SLA \t\t\t ./qat_sla_mgr update + Delete SLA \t\t\t ./qat_sla_mgr delete + Delete all SLAs \t\t ./qat_sla_mgr delete_all + List all SLAs \t\t ./qat_sla_mgr list + Device capacity \t\t ./qat_sla_mgr caps + " +} + +case "$1" in + + add | create) + # Create SLA - ./qat_sla_mgr create + if [[ $# -ne 5 ]]; then + echo "Usage: $0 create " + exit 1 + fi + python3 "$RL_PY" add "$2" --cir "$3" --pir "$4" --service "$5" --scale_mbps + ;; + + update) + # Update SLA - ./qat_sla_mgr update + if [[ $# -ne 5 ]]; then + echo "Usage: $0 update " + exit 1 + fi + python3 "$RL_PY" update "$2" --sla_id "$3" --cir "$4" --pir "$5" --scale_mbps + ;; + + delete) + # Delete SLA - ./qat_sla_mgr delete + if [[ $# -ne 3 ]]; then + echo "Usage: $0 delete " + exit 1 + fi + python3 "$RL_PY" rm "$2" --sla_id "$3" + ;; + + delete_all) + # Delete all SLAs - ./qat_sla_mgr delete_all + if [[ $# -ne 2 ]]; then + echo "Usage: $0 delete_all " + exit 1 + fi + python3 "$RL_PY" rm_all "$2" + ;; + + caps) + # Device capabilities - ./qat_sla_mgr caps + if [[ $# -ne 2 ]]; then + echo "Usage: $0 caps " + exit 1 + fi + python3 "$RL_PY" caps "$2" --scale_mbps + ;; + list) + if [[ $# -ne 2 ]]; then + echo "Usage: $0 list " + exit 1 + fi + python3 "$RL_PY" list "$2" --scale_mbps + ;; + help) + echo "" + echo " SLA Manager for in-tree driver " + help + exit 0 + ;; + + *) + echo "Unsupported operation" + exit 1 + ;; +esac diff --git a/quickassist/utilities/apps/sla_mgr/qat_sla_rl.py b/quickassist/utilities/apps/sla_mgr/qat_sla_rl.py new file mode 100755 index 00000000..c30a76dd --- /dev/null +++ b/quickassist/utilities/apps/sla_mgr/qat_sla_rl.py @@ -0,0 +1,437 @@ +#!/usr/bin/env python3 +#***************************************************************************** +# +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2007-2026 Intel Corporation +# +# These contents may have been developed with support from one or more +# Intel-operated generative artificial intelligence solutions. +# +#*****************************************************************************/ +# +# qat_sla_rl.py - underlying implementation used by qat_sla_mgr. +# +# This script can be invoked directly for advanced use cases, but is not a +# supported interface and may change without notice. Run ./qat_sla_rl.py --help for +# usage details. +# +# By default, values are in the device's internal permille units (0-1000, +# representing a fraction of the device's maximum capacity). Use the +# --scale_mbps (-sm) flag to specify CIR and PIR in Mbps instead. +# + +import os +import re +from argparse import ArgumentParser, HelpFormatter +import textwrap + +# DBDF format: domain is optional (e.g. both "BB:DD.F" and "DDDD:BB:DD.F" are valid) +dbdf_regex = r"^([0-9a-fA-F]{4}:)?[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$" +rl_ops = ["add", "update", "rm", "rm_all", "list", "caps", "cap_rem", "get"] +rl_services = ["asym", "sym", "dc", "decomp", "dcc"] +# Service capacity in Mbps, keyed by PCI device ID +# Maximum SLA ID to scan (mirrors ADF_MAX_SLA in SAL C code) +MAX_SLA_ID = 64 +# Service capacity in Mbps, keyed by PCI device ID +DEVICE_CAPS = { + "0x4940": {"asym": 173750, "sym": 95000, "dc": 45000, "dcc": 45000}, + "0x4942": {"asym": 173750, "sym": 95000, "dc": 45000, "dcc": 45000}, + "0x4944": {"asym": 173750, "sym": 95000, "dc": 45000, "dcc": 45000}, + "0x4946": {"asym": 173750, "sym": 95000, "dc": 45000, "dcc": 45000}, + "0x4948": {"asym": 173750, "sym": 95000, "dc": 40000, "decomp": 40000, "dcc": 40000}, +} +ophelp = f''' +Rate Limiting configuration tool + +Supported operations: + +Create SLA using RPs mask \t ./%(prog)s add\t -c -p -s -r +Create SLA using VF addr \t ./%(prog)s add\t -c -p -s +Update SLA \t\t\t ./%(prog)s update\t -i -c -p +Get SLA \t\t\t ./%(prog)s get\t -i +Delete SLA \t\t\t ./%(prog)s rm\t -i +Delete all SLAs \t\t ./%(prog)s rm_all\t +List all SLAs \t\t ./%(prog)s list\t +Remaining service capacity \t ./%(prog)s cap_rem -s +All service capacity \t\t ./%(prog)s caps\t + +CIR and PIR values must be positive values. + + +''' + +class RawFormatter(HelpFormatter): + def _fill_text(self, text, width, indent): + text = textwrap.dedent(text) + text = textwrap.indent(text, indent) + text = text.splitlines() + text = [textwrap.fill(line, width) for line in text] + text = "\n".join(text) + return text + +class Ratelimiting: + def resolve_pf_dbdf(self, dbdf): + dev_path = f"/sys/bus/pci/devices/{dbdf}" + physfn = os.path.join(dev_path, "physfn") + + if os.path.islink(physfn): + # VF → PF + pf_path = os.readlink(physfn) + return os.path.basename(pf_path) + + return dbdf + + def __init__(self, dbdf, operation, sla_id, cir, pir, service, rp, scale): + if not re.match(dbdf_regex, dbdf): + raise Exception("Incorrect BDF format: " + dbdf + ". Expected format: [DDDD:]BB:DD.F (e.g. 0000:05:00.0 or 05:00.0)") + if not dbdf.count(':') == 2: + dbdf = "0000:" + dbdf + + self.dbdf = dbdf + match = re.split(r"[:\.]", dbdf) + self.bdf_bus = match[1] + self.bdf_dev = match[2] + self.bdf_func = match[3] + + self.input_dbdf = self.dbdf + self.pf_dbdf = self.resolve_pf_dbdf(self.dbdf) + + self.sysfs_dir = os.path.join("/sys/bus/pci/devices", self.pf_dbdf) + self.qat_rl_dir = os.path.join(self.sysfs_dir, "qat_rl") + + if not os.path.exists(os.path.join(self.sysfs_dir, "qat")): + raise Exception(f"QAT device with address: `{dbdf}` does not exist") + + self.operation_file = os.path.join(self.qat_rl_dir, "sla_op") + if not os.path.exists(self.operation_file): + raise Exception(f"QAT device with address: `{dbdf}` does not support Rate Limiting") + + pci_device_id_file = os.path.join(self.sysfs_dir, "device") + with open(pci_device_id_file, "r") as f: + self.pci_device_id = f.read().strip() + + self.operation = operation + self.cir = cir + self.pir = pir + self.srv = service + self.sla_id = sla_id + self.rp = int(rp, 0) if rp else 0 + self.scale = scale + + + def add(self): + if self.srv == "": + raise Exception("Service type is required for add operation. Use -s ") + if self.rp == 0: + if self.input_dbdf == self.pf_dbdf: + raise Exception("Ring Pair Mask not provided. Use -r or provide a VF address") + if not self.is_sriov_enabled(): + raise Exception("Ring Pair Mask not provided and SR-IOV is not enabled") + print("Ring Pair Mask not provided, trying to calculate it from VF address.") + self.rp = self.set_rp_mask_from_vf() + if self.cir <= 0: + raise Exception("CIR value must be greater than 0") + if self.pir < self.cir: + print("PIR must be >= CIR, setting PIR to CIR value") + self.pir = self.cir + + if self.scale: + s_cir = self.scale_to_permille(int(self.cir)) + s_pir = self.scale_to_permille(int(self.pir)) + self.set("cir", s_cir) + self.set("pir", s_pir) + else: + self.set("cir", self.cir) + self.set("pir", self.pir) + try: + self.set("srv", self.srv) + except OSError as error: + if error.errno == 22: + raise Exception(f"Service '{self.srv}' is not enabled on this PF") + raise + self.set("rp", self.rp) + self._write_op(self.operation) + print("SLA ID:", self.get("id")) + + def update(self): + if self.cir <= 0: + raise Exception("CIR value must be greater than 0") + self.set("id", self.sla_id) + self._write_op("get") + if self.scale: + self.srv = self.get("srv") + if self.pir == 0: + self.pir = int(self.get("pir")) + if self.scale: + self.pir = self.scale_to_mbps(self.pir) + if self.pir < self.cir: + print("PIR must be >= CIR, setting PIR to CIR value") + self.pir = self.cir + if self.scale: + s_cir = self.scale_to_permille(int(self.cir)) + s_pir = self.scale_to_permille(int(self.pir)) + self.set("cir", s_cir) + self.set("pir", s_pir) + else: + self.set("cir", self.cir) + self.set("pir", self.pir) + self._write_op(self.operation) + + def get_sla(self): + self.set("id", self.sla_id) + self._write_op("get") + print("\n\tSLA ID:", self.get("id")) + cir = self.get("cir") + pir = self.get("pir") + self.srv = self.get("srv") + if self.scale: + cir = str(self.scale_to_mbps(int(cir))) + pir = str(self.scale_to_mbps(int(pir))) + print("\tCIR:", cir) + print("\tPIR:", pir) + print("\tSRV:", self.srv) + rp = self.get("rp") + print("\tRP:", rp) + if self.is_sriov_enabled(): + vf_addr = self.rp_mask_to_vf_addr(rp) + if vf_addr: + print("\tVF:", vf_addr) + + def rm(self): + self.set("id", self.sla_id) + self._write_op(self.operation) + + def rm_all(self): + self._write_op(self.operation) + + def get_configured_services(self): + """Read rp2srv sysfs to discover which services are configured on this PF.""" + qat_rp2srv = os.path.join(self.sysfs_dir, "qat/rp2srv") + services = set() + for i in range(4): + try: + with open(qat_rp2srv, "w") as file: + file.write(str(i)) + with open(qat_rp2srv, "r") as file: + srv = file.read().strip() + if srv in rl_services: + services.add(srv) + except OSError as error: + if error.errno == 22: + # Ring pair not configured or invalid index (EINVAL) + print(f"Ring pair {i} not configured (errno: {error.errno})") + continue + # Raise unexpected errors (e.g., permission issues, missing sysfs node) + raise Exception(f"Unexpected OSError for ring pair {i}: errno={error.errno}, {error.strerror}") + return services + + def cap_rem(self): + if self.srv == "": + raise Exception("Service type is required for cap_rem operation. Use -s ") + cap_rem_file = os.path.join(self.sysfs_dir, "qat_rl/cap_rem") + try: + self.set("cap_rem", self.srv) + with open(cap_rem_file, "r") as file: + val = file.read().strip() + if self.scale: + val = self.scale_to_mbps(int(val)) + except OSError as error: + if error.errno == 22: + raise Exception(f"Service '{self.srv}' is not enabled on this PF") + raise + if self.scale: + max_mbps = self.get_max_mbps() + print("Remaining capacity for \'{}\' is: {} of: {}".format(self.srv, val, max_mbps)) + else: + print("Remaining capacity for \'{}\' is: {}".format(self.srv, val)) + + def caps(self): + errors = [] + for srv in sorted(self.get_configured_services()): + self.srv = srv + try: + self.cap_rem() + except Exception as e: + print(f"Error querying service '{srv}': {e}") + errors.append(srv) + if errors: + raise Exception(f"Failed to query capacity for: {', '.join(errors)}") + + def set(self, f, value): + set_file = os.path.join(self.sysfs_dir, "qat_rl/" + f) + try: + with open(set_file, "w") as file: + file.write(str(value)) + except OSError as e: + raise OSError(e.errno, f"Error writing to {f}: {e.strerror}", set_file) from e + + def get(self, f): + set_file = os.path.join(self.sysfs_dir, "qat_rl/" + f) + try: + with open(set_file, "r") as file: + return file.read().strip() + except OSError as e: + raise OSError(e.errno, f"Error reading from {f}: {e.strerror}", set_file) from e + + def _write_op(self, op): + with open(self.operation_file, "w") as file: + file.write(op) + + def list(self): + print("Listing SLAs for device:", self.dbdf) + print("--------------------------------------------------") + found = False + for sla_id in range(0, MAX_SLA_ID): + try: + self.sla_id = sla_id + self.get_sla() + except OSError as error: + if error.errno == 22: + continue + raise + + found = True + + if not found: + print("No SLAs configured") + + def get_max_mbps(self): + caps = DEVICE_CAPS.get(self.pci_device_id) + if caps is None: + raise Exception(f"No capacity data for device ID {self.pci_device_id}") + if self.srv not in caps: + raise Exception(f"Unknown service type: '{self.srv}'") + return caps[self.srv] + + def scale_to_mbps(self, rate: int): + max_mbps = self.get_max_mbps() + val = int(rate * max_mbps / 1000) + if val == 0 and rate > 0: + val = 1 + return val + + def scale_to_permille(self, rate: int): + max_mbps = self.get_max_mbps() + val = int(rate * 1000 / max_mbps) + if val == 0 and rate > 0: + val = 1 + return val + + def set_rp_mask_from_vf(self): + # bdf_dev and bdf_func are hexadecimal components of the PCI BDF + dev = int(self.bdf_dev, 16) + func = int(self.bdf_func, 16) + vf_id = (dev * 8 + func - 1) + if vf_id not in range(0,16): + raise Exception("Mask calculation failed: VF addr: {} does not exist in QAT".format(self.dbdf)) + rp_mask = hex(self.get_srv2rp_mask() << (vf_id *4)) + return rp_mask + + def is_sriov_enabled(self): + numvfs_file = os.path.join(self.sysfs_dir, "sriov_numvfs") + try: + with open(numvfs_file, "r") as f: + return int(f.read().strip()) > 0 + except (OSError, ValueError): + return False + + def rp_mask_to_vf_addr(self, rp_mask_str): + """Translate RP mask back to VF address. Returns None if not possible.""" + try: + rp_mask = int(rp_mask_str, 0) + if rp_mask == 0: + return None + # Find the lowest non-zero nibble to determine vf_id + vf_id = 0 + temp = rp_mask + while temp & 0xF == 0: + temp >>= 4 + vf_id += 1 + if vf_id not in range(0, 16): + return None + # vf_id = dev * 8 + func - 1 + pci_id = vf_id + 1 + dev = pci_id // 8 + func = pci_id % 8 + pf_match = re.split(r"[:\.]", self.pf_dbdf) + domain = pf_match[0] + bus = pf_match[1] + return f"{domain}:{bus}:{dev:02x}.{func}" + except (ValueError, IndexError): + return None + + def get_srv2rp_mask(self): + qat = os.path.join(self.sysfs_dir, "qat/rp2srv") + mask = 0 + for i in range(4): + try: + with open(qat, "w") as file: + file.write(str(i)) + with open(qat, "rt") as file: + srv = file.read().strip() + if srv == self.srv: + mask = mask | (1 << i) + except OSError as error: + if error.errno == 22: + # Ring pair not configured or invalid index (EINVAL) + print(f"Ring pair {i} not configured (errno: {error.errno})") + continue + # Raise unexpected errors (e.g., permission issues, missing sysfs node) + raise Exception(f"Unexpected OSError for ring pair {i}: errno={error.errno}, {error.strerror}") + if mask == 0: + raise Exception("No ring pairs assigned to service {} on this PF".format(self.srv)) + return mask + +# Main function. +if __name__ == "__main__": + parser = ArgumentParser(description=ophelp, formatter_class=RawFormatter) + + parserg1 = parser.add_argument_group(title='Parameters', description='Arguments needed for operations') + parserg1.add_argument('operation', action='store', choices=rl_ops, help='Operation to perform', + metavar="operation") + parserg1.add_argument('bdf', action='store', help='[Domain] Bus Device Function address - XX:XX.X', metavar="pci_bdf") + parserg1.add_argument("--cir", "-c", action='store', dest='cir', + help='Committed information rate', default=0, + type=int, metavar="N") + parserg1.add_argument('--pir', '-p', action='store', dest='pir', + help='Peak information rate' , default=0, + type=int, metavar="N") + parserg1.add_argument('--sla_id', '-i', action='store', dest='sla_id', + help='SLA identification', default=0, + type=int, metavar="N") + parserg1.add_argument('--service', '-s', action='store', dest='service', + help='SLA service type', default="", metavar="srv", + choices=rl_services) + parserg1.add_argument('--ring_pairs', '-r', action='store', dest='ring_pairs', + help='Ring pair hexadecimal mask (max 64bit)', default="", + type=str, metavar="0xNN") + parserg2 = parser.add_argument_group(title='Misc', description='Additional arguments') + parserg2.add_argument('--scale_mbps', '-sm', action='store_true', dest='scale', + help='Scale to old Mbps units', default=False) + + args = parser.parse_args() + + # Run the command + try: + rl = Ratelimiting(args.bdf, args.operation, args.sla_id, args.cir, args.pir, args.service, args.ring_pairs, args.scale) + FUNC_MAP = { + "add": rl.add, + "update": rl.update, + "get": rl.get_sla, + "rm": rl.rm, + "rm_all": rl.rm_all, + "cap_rem": rl.cap_rem, + "caps": rl.caps, + "list": rl.list, + } + + func = FUNC_MAP[args.operation] + func() + except OSError as error: + print('Operation `' + args.operation + '` failed with: ' + str(error) + '\nCheck kernel log for more details.') + exit(1) + except Exception as error: + print('Operation `' + args.operation + '` failed with: ' + str(error)) + exit(1) + + exit(0) diff --git a/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h b/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h index b3f08a26..cec1b7b5 100644 --- a/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h +++ b/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h @@ -166,21 +166,54 @@ BITMAP_LEN is a macro the represents the number of 64-bit quad words that make up the bitmap with 512 pages of 4k page and 1k units this value is 32 */ -#define CHUNK_SIZE (UNIT_SIZE * QWORD_WIDTH) +#define BLOCK_SIZES (QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE) -#define BITMAP_LEN (QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / CHUNK_SIZE) +#define BITMAP_LEN (BLOCK_SIZES / QWORD_WIDTH) -#define BLOCK_SIZES (BITMAP_LEN * QWORD_WIDTH) - -/*block control structure */ +/* + * block_ctrl_t: slab control block. + * + * bitmap[] is a Flexible Array Member (FAM) and the sizes[] region lives + * in slab memory immediately after the sentinel bitmap word. The sizes + * pointer is set by init_block_ctrl() and must not be used before then. + * + * Memory layout (base = slab virtual address): + * [fixed header][bitmap[max_num_bitmaps + 1]][sizes[max_num_blocks]] + * + * The first max_num_blocks uint32_t words after the sentinel bitmap word + * hold the allocation length (in units) for each block index: 0 when free, + * >0 when in use. + */ typedef struct block_ctrl_s { - dev_mem_info_t mem_info; /* memory device info type */ - /* adding an extra element at the end to make a barrier */ - uint64_t bitmap[BITMAP_LEN + 1]; /* bitmap each bit represents a 1k block */ - uint16_t sizes[BLOCK_SIZES]; /* Holds the size of each allocated block */ + dev_mem_info_t mem_info; /* memory device info type - must stay first */ + size_t header_size; /* total control region bytes (hdr + bitmap + + * sizes) */ + size_t unit_size; /* bytes per allocation unit */ + size_t max_num_bitmaps; /* number of uint64_t bitmap words (excl. + * sentinel) */ + size_t max_num_blocks; /* number of allocatable block positions */ + size_t reserved_units; /* units pre-reserved for this header region */ + uint32_t *sizes; /* pointer to the sizes[] region after bitmap + * sentinel */ + uint64_t bitmap[]; /* Flexible Array Member (FAM): max_num_bitmaps + + * 1 words (last = sentinel) */ } block_ctrl_t; +/* Total slab control region size in bytes: fixed header + bitmap words + * (including sentinel) + sizes words. Used before a block_ctrl_t is + * initialised (e.g. to compute the reserved unit count at allocation + * time). Once initialised, prefer bc->header_size. + */ +static inline size_t get_ctrl_size(void) +{ + return sizeof(block_ctrl_t) + (BITMAP_LEN + 1) * sizeof(uint64_t) + + BLOCK_SIZES * sizeof(uint32_t); +} + +#undef BITMAP_LEN +#undef BLOCK_SIZES + /** ***************************************************************************** * @ingroup qaeMemUtils @@ -388,15 +421,26 @@ typedef struct user_mem_dev_s #define DEV_MEM_IOC_HUGEPAGE_IOMMU_UNMAP \ _IOWR(DEV_MEM_MAGIC, DEV_MEM_CMD_HUGEPAGE_IOMMU_UNMAP, user_page_info_t) + +#ifndef API_LOCAL +#if __GNUC__ >= 4 +#define API_PUBLIC __attribute__((visibility("default"))) +#define API_LOCAL __attribute__((visibility("hidden"))) +#else +#define API_PUBLIC +#define API_LOCAL +#endif +#endif /***************************************************************************** - * * @ingroup CommonMemoryDriver - * qaeMemInit + * @internal + * @ingroup CommonMemoryDriver + * __qae_memInit * * @description * Initialize the user-space allocator, opening the device driver * used to communicate with the kernel-space. - * - * @param[in] path - path to the specific device + * This is an internal function not intended for direct use by + * applications. The library self-initializes on first allocation. * * @retval 0 if the open of the device was successful and * non-zero otherwise @@ -406,27 +450,30 @@ typedef struct user_mem_dev_s * Allocator is initialized * ****************************************************************************/ -int32_t qaeMemInit(void); +API_LOCAL int32_t __qae_memInit(void); /***************************************************************************** - * * @ingroup CommonMemoryDriver - * qaeMemDestroy + * @internal + * @ingroup CommonMemoryDriver + * __qae_memDestroy * * @description * Release the user-space allocator. It closes the file descriptor - * associated with the device driver + * associated with the device driver. + * This is an internal function not intended for direct use by + * applications. The library manages its own cleanup. * * @param[in] none * * @retval none * * @pre - * The user space allocator is initialized using qaeMemInit + * The user space allocator is initialized using __qae_memInit * @post * The user-space allocator is released * ****************************************************************************/ -void qaeMemDestroy(void); +API_LOCAL void __qae_memDestroy(void); /***************************************************************************** * * @ingroup CommonMemoryDriver @@ -619,7 +666,7 @@ void qaeIOMMUDetachDev(void *dev); * @retval none * * @pre - * The user space allocator is initialized using qaeMemInit + * The user space allocator is initialized using __qae_memInit * @post * memory allocation count printed * @@ -652,49 +699,7 @@ void printMemAllocations(void); #if defined(__KERNEL__) int handle_other_ioctls(uint32_t cmd); -#if defined(ICP_ADF_IOMMU) -int icp_adf_iommu_map(void *iova, void *phaddr, size_t size); -int icp_adf_iommu_unmap(void *iova, size_t size); -size_t icp_adf_iommu_get_remapping_size(size_t size); -static inline int icp_iommu_map(void **iova, void *vaddr, size_t size) -{ - void *phaddr = (void *)virt_to_phys(vaddr); - *iova = phaddr; - return icp_adf_iommu_map(*iova, phaddr, size); -} -static inline int icp_iommu_unmap(void *iova, size_t size) -{ - return icp_adf_iommu_unmap(iova, size); -} -static inline size_t icp_iommu_get_remapping_size(size_t size) -{ - return icp_adf_iommu_get_remapping_size(size); -} -#elif defined(ICP_OSAL_IOMMU) -int osalIOMMUMap(uint64_t iova, uint64_t phaddr, size_t size); -static inline int icp_iommu_map(void **iova, void *vaddr, size_t size) -{ - void *phaddr = (void *)virt_to_phys(vaddr); - *iova = phaddr; - return osalIOMMUMap((uintptr_t)*iova, phaddr, size); -} - -int osalIOMMUUnmap(uint64_t iova, size_t size); -static inline int icp_iommu_unmap(void *iova, size_t size) -{ - return osalIOMMUUnmap((uintptr_t)iova, size); -} -uint64_t osalIOMMUVirtToPhys(uint64_t iova); -static inline uint64_t icp_iommu_virt_to_phys(void *iova) -{ - return osalIOMMUVirtToPhys((uintptr_t)iova); -} -size_t osalIOMMUgetRemappingSize(size_t size); -static inline size_t icp_iommu_get_remapping_size(size_t size) -{ - return osalIOMMUgetRemappingSize(size); -} -#elif defined(ICP_QDM_IOMMU) +#if defined(ICP_QDM_IOMMU) int qdm_iommu_map(void **iova, void *vaddr, size_t size); int qdm_iommu_unmap(void *iova, size_t size); int qdm_hugepage_iommu_map(void **iova, void *va_page, size_t size); diff --git a/quickassist/utilities/libusdm_drv/qae_mem.h b/quickassist/utilities/libusdm_drv/qae_mem.h index c7d8bf66..3c66f148 100644 --- a/quickassist/utilities/libusdm_drv/qae_mem.h +++ b/quickassist/utilities/libusdm_drv/qae_mem.h @@ -21,6 +21,22 @@ extern "C" { #endif +/** + * @brief Deprecated attribute macro for USDM APIs. + * + * When QAE_DEPRECATED is applied to a function declaration, compilers that + * support __attribute__((deprecated)) will emit a warning at each call site, + * alerting users that the function should no longer be used. + * + * Uncomment the deprecated macro if you need to see which APIs are deprecated. + */ +#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(_WIN64) +#define QAE_DEPRECATED +/* #define QAE_DEPRECATED __attribute__((deprecated)) */ +#else +#define QAE_DEPRECATED +#endif + #ifdef __KERNEL__ #include #else @@ -393,6 +409,36 @@ int qaeMemUnmapContiguousIova(void *virt, size_t size); void qaeAtFork(void); #endif +/** + ***************************************************************************** + * @ingroup CommonMemoryDriver + * qaeMemInit + * + * @brief + * @deprecated This function is a no-op and is no longer required. + * The USDM library self-initializes on first use (e.g. when + * qaeMemAllocNUMA() is called). Existing callers may continue to + * call this function without error; it will return 0 (success) + * immediately. + * + * @retval 0 always (success) + * + ****************************************************************************/ +QAE_DEPRECATED int32_t qaeMemInit(void); + +/** + ***************************************************************************** + * @ingroup CommonMemoryDriver + * qaeMemDestroy + * + * @brief + * @deprecated This function is a no-op and is no longer required. + * The USDM library manages its own cleanup. Existing callers may + * continue to call this function without error; it does nothing. + * + ****************************************************************************/ +QAE_DEPRECATED void qaeMemDestroy(void); + #ifdef __cplusplus } /* close the extern "C" { */ #endif diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c b/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c index 6b1555fe..887fa9fd 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c @@ -264,7 +264,8 @@ void __qae_ResetControl(void) __qae_pUserLargeMemListTail = NULL; } -int32_t qaeMemInit() +API_LOCAL +int32_t __qae_memInit() { int32_t fd_status = 0; int32_t status = 0; @@ -293,6 +294,12 @@ int32_t qaeMemInit() return fd_status; } +/* Deprecated public no-op stub - library self-initializes on first use */ +int32_t qaeMemInit() +{ + return 0; +} + API_LOCAL void __qae_destroyList(const int fd, dev_mem_info_t *pList) { @@ -318,7 +325,8 @@ void __qae_reset_cache(const int fd) } while (slab != NULL); } -void qaeMemDestroy(void) +API_LOCAL +void __qae_memDestroy(void) { int ret = 0; @@ -356,6 +364,12 @@ void qaeMemDestroy(void) } } +/* Deprecated no-op; return 0 in rax for int-declared callers. */ +void qaeMemDestroy(void) +{ + __asm__ __volatile__("xorl %%eax, %%eax" ::: "rax"); +} + API_LOCAL void *__qae_alloc_addr(size_t size, const int node, @@ -367,13 +381,10 @@ void *__qae_alloc_addr(size_t size, enum slabType mem_type = SMALL; const size_t phys_align_unit = phys_alignment_byte / UNIT_SIZE; - const size_t reserved = div_round_up(sizeof(block_ctrl_t), UNIT_SIZE); + const size_t reserved = div_round_up(get_ctrl_size(), UNIT_SIZE); /* calculate units needed */ const size_t requested_pages = div_round_up(size, UNIT_SIZE) + reserved; - if (0 != __qae_open()) - return NULL; - if (requested_pages > QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE || phys_alignment_byte >= QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE) { @@ -409,11 +420,10 @@ void *__qae_alloc_addr(size_t size, if (NULL == p_ctrl_blk) return NULL; - store_mmap_range(&g_page_table, - p_ctrl_blk->virt_addr, - p_ctrl_blk->phy_addr, - p_ctrl_blk->size, - __qae_hugepage_enabled()); + store_mmap_range_fptr(&g_page_table, + p_ctrl_blk->virt_addr, + p_ctrl_blk->phy_addr, + p_ctrl_blk->size); if (LARGE == mem_type) { @@ -471,22 +481,14 @@ void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) return NULL; } - if (size > QAE_MAX_ALLOC_SIZE) - { - CMD_ERROR( - "%s:%d Size cannot exceed 64M for vfio\n", __func__, __LINE__); - return NULL; - } - - if (!phys_alignment_byte || phys_alignment_byte > QAE_MAX_PHYS_ALIGN || + if (!phys_alignment_byte || (phys_alignment_byte & (phys_alignment_byte - 1))) { - CMD_ERROR("%s:%d Invalid alignment parameter %zu. It must be non zero, " - "not more than %llu and multiple of 2 \n", + CMD_ERROR("%s:%d Invalid alignment %zu: must be non-zero and a " + "power of 2\n", __func__, __LINE__, - phys_alignment_byte, - QAE_MAX_PHYS_ALIGN); + phys_alignment_byte); return NULL; } @@ -500,6 +502,34 @@ void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) return NULL; } + /* init: opens the fd. Also handles fork transparently via + * is_new_process(). + */ + if (unlikely(__qae_open())) + { + mem_mutex_unlock(&mutex); + return NULL; + } + + if (size > QAE_MAX_ALLOC_SIZE) + { + CMD_ERROR( + "%s:%d Size cannot exceed 64M for vfio\n", __func__, __LINE__); + mem_mutex_unlock(&mutex); + return NULL; + } + + if (phys_alignment_byte > QAE_MAX_PHYS_ALIGN) + { + CMD_ERROR("%s:%d Invalid alignment %zu exceeds maximum %llu\n", + __func__, + __LINE__, + phys_alignment_byte, + QAE_MAX_PHYS_ALIGN); + mem_mutex_unlock(&mutex); + return NULL; + } + pVirtAddress = __qae_alloc_addr(size, node, phys_alignment_byte); ret = mem_mutex_unlock(&mutex); diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_hugepage_utils.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_hugepage_utils.h index a7821ee4..261090a7 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_hugepage_utils.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_hugepage_utils.h @@ -19,6 +19,7 @@ #define QAE_MEM_HUGEPAGE_UTILS_H #include "qae_mem_utils.h" #include "qae_mem_user_utils.h" +#include "qae_page_table_defs.h" API_LOCAL uint64_t __qae_hugepage_virt2phy(const int fd, @@ -57,4 +58,5 @@ int __qae_vfio_init_hugepages(void); API_LOCAL int __qae_hugepage_enabled(void); + #endif diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h index c2c377c1..86dd2b32 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h @@ -136,15 +136,13 @@ static inline void *init_slab_and_alloc(block_ctrl_t *slab, const size_t size, const size_t phys_align_unit) { - const size_t last = slab->mem_info.size / CHUNK_SIZE; dev_mem_info_t *p_ctrl_blk = &slab->mem_info; - const size_t reserved = div_round_up(sizeof(block_ctrl_t), UNIT_SIZE); void *virt_addr = NULL; - /* initialise the bitmap to 1 for reserved blocks */ - set_bitmap(slab->bitmap, 0, reserved); - /* make a barrier to stop search at the end of the bitmap */ - slab->bitmap[last] = QWORD_ALL_ONE; + /* Initialise geometry fields and sizes[] pointer before the bitmap + * is touched. + */ + init_block_ctrl(slab, UNIT_SIZE); virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); if (NULL != virt_addr) diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h index 0d5d3d23..1ba49a15 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h @@ -169,15 +169,13 @@ static inline void *init_slab_and_alloc(block_ctrl_t *slab, const size_t phys_align_unit, qae_mem_info_t *tls_ptr) { - const size_t last = slab->mem_info.size / CHUNK_SIZE; dev_mem_info_t *p_ctrl_blk = &slab->mem_info; - const size_t reserved = div_round_up(sizeof(block_ctrl_t), UNIT_SIZE); void *virt_addr = NULL; - /* initialise the bitmap to 1 for reserved blocks */ - set_bitmap(slab->bitmap, 0, reserved); - /* make a barrier to stop search at the end of the bitmap */ - slab->bitmap[last] = QWORD_ALL_ONE; + /* Initialise geometry fields and sizes[] pointer before the bitmap + * is touched. + */ + init_block_ctrl(slab, UNIT_SIZE); virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); if (NULL != virt_addr) diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c index b76abee1..710c695f 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c @@ -224,7 +224,8 @@ static void qae_mem_init_t(void) qae_mem_inited = 1; } -int32_t qaeMemInit() +API_LOCAL +int32_t __qae_memInit() { int32_t fd_status = 0; int32_t status = 0; @@ -244,6 +245,12 @@ int32_t qaeMemInit() return fd_status; } +/* Deprecated public no-op stub - library self-initializes on first use */ +int32_t qaeMemInit() +{ + return 0; +} + API_LOCAL void __qae_destroyList(const int fd, dev_mem_info_t *pList, void *thread_key) { @@ -270,7 +277,8 @@ void __qae_reset_cache(const int fd, void *thread_key) } while (slab != NULL); } -void qaeMemDestroy(void) +API_LOCAL +void __qae_memDestroy(void) { qae_mem_info_t *tls_ptr = NULL; @@ -291,6 +299,16 @@ void qaeMemDestroy(void) qae_mem_inited = 0; pthread_key_delete(qae_key); + /* Reset the once-guard so the key is recreated on the next init; + * otherwise pthread_once() skips qae_make_key() and qae_key keeps + * referring to the deleted key, making pthread_setspecific() fail. */ + qae_key_once = PTHREAD_ONCE_INIT; +} + +/* Deprecated no-op; return 0 in rax for int-declared callers. */ +void qaeMemDestroy(void) +{ + __asm__ __volatile__("xorl %%eax, %%eax" ::: "rax"); } void qae_mem_destroy_t(void *thread_key) @@ -319,7 +337,7 @@ void *__qae_alloc_addr(size_t size, tls_ptr = (qae_mem_info_t *)pthread_getspecific(qae_key); const size_t phys_align_unit = phys_alignment_byte / UNIT_SIZE; - const size_t reserved = div_round_up(sizeof(block_ctrl_t), UNIT_SIZE); + const size_t reserved = div_round_up(get_ctrl_size(), UNIT_SIZE); /* calculate units needed */ const size_t requested_pages = div_round_up(size, UNIT_SIZE) + reserved; @@ -369,11 +387,10 @@ void *__qae_alloc_addr(size_t size, if (NULL == p_ctrl_blk) return NULL; - store_mmap_range(&g_page_table, - p_ctrl_blk->virt_addr, - p_ctrl_blk->phy_addr, - p_ctrl_blk->size, - __qae_hugepage_enabled()); + store_mmap_range_fptr(&g_page_table, + p_ctrl_blk->virt_addr, + p_ctrl_blk->phy_addr, + p_ctrl_blk->size); if (LARGE == mem_type) { @@ -430,6 +447,20 @@ void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) return NULL; } + if (!phys_alignment_byte || + (phys_alignment_byte & (phys_alignment_byte - 1))) + { + CMD_ERROR("%s:%d Invalid alignment %zu: must be non-zero and a " + "power of 2\n", + __func__, + __LINE__, + phys_alignment_byte); + return NULL; + } + + if (0 != __qae_memInit()) + return NULL; + if (size > QAE_MAX_ALLOC_SIZE) { CMD_ERROR( @@ -437,11 +468,9 @@ void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) return NULL; } - if (!phys_alignment_byte || phys_alignment_byte > QAE_MAX_PHYS_ALIGN || - (phys_alignment_byte & (phys_alignment_byte - 1))) + if (phys_alignment_byte > QAE_MAX_PHYS_ALIGN) { - CMD_ERROR("%s:%d Invalid alignment parameter %zu. It must be non zero, " - "not more than %llu and multiple of 2 \n", + CMD_ERROR("%s:%d Invalid alignment %zu exceeds maximum %llu\n", __func__, __LINE__, phys_alignment_byte, @@ -449,9 +478,6 @@ void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) return NULL; } - if (0 != qaeMemInit()) - return NULL; - if (!qae_mem_inited) { qae_mem_init_t(); diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c b/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c new file mode 100644 index 00000000..c1e44cac --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.c @@ -0,0 +1,173 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ +/** + **************************************************************************** + * @file qae_mem_sysfs_utils.c + * + * Helpers to read hugepage counters from sysfs and to initialise the + * per-process hugepage configuration from environment variables. + * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "qae_mem_utils.h" +#include "qae_mem_user_utils.h" +#include "qae_mem_utils_common.h" +#include "qae_mem_sysfs_utils.h" +#include "qae_mem_hugepage_utils.h" + +/* Max environment variable value 64k */ +#define MAX_ENV_VAL (0x10000) + +/* Read the current free 2M hugepage count from sysfs. */ +API_LOCAL +int __qae_read_free_hugepages(void) +{ + unsigned long val = 0; + + if (parse_sysfs_value(SYSFS_2M_FREE_HUGEPAGES, &val) < 0) + return -EIO; + + return val; +} + +/* parse_uint32_env - parse an env var string as uint32_t. + * + * NULL or empty string (var exported without a value) → *out = 0. + * Non-empty malformed string → *out = 0 (warn). + * Non-empty valid decimal integer ≤ MAX_ENV_VAL → *out = parsed value. + */ +static void parse_uint32_env(const char *name, const char *env, uint32_t *out) +{ + char *endptr = NULL; + unsigned long val; + + /* used only in CMD_DEBUG, suppress warning in non-debug builds */ + UNUSED(name); + + *out = 0; + if (!env || *env == '\0') + return; + + errno = 0; + val = strtoul(env, &endptr, 10); + if (errno != 0 || endptr == env || *endptr != '\0' || val > MAX_ENV_VAL) + { + CMD_DEBUG("%s: invalid %s value '%s', treating as zero\n", + __func__, + name, + env); + return; + } + *out = (uint32_t)val; +} + +/* __qae_hugepage_config_init - Read QAT_MAX_2M_HPG_PER_PROCESS env var to + * determine hugepage mode and set per-process page budget. + * + * Decision rules: + * - Var not exported → 4K mode (return 0) + * - Var exported, zero (or no value) → 4K mode (return 0) + * - Var non-zero, nr_hugepages=0 → error (return -EINVAL) + * - Var non-zero, nr_hugepages>0 → 2M mode, budget=env value + * + * Returns the env variable value as budget on success, 0 for 4K mode, + * or -EINVAL on error. The caller must propagate a negative return. + */ +API_LOCAL +int __qae_hugepage_config_init(void) +{ + const char *env_2m = getenv("QAT_MAX_2M_HPG_PER_PROCESS"); + uint32_t val_2m = 0; + + if (!env_2m) + { + CMD_DEBUG("%s: no hugepage env var set, defaulting to 4K mode.\n", + __func__); + return 0; + } + + parse_uint32_env("QAT_MAX_2M_HPG_PER_PROCESS", env_2m, &val_2m); + + if (val_2m > 0) + { + DIR *hp_dir = qae_opendir(SYSFS_2M_HUGEPAGES_DIR); + unsigned long nr_hp = 0; + + if (!hp_dir) + { + CMD_ERROR("%s: No 2M huge pages configured in the system\n", + __func__); + return -EINVAL; + } + closedir(hp_dir); + + if (parse_sysfs_value(SYSFS_2M_NR_HUGEPAGES, &nr_hp) < 0) + return -EIO; + + if (!nr_hp) + { + CMD_ERROR("%s: No 2M huge pages configured in the system\n", + __func__); + return -EINVAL; + } + CMD_DEBUG("%s: 2M mode: nr_hugepages=%lu budget=%u\n", + __func__, + nr_hp, + val_2m); + return (int32_t)val_2m; + } + else + { + CMD_DEBUG("%s: hugepage env var is zero, defaulting to 4K mode.\n", + __func__); + return 0; + } +} + +/* Parse a sysfs (or other) file containing one unsigned long value. + * Returns 0 on success, -EINVAL on error. + */ +int parse_sysfs_value(const char *filename, unsigned long *val) +{ + FILE *f; + char buf[BUFSIZ]; + char *end = NULL; + + if ((f = qae_fopen(filename, "r")) == NULL) + { + CMD_ERROR("%s(): qae_fopen failed for %s\n", __func__, filename); + return -EINVAL; + } + + if (qae_fgets(buf, sizeof(buf), f) == NULL) + { + CMD_ERROR( + "%s(): qae_fgets failed for sysfs value %s\n", __func__, filename); + fclose(f); + return -EINVAL; + } + errno = 0; + *val = strtoul(buf, &end, 0); + if (errno != 0 || (buf[0] == '\0') || (end == NULL) || + ((*end != '\n') && (*end != '\0')) || (*val > MAX_ENV_VAL)) + { + CMD_ERROR("%s(): cannot parse sysfs value %s\n", __func__, filename); + fclose(f); + return -EINVAL; + } + fclose(f); + return 0; +} diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.h new file mode 100644 index 00000000..2af596f3 --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_sysfs_utils.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * + * SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2007-2026 Intel Corporation + * + * These contents may have been developed with support from one or more + * Intel-operated generative artificial intelligence solutions. + * + ***************************************************************************/ +/* + **************************************************************************** + * @file qae_mem_sysfs_utils.h + * + * sysfs helpers for reading hugepage counters and initialising the + * per-process hugepage configuration from environment variables. + * + ***************************************************************************/ +#ifndef QAE_MEM_SYSFS_UTILS_H +#define QAE_MEM_SYSFS_UTILS_H + +#include + +/* sysfs paths for 2MB hugepage counters. */ +#define SYSFS_2M_HUGEPAGES_DIR "/sys/kernel/mm/hugepages/hugepages-2048kB" +#define SYSFS_2M_FREE_HUGEPAGES \ + "/sys/kernel/mm/hugepages/hugepages-2048kB/free_hugepages" +#define SYSFS_2M_NR_HUGEPAGES \ + "/sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages" + +/* + * __qae_hugepage_config_init - configure hugepage mode and set per-process + * budget. + * + * Reads QAT_MAX_2M_HPG_PER_PROCESS and validates against sysfs nr_hugepages. + * + * Returns the env variable value as budget on success, 0 if no env var is + * set or env var is zero, or -EINVAL on error (env non-zero but system has + * no hugepages configured). + * The caller must propagate the error rather than silently falling back. + */ +int __qae_hugepage_config_init(void); + +/* + * __qae_read_free_hugepages - read current free 2M hugepage count + * from sysfs. + * + * Returns no. of free hugepages value or negative errno on error. + */ +int __qae_read_free_hugepages(void); + +/* + * parse_sysfs_value - read one unsigned long integer from a sysfs file. + * + * @filename: full path to the sysfs file + * @val: output pointer, set on success + * + * Returns 0 on success, negative errno on error. + */ +int parse_sysfs_value(const char *filename, unsigned long *val); + +#endif /* QAE_MEM_SYSFS_UTILS_H */ diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_user_utils.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_user_utils.h index 13d4b160..509cc73b 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_user_utils.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_user_utils.h @@ -27,6 +27,7 @@ #define unlikely(x) (0 == (x)) #endif +#ifndef API_LOCAL #if __GNUC__ >= 4 #define API_PUBLIC __attribute__((visibility("default"))) #define API_LOCAL __attribute__((visibility("hidden"))) @@ -34,6 +35,7 @@ #define API_PUBLIC #define API_LOCAL #endif +#endif /* API_LOCAL */ #ifdef ICP_DEBUG static inline void CMD_DEBUG(const char *format, ...) diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c b/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c index 6b0b3c19..e0fad8b8 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.c @@ -39,6 +39,7 @@ #include "qae_mem_utils_common.h" load_addr_fptr_t load_addr_fptr = load_addr; +store_mmap_range_fptr_t store_mmap_range_fptr = store_mmap_range; const uint64_t __qae_bitmask[65] = { 0x0000000000000000ULL, 0x0000000000000001ULL, 0x0000000000000003ULL, @@ -72,7 +73,7 @@ const uint64_t __qae_bitmask[65] = { * returns the 64-bit window from the BITMAP_LENx64 bitmap. * Each bit represents a 1k block in the 2 Meg buffer */ -STATIC uint64_t bitmap_read(uint64_t *map, size_t window_pos) +STATIC uint64_t bitmap_read(uint64_t *map, size_t window_pos, size_t map_len) { uint64_t quad_word_window = 0ULL; uint64_t next_quad_word = 0ULL; @@ -81,7 +82,7 @@ STATIC uint64_t bitmap_read(uint64_t *map, size_t window_pos) quad_word_pos = window_pos / QWORD_WIDTH; - if (quad_word_pos >= BITMAP_LEN) + if (quad_word_pos >= map_len) { return QWORD_ALL_ONE; } @@ -141,7 +142,7 @@ void *__qae_mem_alloc(block_ctrl_t *block_ctrl, size_t size, size_t align) bitmap = block_ctrl->bitmap; - blocks_required = div_round_up(size, UNIT_SIZE); + blocks_required = div_round_up(size, block_ctrl->unit_size); window_pos = 0; first_block = window_pos; @@ -149,7 +150,8 @@ void *__qae_mem_alloc(block_ctrl_t *block_ctrl, size_t size, size_t align) do { /* read 64-bit bitmap window from window_pos (0-BITMAP_LEN*64) */ - bitmap_window = bitmap_read(bitmap, window_pos); + bitmap_window = + bitmap_read(bitmap, window_pos, block_ctrl->max_num_bitmaps); /* find number of contiguous 0s from right */ width = mem_ctzll(bitmap_window); @@ -161,21 +163,22 @@ void *__qae_mem_alloc(block_ctrl_t *block_ctrl, size_t size, size_t align) { /* calculate return address from virtual address and first block number */ - retval = (uint8_t *)(block_ctrl) + first_block * UNIT_SIZE; - if (first_block + blocks_required > BITMAP_LEN * QWORD_WIDTH) + retval = + (uint8_t *)(block_ctrl) + first_block * block_ctrl->unit_size; + if (first_block + blocks_required > block_ctrl->max_num_blocks) { CMD_ERROR("%s:%d Allocation error - Required blocks exceeds " "bitmap window. Block index = %zu, Blocks required" - " = %zu and Bitmap window = %ld \n", + " = %zu and Bitmap window = %zu \n", __func__, __LINE__, first_block, blocks_required, - (BITMAP_LEN * QWORD_WIDTH)); + block_ctrl->max_num_blocks); return NULL; } /* save length in the reserved area right after the bitmap */ - block_ctrl->sizes[first_block] = (uint16_t)blocks_required; + block_ctrl->sizes[first_block] = (uint32_t)blocks_required; /* set bit maps from bit position (0<->BITMAP_LEN*64 -1) = * first_block(0<->BITMAP_LEN*64-1) * with blocks_required length in bitmap @@ -214,7 +217,7 @@ void *__qae_mem_alloc(block_ctrl_t *block_ctrl, size_t size, size_t align) window_pos += width; } } - } while (window_pos < BITMAP_LEN * QWORD_WIDTH); + } while (window_pos < block_ctrl->max_num_blocks); return retval; } @@ -246,13 +249,14 @@ bool __qae_mem_free(block_ctrl_t *block_ctrl, void *block, bool secure_free) return false; } - if ((uintptr_t)block % UNIT_SIZE) + if ((uintptr_t)block % block_ctrl->unit_size) { - CMD_ERROR("%s:%d Block address(%p) must be multiple of Unit size(%d)\n", - __func__, - __LINE__, - block, - UNIT_SIZE); + CMD_ERROR( + "%s:%d Block address(%p) must be multiple of Unit size(%zu)\n", + __func__, + __LINE__, + block, + block_ctrl->unit_size); return false; } @@ -262,8 +266,8 @@ bool __qae_mem_free(block_ctrl_t *block_ctrl, void *block, bool secure_free) * buffer and block retrieve first_block and length of block from integer * at the start of block */ - first_block = - ((uintptr_t)start_of_block - (uintptr_t)block_ctrl) / UNIT_SIZE; + first_block = ((uintptr_t)start_of_block - (uintptr_t)block_ctrl) / + block_ctrl->unit_size; length = block_ctrl->sizes[first_block]; if (!length) @@ -278,7 +282,7 @@ bool __qae_mem_free(block_ctrl_t *block_ctrl, void *block, bool secure_free) return false; } - if (length + first_block > BITMAP_LEN * QWORD_WIDTH) + if (length + first_block > block_ctrl->max_num_blocks) { CMD_ERROR("%s:%d Invalid block address provided - " "block length exceeds bitmap window. block index = %zu " diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.h b/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.h index 41d1a167..91cf48fb 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_utils_common.h @@ -72,11 +72,11 @@ typedef struct extern page_table_t g_page_table; extern const uint64_t __qae_bitmask[65]; extern int g_fd; -extern uint32_t normalAllocations_g; extern free_page_table_fptr_t free_page_table_fptr; extern load_addr_fptr_t load_addr_fptr; extern load_key_fptr_t load_key_fptr; +extern store_mmap_range_fptr_t store_mmap_range_fptr; API_LOCAL int __qae_open(void); @@ -122,6 +122,45 @@ static inline size_t round_up(const size_t n, const size_t s) return ((n + s - 1) / s) * s; } +static inline size_t get_header_size(const size_t num_blocks) +{ + return sizeof(block_ctrl_t) + + (num_blocks / QWORD_WIDTH + 1) * sizeof(uint64_t) + + num_blocks * sizeof(uint32_t); +} + +/* Compute the base pointer of the sizes[] region that lives immediately + * after bitmap[] in the slab. The sizes array holds the allocation length + * (in units) for each block index: 0 = free, >0 = number of consecutive + * units owned by the allocation starting at that index. + */ +static inline uint32_t *block_ctrl_sizes(block_ctrl_t *bc) +{ + return (uint32_t *)(bc->bitmap + bc->max_num_bitmaps + 1); +} + +static inline void set_bitmap(uint64_t *bitmap, const size_t index, size_t len); + +/* Initialise the geometry fields of a freshly-allocated block_ctrl_t and + * set up the sizes[] pointer to reference the slab region immediately + * after the bitmap sentinel word. The caller is responsible for zeroing + * the bitmap[] and sizes[] regions before use. + */ +static inline void init_block_ctrl(block_ctrl_t *bc, const size_t unit_size) +{ + bc->unit_size = unit_size; + bc->max_num_blocks = bc->mem_info.size / unit_size; + bc->max_num_bitmaps = bc->max_num_blocks / QWORD_WIDTH; + bc->header_size = get_header_size(bc->max_num_blocks); + bc->reserved_units = div_round_up(bc->header_size, UNIT_SIZE); + bc->sizes = block_ctrl_sizes(bc); + + /* initialise the bitmap to 1 for reserved blocks */ + set_bitmap(bc->bitmap, 0, bc->reserved_units); + /* make a barrier to stop search at the end of the bitmap */ + bc->bitmap[bc->max_num_bitmaps] = QWORD_ALL_ONE; +} + /* mem_ctzll function * input: a 64-bit bitmap window * output: number of contiguous 0s from least significant bit position diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_page_table_common.h b/quickassist/utilities/libusdm_drv/user_space/qae_page_table_common.h index f5a5841c..314b4af6 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_page_table_common.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_page_table_common.h @@ -35,6 +35,9 @@ void __qae_set_loadaddr_fptr(load_addr_fptr_t fp); API_LOCAL void __qae_set_loadkey_fptr(load_key_fptr_t fp); +API_LOCAL +void __qae_set_storemmap_fptr(store_mmap_range_fptr_t fp); + static inline void *qae_memzero(void *const ptr, const size_t count) { uint32_t lim = 0; @@ -59,7 +62,7 @@ static inline void *qae_memzero_explicit(void *const ptr, const size_t count) } #ifdef __STDC_LIB_EXT1__ errno_t result = - memset_s(ptr, sizeof(ptr), 0, count); /* Supported on C11 standard */ + memset_s(ptr, count, 0, count); /* Supported on C11 standard */ if (result != 0) { return NULL; @@ -145,6 +148,52 @@ static inline void store_addr(page_table_t *level, level->next[id.pg_entry.idxl0].pa = phys; } +/* 1GB hugepage store: stop one level earlier (L2) and write base + * physical address + */ +static inline void store_addr_gpg(page_table_t *level, + uintptr_t virt, + uint64_t phys) +{ + page_index_t id; + + id.addr = virt; + + level = next_level(&level->next[id.gpg_entry.idxl4].pt); + if (NULL == level) + return; + + level = next_level(&level->next[id.gpg_entry.idxl3].pt); + if (NULL == level) + return; + + level->next[id.gpg_entry.idxl2].pa = phys; +} + +static inline uint64_t get_key(const uint64_t phys) +{ + /* Derive a 12-bit key from the physical address. + * - For 1GB use bits 30..41 + * - For other cases use bits 20..31 + * The key is always 12 bits and is stored in the lower 12 bits of + * the encoded physical address (compatible with load_key* functions). + */ + return (phys >> 30 ^ phys >> 20) & ~QAE_PAGE_MASK; +} + +static inline void store_mmap_range_gpg(page_table_t *p_level, + void *p_virt, + uint64_t p_phys, + size_t p_size) +{ + size_t offset; + const uintptr_t virt = (uintptr_t)p_virt; + + p_phys = (p_phys & HUGEPAGE_1G_MASK) | get_key(p_phys); + for (offset = 0; offset < p_size; offset += HUGEPAGE_1G_SIZE) + store_addr_gpg(p_level, virt + offset, p_phys + offset); +} + static inline void store_addr_hpg(page_table_t *level, uintptr_t virt, uint64_t phys) @@ -168,44 +217,30 @@ static inline void store_addr_hpg(page_table_t *level, level->next[id.hpg_entry.idxl1].pa = phys; } -static inline uint64_t get_key(const uint64_t phys) +static inline void store_mmap_range_hpg(page_table_t *p_level, + void *p_virt, + uint64_t p_phys, + size_t p_size) { - /* For 4KB page: use bits 20-31 of a physical address as a hash key. - * It provides a good distribution for 1Mb/2Mb slabs and a moderate - * distribution for 128Kb/256Kb/512Kbslabs. - */ - return (phys >> 20) & ~QAE_PAGE_MASK; + size_t offset; + const uintptr_t virt = (uintptr_t)p_virt; + + p_phys = (p_phys & HUGEPAGE_MASK) | get_key(p_phys); + for (offset = 0; offset < p_size; offset += HUGEPAGE_SIZE) + store_addr_hpg(p_level, virt + offset, p_phys + offset); } static inline void store_mmap_range(page_table_t *p_level, void *p_virt, uint64_t p_phys, - size_t p_size, - int hp_en) + size_t p_size) { size_t offset; - size_t page_size = PAGE_SIZE; - uint64_t page_mask = QAE_PAGE_MASK; - store_addr_fptr_t store_addr_ptr = store_addr; const uintptr_t virt = (uintptr_t)p_virt; - if (hp_en) - { - page_size = HUGEPAGE_SIZE; - page_mask = HUGEPAGE_MASK; - store_addr_ptr = store_addr_hpg; - } - /* Store the key into the physical address itself, - * for 4KB pages: 12 lower bits are always 0 (physical page addresses - * are 4KB-aligned). - * for 2MB pages: 21 lower bits are always 0 (physical page addresses - * are 2MB-aligned) - */ - p_phys = (p_phys & page_mask) | get_key(p_phys); - for (offset = 0; offset < p_size; offset += page_size) - { - store_addr_ptr(p_level, virt + offset, p_phys + offset); - } + p_phys = (p_phys & QAE_PAGE_MASK) | get_key(p_phys); + for (offset = 0; offset < p_size; offset += PAGE_SIZE) + store_addr(p_level, virt + offset, p_phys + offset); } static inline uint64_t load_addr(page_table_t *level, void *virt) @@ -237,6 +272,28 @@ static inline uint64_t load_addr(page_table_t *level, void *virt) return (phy_addr & QAE_PAGE_MASK) | id.pg_entry.offset; } +/* 1GB hugepage load: base physical address at L2, 30-bit offset */ +static inline uint64_t load_addr_gpg(page_table_t *level, void *virt) +{ + page_index_t id; + uint64_t phy_addr; + + id.addr = (uintptr_t)virt; + + level = level->next[id.gpg_entry.idxl4].pt; + if (NULL == level) + return 0; + + level = level->next[id.gpg_entry.idxl3].pt; + if (NULL == level) + return 0; + + phy_addr = level->next[id.gpg_entry.idxl2].pa; + if (0 == phy_addr) + return 0; + return (phy_addr & HUGEPAGE_1G_MASK) | id.gpg_entry.offset; +} + static inline uint64_t load_addr_hpg(page_table_t *level, void *virt) { page_index_t id; @@ -321,4 +378,34 @@ static inline void free_page_table_hpg(page_table_t *const table) memset(table, 0, sizeof(page_table_t)); } +/* Free page table for 1GB hugepages: 1+2 levels (L4->L3->L2). + * Root holds L4 entries; two allocated sub-levels use L3 and L2 (PA) indices. + * free_page_level(table, 2) frees the two sub-levels; root is only zeroed. + */ +static inline void free_page_table_gpg(page_table_t *const table) +{ + free_page_level(table, 2); + memset(table, 0, sizeof(page_table_t)); +} + +/* Hash key load for 1GB hugepages: reads key from L2 level */ +static inline uint64_t load_key_gpg(page_table_t *level, void *virt) +{ + page_index_t id; + uint64_t phy_addr; + + id.addr = (uintptr_t)virt; + + level = level->next[id.gpg_entry.idxl4].pt; + if (NULL == level) + return 0; + + level = level->next[id.gpg_entry.idxl3].pt; + if (NULL == level) + return 0; + + phy_addr = level->next[id.gpg_entry.idxl2].pa; + return phy_addr & ~QAE_PAGE_MASK; +} + #endif /* QAE_PAGE_TABLE_COMMON_H */ diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_page_table_defs.h b/quickassist/utilities/libusdm_drv/user_space/qae_page_table_defs.h index dac13574..16b652c6 100644 --- a/quickassist/utilities/libusdm_drv/user_space/qae_page_table_defs.h +++ b/quickassist/utilities/libusdm_drv/user_space/qae_page_table_defs.h @@ -33,10 +33,16 @@ #define QAE_PAGE_MASK (~(PAGE_SIZE - 1)) #define LEVEL_SIZE (PAGE_SIZE / sizeof(uint64_t)) +/* 2MB hugepage */ #define HUGEPAGE_SIZE (0x200000) #define HUGEPAGE_SHIFT (21) #define HUGEPAGE_MASK (~(HUGEPAGE_SIZE - 1)) +/* 1GB hugepage */ +#define HUGEPAGE_1G_SIZE (0x40000000) +#define HUGEPAGE_1G_SHIFT (30) +#define HUGEPAGE_1G_MASK (~(HUGEPAGE_1G_SIZE - 1)) + typedef struct { uint64_t offset : 12; @@ -56,10 +62,20 @@ typedef struct uint64_t idxl4 : 9; } hugepage_entry_t; +/* 1GB hugepage page-index breakdown: uses L4->L3->base at L2, 30-bit offset */ +typedef struct +{ + uint64_t offset : 30; + uint64_t idxl2 : 9; + uint64_t idxl3 : 9; + uint64_t idxl4 : 9; +} gigapage_entry_t; + typedef union { uint64_t addr; page_entry_t pg_entry; hugepage_entry_t hpg_entry; + gigapage_entry_t gpg_entry; } page_index_t; typedef struct page_table_t @@ -71,8 +87,11 @@ typedef struct page_table_t } page_table_t; typedef void (*free_page_table_fptr_t)(page_table_t *const table); -typedef void (*store_addr_fptr_t)(page_table_t *, uintptr_t, uint64_t); typedef uint64_t (*load_addr_fptr_t)(page_table_t *, void *); typedef uint64_t (*load_key_fptr_t)(page_table_t *, void *); +typedef void (*store_mmap_range_fptr_t)(page_table_t *, + void *, + uint64_t, + size_t); #endif /* QAE_PAGE_TABLE_DEFS_H */ diff --git a/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_hugepage_utils_vfio.c b/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_hugepage_utils_vfio.c index 548d6686..ad5722a3 100644 --- a/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_hugepage_utils_vfio.c +++ b/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_hugepage_utils_vfio.c @@ -35,6 +35,7 @@ #include "qae_mem_user_utils.h" #include "qae_mem_utils_common.h" #include "qae_mem_utils.h" +#include "qae_mem_sysfs_utils.h" #include "qae_page_table_common.h" #ifdef ICP_THREAD_SPECIFIC_USDM #include "qae_mem_multi_thread.h" @@ -42,86 +43,35 @@ static bool g_hugepages_enabled = false; static size_t g_num_hugepages = 0; -static const char sys_dir_path[] = "/sys/kernel/mm/hugepages"; +/* hugepages allocated by this process */ +static size_t g_alloc_hugepages = 0; extern int vfio_container_fd; extern int g_noiommu_enabled; #define UMASK_OWNER_ONLY 0077 #define HUGEPAGE_FILE_DIR "/dev/hugepages/qat/qat-usdm.XXXXXX" #define HUGEPAGE_FILE_LEN (sizeof(HUGEPAGE_FILE_DIR)) -#define HUGEPAGE_SYS_NODE "hugepages-2048kB" -#define HUGEPAGE_SOCKET_PATH_SIZE 50 -#define HUGEPAGE_SYSFS_PATH_SIZE HUGEPAGE_SOCKET_PATH_SIZE + 32 /* The pfn (page frame number) are bits 0-54 of page. */ #define PFN_MASK 0x7fffffffffffffULL #define PAGEMAP_FILE "/proc/self/pagemap" -/* Parse a sysfs (or other) file containing one integer value */ -static int parse_sysfs_value(const char *filename, unsigned long *val) +static inline void reset_hp(const int limit) { - FILE *f; - char buf[BUFSIZ]; - char *end = NULL; - - if ((f = qae_fopen(filename, "r")) == NULL) - { - CMD_ERROR("%s(): qae_fopen failed for %s\n", __func__, filename); - return -1; - } - - if (qae_fgets(buf, sizeof(buf), f) == NULL) - { - CMD_ERROR( - "%s(): qae_fgets failed for sysfs value %s\n", __func__, filename); - fclose(f); - return -1; - } - *val = strtoul(buf, &end, 0); - if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) - { - CMD_ERROR("%s(): cannot parse sysfs value %s\n", __func__, filename); - fclose(f); - return -1; - } - fclose(f); - return 0; + g_num_hugepages = limit; + g_alloc_hugepages = 0; } -static int get_num_hugepages_per_system(const char *subdir) +static inline void inc_hp(void) { - char path[HUGEPAGE_SYSFS_PATH_SIZE] = { '\0' }; - char socketpath[HUGEPAGE_SOCKET_PATH_SIZE] = { '\0' }; - DIR *socketdir; - unsigned long num_pages = 0; - const char nr_hp_file[] = "nr_hugepages"; - - snprintf(socketpath, sizeof(socketpath), "%s/%s", sys_dir_path, subdir); - - socketdir = qae_opendir(socketpath); - if (socketdir) - { - closedir(socketdir); - } - else - { - if (g_hugepages_enabled) - return -EIO; - /* - * HUGETLBFS is not configured in kernel. - * Number of hugepages should be 0 - */ - g_num_hugepages = 0; - return 0; - } - - snprintf(path, sizeof(path), "%s/%s", socketpath, nr_hp_file); - if (parse_sysfs_value(path, &num_pages) < 0) - return -EIO; - - g_num_hugepages = num_pages; + g_num_hugepages--; + g_alloc_hugepages++; +} - return 0; +static inline void dec_hp(void) +{ + g_num_hugepages++; + g_alloc_hugepages--; } /* @@ -198,8 +148,25 @@ API_LOCAL int __qae_vfio_init_hugepages() { int ret = 0; - if (get_num_hugepages_per_system(HUGEPAGE_SYS_NODE)) - return -EIO; + /* QAT_MAX_2M_HPG_PER_PROCESS controls hugepage mode: + * NULL/empty/zero -> 4K; positive value -> 2M with budget. + * + * Read config *before* touching state, so a failure (e.g. sysfs check + * returning -EINVAL on re-init) leaves the previously-configured + * g_num_hugepages / g_hugepages_enabled intact. + */ + int budget = __qae_hugepage_config_init(); + + if (budget < 0) + { + CMD_ERROR("%s:%d Hugepages are not configured on system, ret = %d\n", + __func__, + __LINE__, + budget); + return budget; + } + + reset_hp(budget); if (g_num_hugepages > 0) { @@ -207,6 +174,8 @@ int __qae_vfio_init_hugepages() __qae_set_free_page_table_fptr(free_page_table_hpg); __qae_set_loadaddr_fptr(load_addr_hpg); __qae_set_loadkey_fptr(load_key_hpg); + __qae_set_storemmap_fptr(store_mmap_range_hpg); + CMD_DEBUG("%s:%d 2MB huge page mode enabled.\n", __func__, __LINE__); } else { @@ -214,6 +183,8 @@ int __qae_vfio_init_hugepages() __qae_set_free_page_table_fptr(free_page_table); __qae_set_loadaddr_fptr(load_addr); __qae_set_loadkey_fptr(load_key); + __qae_set_storemmap_fptr(store_mmap_range); + CMD_DEBUG("%s:%d 4K page mode.\n", __func__, __LINE__); } return ret; } @@ -298,21 +269,32 @@ dev_mem_info_t *__qae_vfio_hugepage_alloc_slab(const int fd, const uint32_t alignment) { dev_mem_info_t *slab = NULL; + int free_hp = 0; int ret = 0; UNUSED(fd); - if (get_num_hugepages_per_system(HUGEPAGE_SYS_NODE)) - return NULL; - if (!g_num_hugepages) { - CMD_ERROR("%s:%d mmap: exceeded max huge pages allocations for this " - "process.\n", + CMD_ERROR("%s:%d Process quota for 2M Huge pages exhausted\n", __func__, __LINE__); return NULL; } + free_hp = __qae_read_free_hugepages(); + if (free_hp <= 0) + { + if (!g_alloc_hugepages) + CMD_ERROR("%s:%d 2M huge pages configured but consumed by " + "other processes\n", + __func__, + __LINE__); + else + CMD_ERROR( + "%s:%d System 2M Huge pages exhausted\n", __func__, __LINE__); + return NULL; + } + slab = __qae_vfio_hugepage_mmap_addr(size); if (!slab) { @@ -322,6 +304,7 @@ dev_mem_info_t *__qae_vfio_hugepage_alloc_slab(const int fd, return NULL; } + inc_hp(); slab->nodeId = node; slab->size = size; slab->type = type; @@ -380,9 +363,14 @@ dev_mem_info_t *__qae_vfio_hugepage_alloc_slab(const int fd, return slab; error: - if (!g_noiommu_enabled) + dec_hp(); + if (!g_noiommu_enabled && slab->phy_addr) iova_release(slab->phy_addr, slab->size); +#ifdef ICP_THREAD_SPECIFIC_USDM + remove_slab_from_tmp_list(slab); +#endif + qae_munmap(slab, size); return NULL; @@ -393,7 +381,9 @@ void __qae_vfio_hugepage_free_slab(dev_mem_info_t *memInfo) { close(memInfo->hpg_fd); - iova_release(memInfo->phy_addr, memInfo->size); + dec_hp(); + if (!g_noiommu_enabled) + iova_release(memInfo->phy_addr, memInfo->size); if (vfio_container_fd < 0) return; diff --git a/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_utils_vfio.c b/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_utils_vfio.c index 21de89dd..aa39c1b4 100644 --- a/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_utils_vfio.c +++ b/quickassist/utilities/libusdm_drv/user_space/vfio/qae_mem_utils_vfio.c @@ -93,6 +93,12 @@ void __qae_set_loadkey_fptr(load_key_fptr_t fp) load_key_fptr = fp; } +API_LOCAL +void __qae_set_storemmap_fptr(store_mmap_range_fptr_t fp) +{ + store_mmap_range_fptr = fp; +} + /* * Each IOVA_SLAB represents a set of memory pages of size 2MB that * are contiguous from the viewpoint of the IO device. @@ -269,7 +275,8 @@ static inline void ioctl_free_slab(const int fd, dev_mem_info_t *memInfo) { UNUSED(fd); - iova_release(memInfo->phy_addr, memInfo->size); + if (!g_noiommu_enabled) + iova_release(memInfo->phy_addr, memInfo->size); if (vfio_container_fd < 0) return; @@ -348,7 +355,7 @@ uint64_t allocate_iova(const uint32_t size, uint32_t alignment) if (unlikely(mem_mutex_lock(&iova_mutex))) { CMD_ERROR( - "%s:%d Error on thread iova_mutex lock %s\n", __func__, __LINE__); + "%s:%d Error on thread iova_mutex lock\n", __func__, __LINE__); return 0; } #endif @@ -374,7 +381,7 @@ uint64_t allocate_iova(const uint32_t size, uint32_t alignment) #ifdef ICP_THREAD_SPECIFIC_USDM if (unlikely(mem_mutex_unlock(&iova_mutex))) { - CMD_ERROR("%s:%d Error on thread iova_mutex unlock %s\n", + CMD_ERROR("%s:%d Error on thread iova_mutex unlock\n", __func__, __LINE__); return 0; @@ -388,7 +395,7 @@ uint64_t allocate_iova(const uint32_t size, uint32_t alignment) if (unlikely(mem_mutex_unlock(&iova_mutex))) { CMD_ERROR( - "%s:%d Error on thread iova_mutex unlock %s\n", __func__, __LINE__); + "%s:%d Error on thread iova_mutex unlock\n", __func__, __LINE__); } #endif @@ -522,7 +529,11 @@ static inline dev_mem_info_t *ioctl_alloc_slab(const int fd, return slab; error: - iova_release(slab->phy_addr, slab->size); + if (!g_noiommu_enabled && slab->phy_addr) + iova_release(slab->phy_addr, slab->size); +#ifdef ICP_THREAD_SPECIFIC_USDM + remove_slab_from_tmp_list(slab); +#endif if (SMALL == type) { qae_munmap(slab, slab->size); @@ -1092,7 +1103,7 @@ uint64_t qaeMemMapContiguousIova(void *virt, size_t size) * to load_addr_hpg which expects 2MB entries. If disabled, it points to * load_addr which expects 4KB entries. */ - store_mmap_range(&g_page_table, virt, iova, size, __qae_hugepage_enabled()); + store_mmap_range_fptr(&g_page_table, virt, iova, size); error: ret = mem_mutex_unlock(&mutex); @@ -1202,7 +1213,7 @@ int qaeMemUnmapContiguousIova(void *virt, size_t size) * Clear the page table entries for qaeVirtToPhysNUMA. * Use the same granularity as when we stored the mapping. */ - store_mmap_range(&g_page_table, virt, 0, size, __qae_hugepage_enabled()); + store_mmap_range_fptr(&g_page_table, virt, 0, size); /* Unmap from IOMMU if container is active */ if (vfio_container_fd >= 0) @@ -1230,3 +1241,4 @@ int qaeMemUnmapContiguousIova(void *virt, size_t size) return ret; #endif } + diff --git a/quickassist/utilities/osal/include/Osal.h b/quickassist/utilities/osal/include/Osal.h index 8432c251..5226b858 100644 --- a/quickassist/utilities/osal/include/Osal.h +++ b/quickassist/utilities/osal/include/Osal.h @@ -20,9 +20,6 @@ extern "C" { #include "OsalOsTypes.h" #include "OsalTypes.h" -#ifndef DISABLE_NUMA_ALLOCATION -#include "OsalDevDrvCommon.h" -#endif #define OSAL_HOST_TO_NW_16(uData) OSAL_OS_HOST_TO_NW_16(uData) #define OSAL_HOST_TO_NW_32(uData) OSAL_OS_HOST_TO_NW_32(uData) @@ -1720,49 +1717,6 @@ int osalIOMMUMap(UINT64 phaddr, UINT64 iova, size_t size); */ int osalIOMMUUnmap(UINT64 iova, size_t size); -/** - * @ingroup Osal - * - * @brief Function translates io virtual address - * to a physical address. - * - * @param in - IO virtual address. - * - * @li Reentrant: no - * @li IRQ safe: no - * - * @return - host physical address - */ -UINT64 osalIOMMUVirtToPhys(UINT64 iova); - -/** - * @ingroup Osal - * - * @brief Function attaches pci dev to iommu domain. - * - * @param in - Device to be attached. - * - * @li Reentrant: no - * @li IRQ safe: no - * - * @return - OSAL_SUCCESS/OSAL_FAIL - */ -int osalIOMMUAttachDev(void *dev); - -/** - * @ingroup Osal - * - * @brief Function detaches pci dev to iommu domain. - * - * @param in - Device to be detached. - * - * @li Reentrant: no - * @li IRQ safe: no - * - * @return - void - */ -void osalIOMMUDetachDev(void *dev); - /** * @ingroup Osal * @@ -1777,34 +1731,6 @@ void osalIOMMUDetachDev(void *dev); */ size_t osalIOMMUgetRemappingSize(size_t size); -/** - * @ingroup Osal - * - * @brief Function creates iommu domain. - * - * @param none - * - * @li Reentrant: no - * @li IRQ safe: no - * - * @return - OSAL_SUCCESS/OSAL_FAIL - */ -int osalIOMMUInit(void); - -/** - * @ingroup Osal - * - * @brief Function removes iommu domain. - * - * @param none - * - * @li Reentrant: no - * @li IRQ safe: no - * - * @return - void - */ -void osalIOMMUExit(void); - /** * @ingroup Osal * diff --git a/quickassist/utilities/osal/include/OsalDevDrvCommon.h b/quickassist/utilities/osal/include/OsalDevDrvCommon.h index 006a6424..c16788df 100644 --- a/quickassist/utilities/osal/include/OsalDevDrvCommon.h +++ b/quickassist/utilities/osal/include/OsalDevDrvCommon.h @@ -20,260 +20,6 @@ extern "C" { #endif -#include "OsalOsTypes.h" -#pragma pack(push) /* Push the current alignment on the stack */ -#pragma pack(1) /* Force alignment on 1 byte to support 32 \ - bits user space on 64 bits kernels */ -/* Number of allocated pages for memory managements - * For kernel which can allocate 4M, then value can be 512 - * So that the performance can be improved - * For legacy old kernel, the value can be 32, that is 128k - */ -#ifndef ICP_NUM_PAGES_PER_ALLOC -#ifndef ICP_SRIOV -#define NUM_PAGES_PER_ALLOC 512 -#else -#define NUM_PAGES_PER_ALLOC 256 -#endif -#else -#define NUM_PAGES_PER_ALLOC 32 -#endif -#define DOUBLE_NUM_PAGES_PER_ALLOC (0x2 * NUM_PAGES_PER_ALLOC) - -/* magic used to identify double length - * Need to bigger than 2 of ICP_NUM_PAGES_PER_ALLOC - * The reason is that we will mmap 2*ICP_NUM_PAGES_PER_ALLOC - * to achieve page alignment, and this macro is used when - * user really wants to mmap 2*ICP_NUM_PAGES_PER_ALLOC pages - */ -#define ICP_MMAP_DOUBLE_NUM_PAGES 2048 - -typedef struct dev_mem_info_s -{ - uint32_t id; - /* Id of this block */ - uint32_t nodeId; - /* Node id for NUMA */ - uint32_t size; - /* Size of this block (bytes) */ - uint32_t mmap_size; - /* Size used to call mmap (bytes) */ - uint32_t available_size; - /* Available size remained on the page */ - uint16_t allocations; - /* Counter keeping track of number of allocations */ - union { - void *kmalloc_ptr; - uint64_t padding_kmalloc_ptr; - }; - /* Pointer to mem originally returned by kmalloc */ - union { - int32_t *kmalloc_area; - uint64_t padding_kmalloc_area; - }; - /* Pointer to kmalloc'd area rounded up to a page boundary */ - UINT64 phy_addr; - /* Physical address of the kmalloced area */ - union { - void *virt_addr; - uint64_t padding_virt_addr; - }; - /* Base address in user space - i.e. virtual address */ - union { - void *fvirt_addr; - uint64_t padding_fvirt_addr; - }; - /* virtual address return from mmap, and it is saved for munmap*/ - /* Please be noted that padding should be used to make the same - structure size for both 32 bit and 64 bit - */ - union { - struct dev_mem_info_s *pPrev; - uint64_t padding_pPrev; - }; - union { - struct dev_mem_info_s *pNext; - uint64_t padding_pNext; - }; -} dev_mem_info_t; - -typedef struct dev_iommu_info_s -{ - uint64_t phaddr; - uint64_t iova; - uint64_t size; -} dev_iommu_info_t; -#pragma pack(pop) /* Restore Previous alignment */ - -typedef struct user_proc_mem_list_s -{ - uint32_t pid; - uint32_t allocs_nr; - uint32_t max_id; - dev_mem_info_t *freed_head; - dev_mem_info_t *freed_tail; - dev_mem_info_t *head; - dev_mem_info_t *tail; - struct user_proc_mem_list_s *pPrev; - struct user_proc_mem_list_s *pNext; -} user_proc_mem_list_t; - -typedef struct user_mem_dev_s -{ - user_proc_mem_list_t *head; - user_proc_mem_list_t *tail; -} user_mem_dev_t; - -#define ADD_ELEMENT_TO_HEAD_OF_LIST(elementtoadd, currentptr, headptr) \ - do \ - { \ - if (NULL == currentptr) \ - { \ - currentptr = elementtoadd; \ - elementtoadd->pNext = NULL; \ - elementtoadd->pPrev = NULL; \ - } \ - else \ - { \ - elementtoadd->pNext = headptr; \ - elementtoadd->pPrev = NULL; \ - headptr->pPrev = elementtoadd; \ - } \ - headptr = elementtoadd; \ - } while (0); - -#define ADD_ELEMENT_TO_END_OF_LIST(elementtoadd, currentptr, headptr) \ - do \ - { \ - if (NULL == currentptr) \ - { \ - currentptr = elementtoadd; \ - elementtoadd->pNext = NULL; \ - elementtoadd->pPrev = NULL; \ - headptr = currentptr; \ - } \ - else \ - { \ - elementtoadd->pPrev = currentptr; \ - currentptr->pNext = elementtoadd; \ - elementtoadd->pNext = NULL; \ - currentptr = elementtoadd; \ - } \ - } while (0); - -#define REMOVE_ELEMENT_FROM_LIST(elementtoremove, currentptr, headptr) \ - do \ - { \ - /*If the previous pointer is not NULL*/ \ - if (NULL != elementtoremove->pPrev) \ - { \ - elementtoremove->pPrev->pNext = elementtoremove->pNext; \ - if (elementtoremove->pNext) \ - { \ - elementtoremove->pNext->pPrev = elementtoremove->pPrev; \ - } \ - else \ - { \ - currentptr = elementtoremove->pPrev; \ - } \ - } \ - else if (NULL != elementtoremove->pNext) \ - { \ - elementtoremove->pNext->pPrev = NULL; \ - headptr = elementtoremove->pNext; \ - } \ - else \ - { \ - currentptr = NULL; \ - headptr = NULL; \ - } \ - } while (0) - -/* IOCTL number for use between the kernel and the user space application */ -#define DEV_MEM_MAGIC 'm' -#define DEV_MEM_CMD_MEMALLOC (0) -#define DEV_MEM_CMD_MEMFREE (1) -#define DEV_MEM_CMD_IOMMUMAP (2) -#define DEV_MEM_CMD_IOMMUUNMAP (3) -#define DEV_MEM_CMD_IOMMUVTOP (4) - -/* IOCTL commands for requesting kernel memory */ -#define DEV_MEM_IOC_MEMALLOC \ - _IOWR(DEV_MEM_MAGIC, DEV_MEM_CMD_MEMALLOC, dev_mem_info_t) - -#define DEV_MEM_IOC_MEMFREE \ - _IOWR(DEV_MEM_MAGIC, DEV_MEM_CMD_MEMFREE, dev_mem_info_t) - -#define DEV_MEM_IOC_IOMMUMAP \ - _IOR(DEV_MEM_MAGIC, DEV_MEM_CMD_IOMMUMAP, dev_iommu_info_t) - -#define DEV_MEM_IOC_IOMMUUNMAP \ - _IOR(DEV_MEM_MAGIC, DEV_MEM_CMD_IOMMUUNMAP, dev_iommu_info_t) - -#define DEV_MEM_IOC_IOMMUVTOP \ - _IOWR(DEV_MEM_MAGIC, DEV_MEM_CMD_IOMMUVTOP, dev_iommu_info_t) - -/* IOCTL number for use between the kernel and the user space application */ -#define DEV_MEM_MAGIC_PAGE 'p' -#define DEV_MEM_CMD_MEMALLOCPAGE (0) -#define DEV_MEM_CMD_MEMFREEPAGE (1) - -/* IOCTL commands for requesting kernel memory */ -#define DEV_MEM_IOC_MEMALLOCPAGE \ - _IOWR(DEV_MEM_MAGIC_PAGE, DEV_MEM_CMD_MEMALLOCPAGE, dev_mem_info_t) - -#define DEV_MEM_IOC_MEMFREEPAGE \ - _IOWR(DEV_MEM_MAGIC_PAGE, DEV_MEM_CMD_MEMFREEPAGE, dev_mem_info_t) - -#define DEV_PATH_SIZE 60 -#define DEV_NAME_SIZE 20 -#define OS_DEV_DIRECTORY "/dev/" -#define DEV_MEM_NAME "icp_dev_mem" -#define DEV_MEM_NAME_PAGE "icp_dev_mem_page" -#define DEV_MEM_PATH "/dev/icp_dev_mem" -#define DEV_MEM_PAGE_PATH "/dev/icp_dev_mem_page" -/** - ******************************************************************************* - * @ingroup Osal - * - * @brief This macro checks if a parameter is within a specified range - * - * @param[in] param Parameter - * @param[in] min Parameter must be greater than OR equal to - * min - * @param[in] max Parameter must be less than max - * - * @return OSAL_FAIL Parameter is outside range - * @return void Parameter is within range - ******************************************************************************/ -#define OSAL_CHECK_PARAM_RANGE(param, min, max) \ - do \ - { \ - if (((param) < (min)) || ((param) >= (max))) \ - { \ - osalLog(OSAL_LOG_LVL_WARNING, \ - OSAL_LOG_DEV_STDOUT, \ - "param is outside valid range\n"); \ - return OSAL_FAIL; \ - } \ - } while (0) - -dev_mem_info_t *userMemAlloc(user_mem_dev_t *dev, - UINT32 sizeInBytes, - UINT32 node, - UINT32 pid); -dev_mem_info_t *userMemGetInfo(user_mem_dev_t *dev, UINT32 id, UINT32 pid); -void userMemFree(user_mem_dev_t *dev, UINT32 id, UINT32 pid); - -dev_mem_info_t *userMemAllocPage(user_mem_dev_t *dev, UINT32 node, UINT32 pid); -dev_mem_info_t *userMemGetInfoPage(user_mem_dev_t *dev, UINT32 id, UINT32 pid); -void userMemFreePage(user_mem_dev_t *dev, UINT32 id, UINT32 pid); - -void userMemFreeAllPid(user_mem_dev_t *dev, UINT32 pid); -void userMemFreeAll(user_mem_dev_t *dev); -void userMemFreeAllPagePid(user_mem_dev_t *dev, UINT32 pid); -void userMemFreeAllPage(user_mem_dev_t *dev); - #ifdef __cplusplus } #endif diff --git a/quickassist/utilities/osal/src/linux/user_space/OsalServices.c b/quickassist/utilities/osal/src/linux/user_space/OsalServices.c index 84137652..abbe22cd 100644 --- a/quickassist/utilities/osal/src/linux/user_space/OsalServices.c +++ b/quickassist/utilities/osal/src/linux/user_space/OsalServices.c @@ -298,7 +298,7 @@ void *osalMemZeroExplicit(void *ptr, UINT32 count) OSAL_MEM_ASSERT(ptr != NULL); #ifdef __STDC_LIB_EXT1__ errno_t result = - memset_s(ptr, sizeof(ptr), 0, count); /* Supported on C11 standard */ + memset_s(ptr, count, 0, count); /* Supported on C11 standard */ OSAL_MEM_ASSERT(result == 0); return ptr; #else diff --git a/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c b/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c deleted file mode 100644 index 953449d6..00000000 --- a/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c +++ /dev/null @@ -1,1280 +0,0 @@ -/** - * @file OsalUsrKrnProxy.c (linux user space) - * - * @brief Implementation for NUMA. - * - * - * @par - * SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2007-2026 Intel Corporation - * - * These contents may have been developed with support from one or more - * Intel-operated generative artificial intelligence solutions. - */ - -#include "Osal.h" -#include "OsalOsTypes.h" -#include "OsalDevDrv.h" -#include "OsalDevDrvCommon.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* The maximum number we allow to search for available size */ -#define MAX_LOOKUP_NUM 10 - -/* the maximum retry to wait for memcpy ready */ -#define MAX_MEMCPY_WAITNUM 100 - -#define BITMAP_LEN 8 -#define QWORD_WIDTH (8 * sizeof(UINT64)) -#define DWORD_WIDTH (8 * sizeof(UINT32)) -#define WORD_WIDTH (8 * sizeof(UINT16)) - -#define QWORD_ALL_ONE 0xFFFFFFFFFFFFFFFFULL -#define QWORD_MSB_SET 0x8000000000000000ULL -#define LOWER_WORD_ALL_ONE 0xFFFFUL - -#define MMAP_FLAGS MAP_PRIVATE - -#ifndef __off_t -typedef off_t __off_t; -#endif - -static int fd = -1; -static int fdp = -1; -static int strict_node = 1; - -#ifndef ICP_WITHOUT_THREAD -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t mutex_page = PTHREAD_MUTEX_INITIALIZER; -#endif -static dev_mem_info_t *pUserMemList = NULL; -static dev_mem_info_t *pUserMemListHead = NULL; - -static dev_mem_info_t *pUserLargeMemList = NULL; -static dev_mem_info_t *pUserLargeMemListHead = NULL; - -static dev_mem_info_t *pUserMemListPage = NULL; -static dev_mem_info_t *pUserMemListHeadPage = NULL; - -static INT32 ctzll(UINT64 bitmap_window) -{ - UINT64 mask = 1ULL; - UINT32 retval = 0; - while (!(mask & bitmap_window)) - { - ++retval; - mask <<= 1; - } - return retval; -} -/* - * reads a 64-bit window from a 8x64-bit bitmap - * starting from window_pos (0 - 510 ) - * map points to the 8x64 bit map area - * returns the 64-bit window from the 8x64 bitmap. - */ - -static UINT64 bitmap_read(UINT64 *map, size_t window_pos) -{ - UINT64 quad_word_window = 0ULL; - UINT64 next_quad_word = 0ULL; - size_t quad_word_pos = BITMAP_LEN - window_pos / QWORD_WIDTH - 1; - size_t bit_pos = window_pos % QWORD_WIDTH; - - quad_word_window = map[quad_word_pos]; - - if (0 == bit_pos) - { - return quad_word_window; - } - - if (0 == quad_word_pos) - { - next_quad_word = QWORD_ALL_ONE; - } - else - { - next_quad_word = map[quad_word_pos - 1]; - } - - quad_word_window >>= bit_pos; - next_quad_word &= ((1ULL << bit_pos) - 1); - next_quad_word <<= QWORD_WIDTH - bit_pos; - quad_word_window |= next_quad_word; - - return quad_word_window; -} -/* - * modify the 8x64-bit bitmap from pos - * for len length - * if set nonzero bits from pos for len length are set to 1 - * otherwise they are cleared to zero - */ -static void modify_bitmap(UINT64 *map, size_t pos, size_t len, UINT32 set) -{ - size_t window = 0; - size_t bitfield_pos = 0; - size_t bitfield_len = 0; - UINT64 mask = 0ULL; - while (len > 0) - { - window = BITMAP_LEN - pos / QWORD_WIDTH - 1; - bitfield_pos = pos % QWORD_WIDTH; - if (len + bitfield_pos >= QWORD_WIDTH) - { - bitfield_len = QWORD_WIDTH - bitfield_pos; - mask = ((1ULL << bitfield_pos) - 1); - } - else - { - bitfield_len = len; - mask = ((1ULL << bitfield_pos) - 1) | - ~((1ULL << (bitfield_pos + bitfield_len)) - 1); - } - if (set) - { - map[window] |= ~mask; - } - else - { - map[window] &= mask; - } - len -= bitfield_len; - pos += bitfield_len; - } -} -/* - * mem_alloc allocates memory with min. size = PAGE_SIZE - * map points to a dev_mem_info_t structure with virtual address - * size is the requested number of bytes - * minimum allocation size is PAGE_SIZE - * the first unsigned int of the allocated block has - * the starting block number in the upper - * and the size in PAGE_SIZE in the lower 16 bits. - * returns a pointer to the newly allocated block that - * points to the memory area after this unsigned integer - */ -static void *mem_alloc(void *map, size_t size) -{ - UINT64 *bitmap = NULL; - INT32 window_pos = 0; - UINT32 *retval = NULL; - INT32 blocks_found = 0; - UINT64 bitmap_window = 0ULL; - UINT32 blocks_required = 0ULL; - UINT32 first_block = 1; - - if (NULL == map || 0 == size) - { - return retval; - } - - bitmap = (UINT64 *)((UINT8 *)map + USER_MEM_128BYTE_OFFSET); - /* increase size to make room for an integer to hold first block/length - * info*/ - size += sizeof(UINT32); - - blocks_required = - size % PAGE_SIZE ? size / PAGE_SIZE + 1 : size / PAGE_SIZE; - do - { - INT32 width = 0; - - /* read 64-bit bitmap window from window_pos (0-510) */ - bitmap_window = bitmap_read(bitmap, window_pos); - - /* check if there is at least a 1 in bitmap window */ - if (bitmap_window) - { - /* find number of contiguous 0s from right */ - width = ctzll(bitmap_window); - } - else - { - /* bitmap window is 0 there are 64 contiguous 0s*/ - width = QWORD_WIDTH; - } - /* increment number of blocks found with number of contig. 0s in bitmap - * window */ - blocks_found += width; - /* check if a fit is found */ - if (blocks_found >= blocks_required) - { - /* calculate return address from virtual address and first block - * number */ - retval = (UINT32 *)(((dev_mem_info_t *)map)->virt_addr) + - (first_block)*PAGE_SIZE / sizeof(UINT32); - /* save first block number and length in the first integer of the - * block - * and increment pointer - */ - *retval++ = (first_block << WORD_WIDTH) | - (blocks_required & LOWER_WORD_ALL_ONE); - /* set bit maps from bit position (0-510) = first_block(1-511) - 1 - * with blocks_required length in bitmap - */ - modify_bitmap(bitmap, first_block - 1, blocks_required, 1); - break; - } - else - { - /* did not find fit check if bitmap_window has at least a 1*/ - if (bitmap_window) - { - /* bit field of 0s not contiguous, clear blocks_found adjust - * first_block - * and window_pos - */ - blocks_found = 0; - window_pos += width + 1; - first_block = window_pos + 1; - } - else - { - /* bit field of 0s is contiguous, but fit not found yet - * move window_pos an search more 0s */ - window_pos += width; - } - } - } while (window_pos < BITMAP_LEN * QWORD_WIDTH - 1); - - return retval; -} -/* - * deallocates previously allocated blocks - * map is a pointer to dev_mem_info_t structure - * block is returned by ia previous mem_alloc call - */ -static void mem_free(void *map, void *block) -{ - UINT32 first_block = 0; - UINT32 length = 0; - UINT32 *start_of_block = block; - UINT64 *bitmap = (UINT64 *)((UINT8 *)map + USER_MEM_128BYTE_OFFSET); - if (NULL == block) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Block address is zero \n"); - - return; - } - /* find start of block that is one integer back from user area */ - --start_of_block; - - /* retrieve first_block and length of block from integer at the start of - * block */ - first_block = *start_of_block >> WORD_WIDTH; - length = *start_of_block & LOWER_WORD_ALL_ONE; - - if (!first_block || first_block > BITMAP_LEN * QWORD_WIDTH - 1 || - length + first_block > BITMAP_LEN * QWORD_WIDTH) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Invalid block first block: %d length: %d\n", - first_block, - length); - - return; - } - /* clear bitmap from bitmap position (0-510) = first_block(1-511) - 1 for - * length */ - modify_bitmap(bitmap, first_block - 1, length, 0); -} - -OSAL_STATUS userMemListAdd(dev_mem_info_t *pMemInfo) -{ -#ifndef ICP_WITHOUT_THREAD - int ret = 0; - - ret = pthread_mutex_lock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - ADD_ELEMENT_TO_HEAD_OF_LIST(pMemInfo, pUserMemList, pUserMemListHead); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - return OSAL_SUCCESS; -} - -static OSAL_STATUS userLargeMemListAdd(dev_mem_info_t *pMemInfo) -{ -#ifndef ICP_WITHOUT_THREAD - int ret = 0; - - ret = pthread_mutex_lock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - ADD_ELEMENT_TO_HEAD_OF_LIST( - pMemInfo, pUserLargeMemList, pUserLargeMemListHead); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - return OSAL_SUCCESS; -} - -OSAL_STATUS userMemListAddPage(dev_mem_info_t *pMemInfo) -{ -#ifndef ICP_WITHOUT_THREAD - int ret = 0; - - ret = pthread_mutex_lock(&mutex_page); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - ADD_ELEMENT_TO_END_OF_LIST( - pMemInfo, pUserMemListPage, pUserMemListHeadPage); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex_page); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - - return OSAL_FAIL; - } -#endif - return OSAL_SUCCESS; -} - -void userMemListFree(dev_mem_info_t *pMemInfo) -{ - dev_mem_info_t *pCurr = NULL; - int done = 0; - - for (pCurr = pUserLargeMemListHead; pCurr != NULL; pCurr = pCurr->pNext) - { - if (pCurr == pMemInfo) - { - REMOVE_ELEMENT_FROM_LIST( - pCurr, pUserLargeMemList, pUserLargeMemListHead); - done = 1; - break; - } - } - - for (pCurr = pUserMemListHead; (pCurr != NULL) && (done == 0); - pCurr = pCurr->pNext) - { - if (pCurr == pMemInfo) - { - REMOVE_ELEMENT_FROM_LIST(pCurr, pUserMemList, pUserMemListHead); - break; - } - } -} - -void userMemListFreePage(dev_mem_info_t *pMemInfo) -{ - dev_mem_info_t *pCurr = NULL; - - for (pCurr = pUserMemListHeadPage; pCurr != NULL; pCurr = pCurr->pNext) - { - if (pCurr == pMemInfo) - { - REMOVE_ELEMENT_FROM_LIST( - pCurr, pUserMemListPage, pUserMemListHeadPage); - break; - } - } -} - -dev_mem_info_t *userMemLookupBySize(UINT32 size, UINT32 node, void **block) -{ - dev_mem_info_t *pCurr = NULL; - int link_num = 0; - /* Search from new to old */ - for (pCurr = pUserMemListHead; pCurr != NULL; pCurr = pCurr->pNext) - { - if (strict_node && (pCurr->nodeId != node)) - { - continue; - } - if (pCurr->available_size >= size + sizeof(UINT32)) - { - *block = mem_alloc(pCurr, size); - if (*block != NULL) - { - return pCurr; - } - } - /* Prevent from visiting whole chain, because after the first - * several node, the chance to get one is very small. - * Another consideration is to prevent new allocation from old - * link, so that the old link could be released - */ - link_num++; - if (link_num >= MAX_LOOKUP_NUM) - { - break; - } - } - return NULL; -} - -dev_mem_info_t *userMemLookupByVirtAddr(void *virt_addr) -{ - dev_mem_info_t *pCurr = NULL; - - for (pCurr = pUserMemListHead; pCurr != NULL; pCurr = pCurr->pNext) - { - if ((UARCH_INT)pCurr->virt_addr <= (UARCH_INT)virt_addr && - ((UARCH_INT)pCurr->virt_addr + pCurr->size) > (UARCH_INT)virt_addr) - { - return pCurr; - } - } - return NULL; -} - -static dev_mem_info_t *userLargeMemLookupByVirtAddr(void *virt_addr) -{ - dev_mem_info_t *pCurr = NULL; - - for (pCurr = pUserLargeMemListHead; pCurr != NULL; pCurr = pCurr->pNext) - { - if ((UARCH_INT)pCurr->virt_addr <= (UARCH_INT)virt_addr && - ((UARCH_INT)pCurr->virt_addr + pCurr->size) > (UARCH_INT)virt_addr) - { - return pCurr; - } - } - return NULL; -} - -dev_mem_info_t *userMemLookupByVirtAddrPage(void *virt_addr) -{ - dev_mem_info_t *pCurr = NULL; - - for (pCurr = pUserMemListHeadPage; pCurr != NULL; pCurr = pCurr->pNext) - { - if ((UARCH_INT)pCurr->virt_addr == (UARCH_INT)virt_addr) - { - return pCurr; - } - } - return NULL; -} - -OSAL_PUBLIC OSAL_STATUS osalMemInitialize(char *path) -{ - char mem_path[DEV_PATH_SIZE] = ""; - char mempage_path[DEV_PATH_SIZE] = ""; - - if (fd > 0 && fdp > 0) - { - return OSAL_SUCCESS; - } - - if (path != NULL) - { - size_t dev_mem_name_page_len = 0; - size_t offs = 0; - size_t os_dev_dir_len = 0; - size_t path_len = 0; - - // Look only at the first DEV_PATH_SIZE characters for a null byte. - path_len = OSAL_OS_GET_STRING_LENGTH(path, DEV_PATH_SIZE); - os_dev_dir_len = sizeof(OS_DEV_DIRECTORY) - 1; - dev_mem_name_page_len = sizeof(DEV_MEM_NAME_PAGE) - 1; - - if (path_len + os_dev_dir_len + dev_mem_name_page_len > DEV_PATH_SIZE) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "path to device is greater that max length %d\n", - fd); - - return OSAL_FAIL; - } - - offs = snprintf(mem_path, sizeof(mem_path), "%s", OS_DEV_DIRECTORY); - offs = MIN(offs, sizeof(mem_path)); - offs += snprintf(mem_path + offs, sizeof(mem_path) - offs, "%s", path); - offs = MIN(offs, sizeof(mem_path)); - snprintf(mem_path + offs, sizeof(mem_path) - offs, "%s", DEV_MEM_NAME); - - offs = snprintf( - mempage_path, sizeof(mempage_path), "%s", OS_DEV_DIRECTORY); - offs = MIN(offs, sizeof(mempage_path)); - offs += snprintf( - mempage_path + offs, sizeof(mempage_path) - offs, "%s", path); - offs = MIN(offs, sizeof(mempage_path)); - snprintf(mempage_path + offs, - sizeof(mempage_path) - offs, - "%s", - DEV_MEM_NAME_PAGE); - } - - fd = open((path) ? mem_path : DEV_MEM_PATH, O_RDWR); - if (fd < 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "unable to open %s %d\n", - (path) ? mem_path : DEV_MEM_PATH, - fd); - return OSAL_FAIL; - } - - fdp = open((path) ? mempage_path : DEV_MEM_PAGE_PATH, O_RDWR); - if (fdp < 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "unable to open %s %d\n", - (path) ? mempage_path : DEV_MEM_PAGE_PATH, - fdp); - close(fd); - fd = -1; - return OSAL_FAIL; - } - return OSAL_SUCCESS; -} - -OSAL_PUBLIC void osalMemDestroy() -{ - if (fd > 0) - { - close(fd); - fd = -1; - } - if (fdp > 0) - { - close(fdp); - fdp = -1; - } -} - -OSAL_PUBLIC void *osalMemAllocContiguousNUMA(UINT32 size, - UINT32 node, - UINT32 alignment) -{ - int ret = 0; - dev_mem_info_t *pMemInfo = NULL; - void *pVirtAddress = NULL; - void *pOriginalAddress = NULL; - UARCH_INT padding = 0; - UARCH_INT aligned_address = 0; - int requested_pages = 0; - int full_size = 0; - int allocate_pages = 0; - UARCH_INT offset = 0; - int mmap_size = 0; - int alloc_size = 0; - int large_memory = 0; - UINT8 *bitmask = NULL; - - if (size == 0 || alignment == 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Invalid size or alignment parameter \n"); - - return NULL; - } - if (fd < 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Memory file handle %d is not ready\n", - fd); - - return NULL; - } - - if (alignment == sizeof(UINT32) || alignment == sizeof(UINT16)) - { - alignment = 0; - } -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_lock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return NULL; - } -#endif - if ((pMemInfo = userMemLookupBySize( - size + alignment, node, &pOriginalAddress)) != NULL) - { - padding = alignment ? (UARCH_INT)pOriginalAddress % alignment : 0; - aligned_address = ((UARCH_INT)pOriginalAddress) + (alignment - padding); - pMemInfo->available_size -= - (*((UINT32 *)pOriginalAddress - 1) & LOWER_WORD_ALL_ONE) * - PAGE_SIZE; - pMemInfo->allocations += 1; -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalMemFreeNUMA(pMemInfo); - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = " - "%d \n", - ret); - - return NULL; - } -#endif - return (void *)aligned_address; - } -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - - return NULL; - } -#endif - /* full size means header size plus requested size */ - full_size = size + sizeof(UINT32) + alignment; - /* calculate pages needed */ - requested_pages = full_size % PAGE_SIZE ? ((full_size / PAGE_SIZE) + 1) - : (full_size) / PAGE_SIZE; - - if (requested_pages > NUM_PAGES_PER_ALLOC - 1) - { - large_memory = 1; - allocate_pages = - size % PAGE_SIZE ? size / PAGE_SIZE + 1 : size / PAGE_SIZE; - } - else - { - allocate_pages = NUM_PAGES_PER_ALLOC; - } - - /* calculate how many memory for allocation*/ - if (alloc_size == 0) - { - alloc_size = allocate_pages * PAGE_SIZE; - } - - /* Memory needed for pMemInfo: - * The first part is for the struct dev_mem_info_t. - * The second part is for the bitmap window which is located at an offset - * of USER_MEM_128BYTE_OFFSET. See mem_alloc() function for usage. - * Note sizeof(dev_mem_info_t) is less than USER_MEM_128BYTE_OFFSET - * The explicit calculation below is just to let static analysers know that - * the struct will fit in the resulting space. - */ - size_t pMemInfo_size = sizeof(dev_mem_info_t) > (USER_MEM_128BYTE_OFFSET) - ? sizeof(dev_mem_info_t) - : USER_MEM_128BYTE_OFFSET; - pMemInfo_size += ((BITMAP_LEN) * sizeof(UINT64)); - pMemInfo = calloc(1, pMemInfo_size); - if (NULL == pMemInfo) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "unable to allocate pMemInfo buffer\n"); - - return NULL; - } - - pMemInfo->allocations = 0; - pMemInfo->nodeId = node; - pMemInfo->size = alloc_size; - - /* Try to allocate memory as much as possible */ - ret = ioctl(fd, DEV_MEM_IOC_MEMALLOC, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl memory alloc failed, ret = %d\n", - ret); - - free(pMemInfo); - return NULL; - } - - if (node != pMemInfo->nodeId) - { - strict_node = 0; - } - - if (large_memory) - { - mmap_size = pMemInfo->size; - /* When uses really wants to mmap 0x2*NUM_PAGES_PER_ALLOC - * We have to do some fixup - */ - if ((mmap_size / PAGE_SIZE) == DOUBLE_NUM_PAGES_PER_ALLOC) - mmap_size = PAGE_SIZE * ICP_MMAP_DOUBLE_NUM_PAGES; - } - else - { - /* Use double size to call mmap, so that we can get aligned - * virtual address - */ - mmap_size = 0x2 * pMemInfo->size; - } - - pMemInfo->mmap_size = mmap_size; - pMemInfo->fvirt_addr = mmap((caddr_t)0, - mmap_size, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - (pMemInfo->id * getpagesize())); - - if (pMemInfo->fvirt_addr == (caddr_t)MAP_FAILED) - { - osalLog(OSAL_LOG_LVL_ERROR, OSAL_LOG_DEV_STDOUT, "mmap failed\n"); - - ret = ioctl(fd, DEV_MEM_IOC_MEMFREE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl DEV_MEM_IOC_MEMFREE call failed, ret = %d\n", - ret); - } - free(pMemInfo); - return NULL; - } - -/* available size needs to subtract current size and header */ -/* As DMA remapping may add extra page, so we need to use alloc_size - instead of the size in pMemInfo structure */ -#ifdef ICP_SRIOV - /* Save one page for IORemapping */ - alloc_size -= PAGE_SIZE; -#endif - pMemInfo->allocations = 1; - if (large_memory) - { - pMemInfo->available_size = alloc_size - size - USER_MEM_128BYTE_OFFSET; - pMemInfo->virt_addr = pMemInfo->fvirt_addr; - pMemInfo->fvirt_addr = 0; - if (userLargeMemListAdd(pMemInfo)) - { - ioctl(fd, DEV_MEM_IOC_MEMFREE, pMemInfo); - userMemListFree(pMemInfo); - free(pMemInfo); - return NULL; - } - pVirtAddress = - (void *)((UARCH_INT)pMemInfo->virt_addr + USER_MEM_128BYTE_OFFSET); - } - else - { - /* Save some space for memory info block*/ - offset = ((UARCH_INT)pMemInfo->fvirt_addr + pMemInfo->size) % - (pMemInfo->size); - pMemInfo->virt_addr = - (void *)((UARCH_INT)pMemInfo->fvirt_addr + pMemInfo->size - offset); - if ((UARCH_INT)pMemInfo->virt_addr % PAGE_SIZE) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Bad virtual address alignment %p %x %lu\n", - pMemInfo->virt_addr, - NUM_PAGES_PER_ALLOC, - PAGE_SIZE); - ioctl(fd, DEV_MEM_IOC_MEMFREE, pMemInfo); - free(pMemInfo); - return NULL; - } - - memcpy(pMemInfo->virt_addr, pMemInfo, sizeof(dev_mem_info_t)); - bitmask = (UINT8 *)pMemInfo; - *(UINT64 *)(bitmask + USER_MEM_128BYTE_OFFSET) = QWORD_MSB_SET; - pVirtAddress = mem_alloc(pMemInfo, size + alignment); - if (NULL == pVirtAddress) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Memory allocation failed Virtual address: %p Size: %x \n", - pMemInfo->virt_addr, - size + alignment); - ioctl(fd, DEV_MEM_IOC_MEMFREE, pMemInfo); - free(pMemInfo); - return NULL; - } - pMemInfo->available_size = - alloc_size - - ((*((UINT32 *)pVirtAddress - 1) & LOWER_WORD_ALL_ONE) + 1) * - PAGE_SIZE; - userMemListAdd(pMemInfo); - - padding = alignment ? (UARCH_INT)pVirtAddress % alignment : 0; - aligned_address = ((UARCH_INT)pVirtAddress) - padding + alignment; - pVirtAddress = (void *)aligned_address; - } - return pVirtAddress; -} - -OSAL_PUBLIC void *osalMemAllocPage(UINT32 node, UINT64 *physAddr) -{ - int ret = 0; - dev_mem_info_t *pMemInfo = NULL; - - if (fd < 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Memory file handle %d is not ready\n", - fd); - return NULL; - } - - pMemInfo = malloc(sizeof(dev_mem_info_t)); - if (NULL == pMemInfo) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "unable to allocate pMemInfo buffer\n"); - - return NULL; - } - - pMemInfo->nodeId = node; - pMemInfo->size = getpagesize(); - - ret = ioctl(fdp, DEV_MEM_IOC_MEMALLOCPAGE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl call failed, ret = %d\n", - ret); - - free(pMemInfo); - return NULL; - } - - pMemInfo->virt_addr = mmap(NULL, - pMemInfo->size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE, - fdp, - (__off_t)pMemInfo->id * getpagesize()); - if (pMemInfo->virt_addr == MAP_FAILED) - { - osalStdLog("Errno: %d\n", errno); - osalLog(OSAL_LOG_LVL_ERROR, OSAL_LOG_DEV_STDOUT, "mmap failed\n"); - - ret = ioctl(fd, DEV_MEM_IOC_MEMFREEPAGE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl call failed, ret = %d\n", - ret); - } - free(pMemInfo); - return NULL; - } - - if (userMemListAddPage(pMemInfo)) - { - ret = munmap(pMemInfo->virt_addr, getpagesize()); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "munmap failed, ret = %d\n", - ret); - } - - ret = ioctl(fdp, DEV_MEM_IOC_MEMFREEPAGE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl call failed, ret = %d\n", - ret); - } - userMemListFreePage(pMemInfo); - free(pMemInfo); - return NULL; - } - - *physAddr = pMemInfo->phy_addr; - return pMemInfo->virt_addr; -} - -OSAL_PUBLIC void osalMemFreeNUMA(void *pVirtAddress) -{ - int ret = 0; - dev_mem_info_t *pMemInfo = NULL; - - if (NULL == pVirtAddress) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Invalid virtual address\n"); - - return; - } -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_lock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return; - } -#endif - if ((pMemInfo = userMemLookupByVirtAddr(pVirtAddress)) != NULL) - { - pMemInfo->allocations -= 1; - if (pMemInfo->allocations != 0) - { - UINT32 *blockAddress = - (UINT32 *)((UARCH_INT)pVirtAddress & ~(PAGE_SIZE - 1)); - pMemInfo->available_size += - (*blockAddress & LOWER_WORD_ALL_ONE) * PAGE_SIZE; - mem_free(pMemInfo, ++blockAddress); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalMemFreeNUMA(pMemInfo); - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, " - "ret = %d \n", - ret); - } -#endif - return; - } - } - else - { - if ((pMemInfo = userLargeMemLookupByVirtAddr(pVirtAddress)) == NULL) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "userMemLookupByVirtAddr failed\n"); - -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, " - "ret = %d \n", - ret); - } -#endif - return; - } - } - - if (pMemInfo->fvirt_addr) - { - ret = munmap(pMemInfo->fvirt_addr, pMemInfo->mmap_size); - } - else - { - ret = munmap(pMemInfo->virt_addr, pMemInfo->mmap_size); - } - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "munmap failed, ret = %d\n", - ret); - } - - ret = ioctl(fd, DEV_MEM_IOC_MEMFREE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl call failed, ret = %d\n", - ret); - } - - userMemListFree(pMemInfo); - free(pMemInfo); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - } -#endif - return; -} - -OSAL_PUBLIC void osalMemFreePage(void *pVirtAddress) -{ - int ret = 0; - dev_mem_info_t *pMemInfo = NULL; - - if (NULL == pVirtAddress) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Invalid virtual address\n"); - - return; - } -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_lock(&mutex_page); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return; - } -#endif - pMemInfo = userMemLookupByVirtAddrPage(pVirtAddress); - - if (pMemInfo == NULL) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "userMemLookupByVirtAddrPage failed \n"); - -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex_page); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = " - "%d \n", - ret); - } -#endif - return; - } - - ret = munmap(pMemInfo->virt_addr, getpagesize()); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "munmap failed, ret = %d\n", - ret); - } - - ret = ioctl(fdp, DEV_MEM_IOC_MEMFREEPAGE, pMemInfo); - if (ret != 0) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "ioctl call failed, ret = %d\n", - ret); - } - userMemListFreePage(pMemInfo); - free(pMemInfo); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex_page); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - } -#endif - return; -} - -UINT64 -osalVirtToPhysNUMA(void *pVirtAddress) -{ - dev_mem_info_t *pMemInfo = NULL; - UARCH_INT offset = 0; - UINT64 phy_address = 0; -#ifndef ICP_WITHOUT_THREAD - int ret = 0; -#endif - - OSAL_LOCAL_ENSURE(pVirtAddress != NULL, - "osalVirtToPhysNUMA(): Null virtual address pointer", - 0); - -/* Firstly search the large memory tree */ -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_lock(&mutex); - if (ret) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_lock(): Failed to lock mutex, ret = %d \n", - ret); - - return (UINT64)0; - } -#endif - if ((pMemInfo = userLargeMemLookupByVirtAddr(pVirtAddress)) != NULL) - { -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - osalMemFreeNUMA(pMemInfo); - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = " - "%d \n", - ret); - - return (UINT64)0; - } -#endif - return (UINT64)(pMemInfo->phy_addr + (UARCH_INT)pVirtAddress - - (UARCH_INT)pMemInfo->virt_addr); - } - pMemInfo = userMemLookupByVirtAddr(pVirtAddress); -#ifndef ICP_WITHOUT_THREAD - ret = pthread_mutex_unlock(&mutex); - if (ret) - { - if (NULL != pMemInfo) - { - osalMemFreeNUMA(pMemInfo); - } - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "pthread_mutex_unlock(): Failed to unlock mutex, ret = %d \n", - ret); - - return (UINT64)0; - } -#endif - if (NULL == pMemInfo) - { - osalLog(OSAL_LOG_LVL_ERROR, - OSAL_LOG_DEV_STDOUT, - "Invalid block address %p !\n", - pVirtAddress); - - return (UINT64)0; - } - - offset = (UARCH_INT)pVirtAddress - (UARCH_INT)(pMemInfo->virt_addr); - phy_address = pMemInfo->phy_addr; - - return (UINT64)(phy_address + offset); -} - -#ifndef ICP_WITHOUT_IOMMU -int osalIOMMUMap(UINT64 phaddr, UINT64 iova, size_t size) -{ - dev_iommu_info_t info = {phaddr, iova, size}; - return ioctl(fd, DEV_MEM_IOC_IOMMUMAP, &info); -} - -int osalIOMMUUnmap(UINT64 iova, size_t size) -{ - dev_iommu_info_t info = {0, iova, size}; - return ioctl(fd, DEV_MEM_IOC_IOMMUUNMAP, &info); -} - -UINT64 osalIOMMUVirtToPhys(UINT64 iova) -{ - dev_iommu_info_t info = {0, iova, 0}; - return (ioctl(fd, DEV_MEM_IOC_IOMMUVTOP, &info) == 0) ? info.phaddr : 0; -} - -size_t osalIOMMUgetRemappingSize(size_t size) -{ - int pages = (size >> PAGE_SHIFT) + 1; - size_t new_size = (pages * PAGE_SIZE); - return new_size; -} -#else -int osalIOMMUMap(UINT64 phaddr, UINT64 iova, size_t size) -{ - return 0; -} - -int osalIOMMUUnmap(UINT64 iova, size_t size) -{ - return 0; -} - -UINT64 osalIOMMUVirtToPhys(UINT64 iova) -{ - return iova; -} - -size_t osalIOMMUgetRemappingSize(size_t size) -{ - return size; -} -#endif diff --git a/quickassist/utilities/qat_mgr/qat_mgr.c b/quickassist/utilities/qat_mgr/qat_mgr.c index 7f3682de..89bd7912 100644 --- a/quickassist/utilities/qat_mgr/qat_mgr.c +++ b/quickassist/utilities/qat_mgr/qat_mgr.c @@ -468,7 +468,7 @@ int main(int argc, char **argv) signal(SIGPIPE, signal_handler); - if (qat_mgr_get_vfio_dev_list(&num_devices, dev_list, list_size, 0)) + if (qat_mgr_get_vfio_dev_list(&num_devices, dev_list, list_size)) { printf("get_dev_list failed\n"); } diff --git a/quickassist/utilities/service/qat_init.sh.in b/quickassist/utilities/service/qat_init.sh.in index a569ee82..9c21df3e 100644 --- a/quickassist/utilities/service/qat_init.sh.in +++ b/quickassist/utilities/service/qat_init.sh.in @@ -49,7 +49,13 @@ QAT_420XX_DEVICE_NAME="420xx" QAT_420XX_DRIVER_NAME="qat_420xx" PF_NAMES="$PF_NAMES $QAT_420XX_DEVICE_NAME" VF_DEVICE_IDS="$VF_DEVICE_IDS $QAT_420XX_DEVICE_PCI_ID_VM" -SERVICES_LIST="sym asym sym;asym dc sym;dc asym;dc dcc" +QAT_6XXX_DEVICE_PCI_ID="0x4948" +QAT_6XXX_DEVICE_PCI_ID_VM="0x4949" +QAT_6XXX_DEVICE_NAME="6xxx" +QAT_6XXX_DRIVER_NAME="qat_6xxx" +PF_NAMES="$PF_NAMES $QAT_6XXX_DEVICE_NAME" +VF_DEVICE_IDS="$VF_DEVICE_IDS $QAT_6XXX_DEVICE_PCI_ID_VM" +SERVICES_LIST="sym asym dc decomp dcc sym;asym sym;dc sym;decomp asym;dc asym;decomp dc;decomp sym;asym;dc sym;asym;decomp sym;dc;decomp asym;dc;decomp" SERVICES_ENABLED="NONE" SERVICES_ENABLED_FOUND="FALSE" SYSTEMD_FILE="@systemdsystemunitdir@/qat.service" @@ -60,10 +66,12 @@ SUPPORTED_DEVICE_PCI_IDS="$QAT_4XXX_DEVICE_PCI_ID" SUPPORTED_DEVICE_PCI_IDS="$SUPPORTED_DEVICE_PCI_IDS $QAT_401XX_DEVICE_PCI_ID" SUPPORTED_DEVICE_PCI_IDS="$SUPPORTED_DEVICE_PCI_IDS $QAT_402XX_DEVICE_PCI_ID" SUPPORTED_DEVICE_PCI_IDS="$SUPPORTED_DEVICE_PCI_IDS $QAT_420XX_DEVICE_PCI_ID" +SUPPORTED_DEVICE_PCI_IDS="$SUPPORTED_DEVICE_PCI_IDS $QAT_6XXX_DEVICE_PCI_ID" # space separated array for supporting new devices pci names SUPPORTED_DRIVER_NAMES="$QAT_4XXX_DRIVER_NAME" SUPPORTED_DRIVER_NAMES="$SUPPORTED_DRIVER_NAMES $QAT_420XX_DRIVER_NAME" +SUPPORTED_DRIVER_NAMES="$SUPPORTED_DRIVER_NAMES $QAT_6XXX_DRIVER_NAME" check_config() { CONFIG_FILE=$(awk -F'EnvironmentFile=-' '{print $2}' $SYSTEMD_FILE | grep '\S') diff --git a/versionfile b/versionfile index b939a421..945dd055 100644 --- a/versionfile +++ b/versionfile @@ -4,8 +4,8 @@ PACKAGE_OS=L PACKAGE_VERSION_MAJOR_NUMBER=26 -PACKAGE_VERSION_MINOR_NUMBER=02 +PACKAGE_VERSION_MINOR_NUMBER=08 PACKAGE_VERSION_PATCH_NUMBER=0 -PACKAGE_VERSION_BUILD_NUMBER=00024 +PACKAGE_VERSION_BUILD_NUMBER=00017