From a9e5fcf212fcb9241b38a3a105c95b1f5b3593db Mon Sep 17 00:00:00 2001 From: Fiona Trahe Date: Mon, 9 Sep 2024 18:27:08 +0530 Subject: [PATCH] QATlib: 24.09.0 release Changes from 24.02.0 to 24.09.0: * Improved performance scaling in multi-thread applications (--enable-icp-thread-specific-usdm) * Set core affinity mapping based on NUMA node to improve performance (near-linear scaling) on multi-socket platforms * Bug fixes (See Resolved section in README.md) Signed-off-by: Fiona Trahe Signed-off-by: Firos Sadarul --- INSTALL | 55 +- Makefile.am | 23 +- README.md | 109 +- configure.ac | 21 +- filelist | 6 +- qatlib.spec.in | 6 +- .../access_layer/include/icp_accel_devices.h | 4 +- .../access_layer/include/icp_adf_cfg.h | 2 - .../access_layer/include/icp_adf_transport.h | 45 - .../access_layer/include/icp_sal_user.h | 26 +- .../access_layer/include/icp_sal_versions.h | 2 +- .../src/common/compression/dc_chain.c | 4 +- .../src/common/compression/dc_datapath.c | 2 +- .../src/common/compression/dc_dp.c | 11 +- .../src/common/compression/dc_ns_datapath.c | 12 + .../src/common/compression/dc_session.c | 12 + .../common/compression/include/dc_datapath.h | 1 - .../src/common/compression/reg_sizes.asm | 12 +- .../crypto/kpt/provision/lac_kpt_provision.c | 2 +- .../common/crypto/sym/include/lac_session.h | 4 +- .../src/common/crypto/sym/lac_sym_alg_chain.c | 136 ++- .../src/common/crypto/sym/lac_sym_api.c | 2 +- .../src/common/crypto/sym/lac_sym_dp.c | 37 + .../crypto/sym/qat/lac_sym_qat_cipher.c | 17 +- .../src/common/ctrl/sal_compression.c | 46 +- .../access_layer/src/common/ctrl/sal_crypto.c | 87 +- .../src/common/ctrl/sal_ctrl_services.c | 12 - .../src/common/ctrl/sal_instances.c | 20 + .../src/common/device/sal_dev_info.c | 2 +- .../src/common/include/lac_common.h | 10 +- .../src/common/include/lac_mem_pools.h | 19 - .../src/common/include/lac_sal_types.h | 2 - .../src/common/utils/lac_mem_pools.c | 42 - .../src/qat_direct/common/adf_process_proxy.c | 9 +- .../common/adf_user_ETring_mgr_dp.c | 5 +- .../src/qat_direct/common/adf_user_cfg.c | 9 + .../src/qat_direct/common/adf_user_device.c | 52 +- .../src/qat_direct/common/adf_user_dyn.c | 59 -- .../src/qat_direct/common/adf_user_init.c | 8 +- .../src/qat_direct/common/adf_user_ring.c | 67 +- .../common/adf_user_transport_ctrl.c | 24 +- .../common/include/adf_dev_ring_ctl.h | 1 - .../common/include/adf_transport_ctrl.h | 215 ---- .../src/qat_direct/common/include/adf_user.h | 6 +- .../common/include/adf_user_arbiter.h | 6 +- .../qat_direct/common/include/adf_user_cfg.h | 8 +- .../qat_direct/common/include/adf_user_ring.h | 32 +- .../common/include/adf_user_transport.h | 39 - .../qat_direct/common/include/icp_platform.h | 20 +- .../common/include/icp_platform_user.h | 4 + .../src/qat_direct/include/adf_io_bundles.h | 22 + .../src/qat_direct/include/adf_io_cfg.h | 15 + .../qat_direct/include/adf_io_user_proxy.h | 3 +- .../src/qat_direct/vfio/adf_pfvf_proto.c | 11 +- .../src/qat_direct/vfio/adf_pfvf_vf_msg.c | 23 +- .../src/qat_direct/vfio/adf_vfio_cfg.c | 27 +- .../src/qat_direct/vfio/adf_vfio_pf.c | 128 ++- .../qat_direct/vfio/adf_vfio_user_bundles.c | 15 +- .../src/qat_direct/vfio/adf_vfio_user_proxy.c | 10 +- .../src/qat_direct/vfio/qat_mgr.h | 41 +- .../src/qat_direct/vfio/qat_mgr_client.c | 2 +- .../src/qat_direct/vfio/qat_mgr_lib.c | 577 +++++++--- .../src/qat_direct/vfio/vfio_lib.c | 25 +- .../src/sample_code/busy_loop/busy_loop.c | 5 + .../diffie_hellman_sample/cpa_dh_sample.c | 4 +- .../cpa_ec_montedwds_sample.c | 14 +- .../asym/eddsa_sample/cpa_eddsa_sample.c | 42 +- .../asym/prime_sample/cpa_prime_sample.c | 2 +- .../functional/common/cpa_sample_utils.c | 73 +- .../dc/chaining_sample/cpa_chaining_sample.c | 8 +- .../dc/dc_dp_sample/cpa_dc_dp_sample.c | 19 +- ...pa_dc_stateless_multi_op_checksum_sample.c | 36 +- .../cpa_dc_stateless_sample.c | 6 +- .../functional/include/cpa_sample_utils.h | 23 +- .../cpa_algchaining_sample.c | 4 +- .../sym/ccm_sample/cpa_ccm_sample.c | 4 +- .../sym/cipher_sample/cpa_cipher_sample.c | 4 +- .../sym/gcm_sample/cpa_gcm_sample.c | 4 +- .../hash_file_sample/cpa_hash_file_sample.c | 4 +- .../sym/hash_sample/cpa_hash_sample.c | 4 +- .../sym/hkdf_sample/cpa_hkdf_sample.c | 9 +- .../sym/ipsec_sample/cpa_ipsec_sample.c | 4 +- .../sym/ssl_sample/cpa_ssl_sample.c | 4 +- .../sym/symdp_sample/cpa_sym_dp_sample.c | 2 +- .../sym/zuc_sample/cpa_zuc_sample.c | 4 +- .../performance/common/qat_perf_utils.c | 6 +- .../compression/cpa_sample_code_dc_dp.c | 11 +- .../compression/cpa_sample_code_dc_perf.h | 1 + .../compression/cpa_sample_code_dc_utils.c | 62 +- .../compression/cpa_sample_code_dc_utils.h | 6 + .../compression/qat_chaining_main.c | 58 +- .../compression/qat_compression_e2e.c | 1 + .../compression/qat_compression_main.c | 31 +- .../compression/qat_compression_main.h | 5 + .../compression/qat_compression_utils.c | 163 +-- .../performance/cpa_sample_code_main.c | 220 +++- .../crypto/cpa_sample_code_cipher_perf2.c | 36 +- .../crypto/cpa_sample_code_crypto_utils.c | 139 ++- .../crypto/cpa_sample_code_crypto_utils.h | 8 + .../crypto/cpa_sample_code_dh_perf.c | 11 +- .../crypto/cpa_sample_code_drbg_perf.c | 15 +- .../crypto/cpa_sample_code_dsa_perf.c | 74 +- .../cpa_sample_code_ec_montedwds_perf.c | 2 + .../crypto/cpa_sample_code_ecdsa_perf.c | 84 +- .../crypto/cpa_sample_code_ike_dsa_perf.c | 79 +- .../crypto/cpa_sample_code_ike_rsa_perf.c | 12 +- .../crypto/cpa_sample_code_nrbg_perf.c | 20 +- .../crypto/cpa_sample_code_rsa_perf.c | 41 +- .../crypto/cpa_sample_code_sm2_perf.c | 18 +- .../crypto/cpa_sample_code_sym_perf.c | 37 +- .../crypto/cpa_sample_code_sym_perf_dp.c | 87 +- .../crypto/cpa_sample_code_sym_update.c | 3 +- .../cpa_sample_code_sym_update_common.c | 137 +-- .../cpa_sample_code_sym_update_common.h | 3 + .../crypto/cpa_sample_code_sym_update_dp.c | 9 +- .../performance/crypto/qat_sym_main.c | 10 +- .../performance/crypto/qat_sym_utils.c | 3 +- .../framework/cpa_sample_code_framework.c | 13 +- .../framework/cpa_sample_code_framework.h | 2 + .../linux/user_space/cpa_sample_code_utils.c | 31 +- .../src/sample_code/performance/qae/qae_mem.h | 4 + .../access_layer/src/user/sal_user.c | 5 +- .../src/user/sal_user_congestion_mgmt.c | 36 + .../src/user/sal_user_dyn_instance.c | 991 +----------------- .../libusdm_drv/include/qae_mem_utils.h | 19 + .../libusdm_drv/user_space/qae_mem_common.c | 677 ++++++++++++ .../user_space/qae_mem_lib_utils.h | 240 +++++ .../user_space/qae_mem_multi_thread.h | 272 +++++ .../user_space/qae_mem_multi_thread_utils.c | 610 +++++++++++ .../user_space/qae_mem_utils_common.c | 603 ----------- .../user_space/qae_mem_utils_common.h | 357 ++----- .../user_space/vfio/qae_mem_utils_vfio.c | 350 ++++++- .../src/linux/user_space/OsalUsrKrnProxy.c | 48 +- quickassist/utilities/qat_mgr/qat_mgr.c | 24 +- versionfile | 6 +- 135 files changed, 4703 insertions(+), 3510 deletions(-) delete mode 100644 quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c delete mode 100644 quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_transport_ctrl.h create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h create mode 100644 quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c diff --git a/INSTALL b/INSTALL index 912f459a..bb6140a8 100644 --- a/INSTALL +++ b/INSTALL @@ -54,9 +54,14 @@ Web-based documentation for QATlib and related components is available at: Using the QATlib package ======================== - Note: Instructions assume running on Fedora and as non-root user who can - get root access using sudo, i.e. user is in sudoers group. Command-lines - may be different in other Linux distributions. + Note: The build instructions provided are for RPM-based Linux distributions + such as Fedora, Red Hat Enterprise Linux (RHEL), CentOS, and Rocky Linux. + For Debian-based distributions like Debian and Ubuntu, refer to the + installation guide at: + https://intel.github.io/quickassist/qatlib/install.html#installing-from-sources + These instructions assume operation as a non-root user with sudo + privileges. Users on other distributions may need to adapt the command-lines + accordingly. Check System Prerequisites @@ -128,12 +133,25 @@ Check System Prerequisites -> Platform Configuration -> Miscellaneous Configuration -> SR-IOV Support - * Grub settings - set intel_iommu on in grub file, e.g. in Fedora: - * sudo vi /etc/default/grub - * to GRUB_CMDLINE_LINUX add "intel_iommu=on" - * sudo grub2-mkconfig -o /etc/grub2-efi.cfg - * sudo shutdown -r now + * GRUB Configuration Updates + - Step 1: Edit the GRUB configuration file. + * Open the file with a text editor, for example, `sudo vi /etc/default/grub`. + + - Step 2: Add the necessary parameters to the `GRUB_CMDLINE_LINUX` entry. + * Enable Intel IOMMU by adding "intel_iommu=on". The line should look like: + `GRUB_CMDLINE_LINUX="... intel_iommu=on"`. + * Add VFIO-PCI device IDs. For a device with the ID 8086:4941, add + "vfio-pci.ids=8086:4941". The line should look like: + `GRUB_CMDLINE_LINUX="... vfio-pci.ids=8086:4941"`. + * Refer to the list of supported devices at + https://intel.github.io/quickassist/qatlib/requirements.html#supported-devices + for other device IDs. + + - Step 3: Update the GRUB configuration and reboot the system. + * Generate a new GRUB configuration file: + `sudo grub2-mkconfig -o /etc/grub2-efi.cfg`. + * Reboot the system to apply the changes: + `sudo shutdown -r now`. =============================================================================== @@ -182,7 +200,7 @@ Compilation and installation - quickstart instructions # Install dependencies sudo dnf install -y gcc systemd-devel automake autoconf libtool - sudo dnf install -y pkg-config openssl-devel zlib-devel nasm + sudo dnf install -y pkg-config openssl-devel zlib-devel nasm numactl-devel # Clone QATlib into ~/qatlib, i.e. in your home dir cd ~ @@ -249,6 +267,7 @@ Compilation and installation - detailed instructions libraries: openssl-devel zlib-devel + numactl-devel ---------------------------------------------------------------------------- @@ -699,6 +718,19 @@ Full list of Configuration options Enable deprecated legacy crypto algorithms. See the README.md for the list of algorithms which are deprecated by default. + --enable-icp-thread-specific-usdm + USDM allocates and handles memory specific to threads. + (For multi-thread apps, allocated memory information will be + maintained separately for each thread; employs thread local storage + feature i.e. TLS. It avoids locking that was needed when a global + data structure being used in non thread-specific implementation). + NOTE: Any memory allocated by a thread must be freed by the same + thread. If it passes the memory to other threads for use, it's + responsible for any synchronisation between those threads. + The thread which did the allocation must live until after all + threads using the memory are finished with it, as any thread + memory not yet freed may be cleaned up on termination of the thread. + MAX_MR Number of Miller Rabin rounds for prime operations. Setting this to a smaller value reduces the memory usage required by the @@ -714,6 +746,9 @@ Full list of Configuration options Common issues ============= + Additional details are available at: + https://intel.github.io/quickassist/qatlib/index.html + Issue: errors like these are seen in system logs: * 4xxx 0000:6b:00.0: IOMMU should be enabled for SR-IOV to work * vfio-pci: probe of 0000:6b:00.1 failed with error -22 diff --git a/Makefile.am b/Makefile.am index 7ccae536..ec27ed4f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,7 +57,6 @@ libadf_la_SOURCES = \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c \ - quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c \ quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c \ @@ -107,13 +106,20 @@ qatmgr_CFLAGS = -I$(srcdir)/quickassist/lookaside/access_layer/src/qat_direct/vf -D USER_SPACE \ $(COMMON_FLAGS) -qatmgr_LDADD = -lpthread +qatmgr_LDADD = -lpthread -lnuma 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/vfio/qae_mem_hugepage_utils_vfio.c +if ICP_THREAD_SPECIFIC_USDM_AC +lib@LIBUSDMNAME@_la_SOURCES += \ + quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c +else +lib@LIBUSDMNAME@_la_SOURCES += \ + quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c +endif lib@LIBUSDMNAME@_la_CFLAGS = -I$(srcdir)/quickassist/utilities/libusdm_drv \ -I$(srcdir)/quickassist/utilities/libusdm_drv/include \ -I$(srcdir)/quickassist/utilities/libusdm_drv/user_space \ @@ -221,6 +227,7 @@ lib@LIBQATNAME@_la_SOURCES = \ quickassist/lookaside/access_layer/src/common/utils/sal_versions.c \ quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c \ quickassist/lookaside/access_layer/src/user/sal_user.c \ + quickassist/lookaside/access_layer/src/user/sal_user_congestion_mgmt.c \ quickassist/lookaside/access_layer/src/user/sal_user_dyn_instance.c if USE_CCODE_CRC lib@LIBQATNAME@_la_SOURCES += \ @@ -245,7 +252,7 @@ lib@LIBQATNAME@_la_CFLAGS = -I$(srcdir)/quickassist/utilities/libusdm_drv \ -D USER_SPACE \ -D LAC_BYTE_ORDER=__LITTLE_ENDIAN \ $(COMMON_FLAGS) -lib@LIBQATNAME@_la_LIBADD = libosal.la libadf.la lib@LIBUSDMNAME@.la -lcrypto +lib@LIBQATNAME@_la_LIBADD = libosal.la libadf.la lib@LIBUSDMNAME@.la -lcrypto -lnuma if !USE_CCODE_CRC lib@LIBQATNAME@_la_LIBADD += crc32_gzip_refl_by8.lo crc64_ecma_norm_by8.lo endif @@ -317,7 +324,9 @@ endif dist_man_MANS = qat_init.sh.8 qatmgr.8 -EXTRA_DIST = LICENSE \ +EXTRA_DIST = INSTALL README.md SECURITY.md LICENSE \ + filelist \ + versionfile \ autogen.sh \ quickassist/lookaside/firmware/include \ quickassist/include \ @@ -327,6 +336,7 @@ EXTRA_DIST = LICENSE \ quickassist/utilities/osal \ quickassist/utilities/libusdm_drv/include \ quickassist/utilities/libusdm_drv/user_space \ + quickassist/utilities/service/qat \ quickassist/lookaside/access_layer/src/sample_code DISTCHECK_CONFIGURE_FLAGS = \ @@ -401,6 +411,11 @@ else QAT_LEGACY_ALGORITHMS = n endif +if ICP_THREAD_SPECIFIC_USDM_AC +ICP_THREAD_SPECIFIC_USDM = 1 +COMMON_FLAGS += -DICP_THREAD_SPECIFIC_USDM +endif + include Samples.am ######################## diff --git a/README.md b/README.md index ab1fc88f..9d6cedba 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ | Date | Doc Revision | Version | Details | |----------|:-------------:|------:|:------| +| 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). | @@ -128,13 +129,11 @@ Please refer to [INSTALL](INSTALL) for details on installing the library. * 4xxx, 401xx and 402xx (QAT GEN 4 devices) * 420xx (QAT GEN 5 devices) -Earlier generations of QAT devices (e.g. c62x, dh895xxcc, etc.) are not +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 on supported devices. ## Limitations -* If an error occurs on the host driver (Heartbeat, Uncorrectable error) it - will not be communicated to the library. * For simplicity, only one configuration file is used by qatlib. For guidance on how to use this to allocate resources for processes, please refer to Configuration and Tuning section in [QATlib User’s Guide](https://intel.github.io/quickassist/qatlib/index.html). @@ -190,11 +189,20 @@ where: \ is one of the following: | Issue ID | Description | |-------------|------------| +| 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-41707 | [CY - Incorrect digest returned when performing a plain hash operation on input data of size 4GB or larger.](#qate-41707) | | QATE-76073 | [GEN - If PF device configuration is modified without restarting qatmgr, undefined behavior may occur.](#qate-76073) | -| QATE-76698 | [GEN - Multi-process applications running in guest will fail when running with default Policy settings.](#qate-76698) | -| QATE-98551 | [GEN - On a multi-socket platform, there can be a performance degradation on the remote sockets.](#qate-98551) | + +## QATE-102390 +| Title | GEN – [error] validateConcurrRequest() - : Invalid numConcurrRequests | +|---------------|:-------------------------------------------------------------------| +| Reference # | QATE-102390 | +| Description | An error occurs in a virtualized environment after VF resources are detached from a running VM (guest) and then re-attached. Following this, the qat service is restarted on the guest to ensure the correct VF resources are used. In rare instances, this leads to a failure in process initialisation with the error: "[error] validateConcurrRequest() - : Invalid numConcurrRequests". | +| Implication | Processes within the guest fail to start. | +| Resolution | To resolve the issue, restart the qatmgr on the guest using "sudo systemctl restart qat". If in standalone mode, restart the process manually. | +| Affected OS | Linux | +| Driver/Module | CPM-IA – Only on the 420xx QAT GEN 5 device. | + ## QATE-3241 | Title | CY - cpaCySymPerformOp when used with parameter checking may reveal the amount of padding. | @@ -206,17 +214,6 @@ where: \ is one of the following: | Affected OS | Linux | | Driver/Module | CPM-IA - Crypto | -## QATE-41707 - -| Title | CY - Incorrect digest returned when performing a plain hash operation on input data of size 4GB or larger. | -|----------|:------------- -| Reference # | QATE-41707 | -| Description | When performing a plain hash operation on input data size of 4GB or larger, incorrect digest is returned. | -| Implication | Incorrect digest is returned from a plane hash operation. | -| Resolution | There is no fix available. | -| Affected OS | Linux | -| Driver/Module | CPM-IA - Crypto | - ## QATE-76073 | Title | GEN - If PF device configuration is modified without restarting qatmgr, undefined behavior may occur. | |----------|:------------- @@ -227,42 +224,80 @@ where: \ is one of the following: | Affected OS | Linux | | Driver/Module | CPM-IA - General | +## Resolved Issues +Resolved issues relating to the Intel® QAT software are described +in this section. + +| Issue ID | Description | +|-------------|------------| +| QATE-76698 | [GEN - Multi-process applications running in guest will fail when running with default Policy settings.](#qate-76698) | +| QATE-99637 | [GEN - QAT instances on PCI domains other than 0000 are inaccessible.](#qate-99637) | +| QATE-99638 | [GEN - Incompatible service to ring configuration with non in-tree QAT kernel modules.](#qate-99638) | +| QATE-98551 | [GEN - On a multi-socket platform, there can be a performance degradation on the remote sockets.](#qate-98551) | +| QATE-41707 | [CY - Incorrect digest returned when performing a plain hash operation on input data of size 4GB or larger.](#qate-41707) | +| QATE-97977 | [DC - 'Unable to get the physical address of Data Integrity buffer' error may be observed when using user-provided address translation functions.](#qate-97977) | +| QATE-94369 | [GEN - SELinux Preventing QAT Service Startup.](#qate-94369) | +| QATE-94286 | [GEN - Compression services not detected when crypto-capable VFs are added to VM.](#qate-94286) | +| QATE-95905 | [GEN - Fix build when building outside of main directory, issue #56](#qate-95905) | +| QATE-93844 | [DC - cpaDcLZ4SCompressBound is not returning correct value, which could lead to a buffer overflow.](#qate-93844) | +| QATE-93278 | [GEN - sample_code potential seg-fault, issue #46](#qate-93278) | +| QATE-90845 | [GEN - QAT service fails to start, issue #38](#qate-90845) | +| QATE-78459 | [DC - cpaDcDeflateCompressBound API returns incorrect output buffer size when input size exceeds 477218588 bytes.](#qate-78459) | +| 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) | + ## QATE-76698 | Title | GEN - Multi-process applications running in guest will fail when running with default Policy settings. | |----------|:------------- | Reference # | QATE-76698 | -| Description | The default Policy setting results in process receiving all available VFs allocated to guest operating system.  In the case of a multi-process application, failures will be observed as all available QAT resources are consumed by the first process. | -| Implication | Multi-process applications running in guest OS will fail with default Policy settings. | -| Resolution | If more than 1 process is needed in a guest OS, set POLICY=n (where n>0) in /etc/sysconfig/qat and restart qatmgr. The process will then receive n VFs. See RUNNING IN A VIRTUAL MACHINE / GUEST section of INSTALL for details. | +| Description | The default Policy setting results in the first process receiving all available VFs allocated to a guest operating system if the BDFs on the guest do not facilitate qatlib recognising which VFs are from the same PF. In the case of a multi-process application, failures will be observed if all available QAT resources are consumed by the first process. | +| Implication | Multi-process applications running in guest OS may fail with default Policy settings. | +| Resolution | Follow the guidance for specifying guest BDFs [here](https://intel.github.io/quickassist/qatlib/running_in_vm.html#qat-virtual-function).| +| Affected OS | Linux | +| Driver/Module | CPM-IA - General | + + +## QATE-99637 +| Title | 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. | +| Resolution | Fixed in 24.09 | | Affected OS | Linux | | Driver/Module | CPM-IA - General | + +## QATE-99638 +| Title | Incompatible service to ring configuration with non in-tree QAT kernel modules. | +|----------|:------------- +| Reference # | QATE-99638 | +| Description | QATlib assumes a ring layout corresponding to ring configuration defaults used by the in-tree QAT kernel driver. This assumption is invalid if qatlib is running on a guest and the host has some other QAT kernel driver, e.g. an out-of-tree driver or ESXi driver, which may use different ring configurations. This affects configurations such as ASYM;DC and SYM;DC. All kernel drivers provide ring2service information via pfvfcomms, qatlib should query this rather than rely on an assumed ring layout. | +| Implication | Crypto or compression operations will fail if sent to a ring which doesn’t handle that service. | +| Resolution | Fixed in 24.09 | +| Affected OS | Linux OOT, ESXi, Windows Server | +| Driver/Module | CPM-IA - General | + ## QATE-98551 | Title | GEN - On a multi-socket platform, there can be a performance degradation on the remote sockets. | |----------|:------------- | Reference # | QATE-98551 | | Description | On a multi-socket platform, there can be a performance degradation on remote sockets. This can arise when either the threads are not affinitised to the core on the socket the device is on and/or the memory is not allocated on the appropriate NUMA node. | | Implication | Performance on socket 0 is as expected, but does not scale proportionally on remote sockets. | -| Resolution | This will be fixed in a future release. In the meantime, applications on a multi-socket platform should configure threads using a QAT VF device on a remote socket to be affinitised to the core on that remote socket. Then the memory allocations are more likely to be done on the remote socket, with minimal performance impact. | +| Resolution | Fixed in 24.09 | | Affected OS | Linux | | Driver/Module | CPM-IA - General | -## Resolved Issues -Resolved issues relating to the Intel® QAT software are described -in this section. +## QATE-41707 -| Issue ID | Description | -|-------------|------------| -| QATE-97977 | [DC - 'Unable to get the physical address of Data Integrity buffer' error may be observed when using user-provided address translation functions.](#qate-97977) | -| QATE-94369 | [GEN - SELinux Preventing QAT Service Startup.](#qate-94369) | -| QATE-94286 | [GEN - Compression services not detected when crypto-capable VFs are added to VM.](#qate-94286) | -| QATE-95905 | [GEN - Fix build when building outside of main directory, issue #56](#qate-95905) | -| QATE-93844 | [DC - cpaDcLZ4SCompressBound is not returning correct value, which could lead to a buffer overflow.](#qate-93844) -| QATE-93278 | [GEN - sample_code potential seg-fault, issue #46](#qate-93278) | -| QATE-90845 | [GEN - QAT service fails to start, issue #38](#qate-90845) | -| QATE-78459 | [DC - cpaDcDeflateCompressBound API returns incorrect output buffer size when input size exceeds 477218588 bytes.](#qate-78459) | -| 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) | +| Title | CY - Incorrect digest returned when performing a plain hash operation on input data of size 4GB or larger. | +|----------|:------------- +| Reference # | QATE-41707 | +| Description | When performing a plain hash operation on input data size of 4GB or larger, incorrect digest is returned. | +| Implication | Incorrect digest is returned from a plain hash operation. | +| Resolution | Fixed in 24.09 | +| Affected OS | Linux | +| Driver/Module | CPM-IA - Crypto | ## QATE-97977 | Title | DC - 'Unable to get the physical address of Data Integrity buffer' error may be observed when using user-provided address translation functions. | @@ -292,7 +327,7 @@ in this section. | Reference # | QATE-94286 | | Description | When configuring a system with different services on different QAT end-points, e.g. asym;sym on one and dc on another, and exposing only one of those Virtual Function (VF) types to the Virtual Machine (VM), the application works as expected. However, when VFs of more than one type are passed to the same VM, the application may only recognize one service-type, e.g. it may detect crypto instances, but not compression instances. There is an assumption that all VFs provide the same services if they come from the same PF. However, detecting which PF they come from is based on domain+bus, which is not always a valid assumption on a VM. | | Implication | This issue prevents the detection of compression services in a virtualized environment when the default kernel configuration is used, and crypto and dc VFs are passed to the VM, potentially impacting the proper functioning of the system. | -| Resolution | Fixed in 23.11.
Temporary solution: use a custom libvirt XML file like QATE-76698 here: https://github.com/intel/qatlib/tree/main#qate-76698 . | +| Resolution | Fixed in 23.11 | | Affected OS | Linux | | Driver/Module | CPM-IA - General | diff --git a/configure.ac b/configure.ac index 8d665f65..c9fb39cd 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], [24.02.0], [qat-linux@intel.com]) +AC_INIT([qatlib], [24.09.0], [qat-linux@intel.com]) AM_INIT_AUTOMAKE([-Wall -Werror -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], [6:0:2]) -AC_SUBST([LIBUSDM_VERSION], [1:0:1]) +AC_SUBST([LIBQAT_VERSION], [7:0:3]) +AC_SUBST([LIBUSDM_VERSION], [1:1:1]) # Checks for programs. AC_PROG_AWK @@ -62,6 +62,12 @@ AC_CHECK_HEADERS([openssl/md5.h], [AC_MSG_ERROR([openssl/md5.h not found])] ) +# Check for numa header +AC_CHECK_HEADERS([numa.h], + [], + [AC_MSG_ERROR([numa.h not found])] +) + # Check if compiler supports mcx16 saved_cflags="$CFLAGS" CFLAGS=-mcx16 @@ -227,6 +233,15 @@ AC_ARG_ENABLE(hb-error-simulation, ) AM_CONDITIONAL([ICP_HB_ERROR_SIMULATION_AC], [test x$hb_error_simulation = xtrue]) +# ICP_THREAD_SPECIFIC_USDM +AC_ARG_ENABLE(icp-thread-specific-usdm, + AS_HELP_STRING([--enable-icp-thread-specific-usdm], [USDM allocates and handles memory specific to threads + (For multi-thread apps, allocated memory information will be maintained separately for each thread). + @<:@default=no@:>@ ]), + [icp_thread_specific_usdm=true], [icp_thread_specific_usdm=false] +) +AM_CONDITIONAL([ICP_THREAD_SPECIFIC_USDM_AC], [test x$icp_thread_specific_usdm = xtrue]) + AC_ARG_ENABLE(legacy-lib-names, AS_HELP_STRING([--enable-legacy-lib-names], [Enables legacy names for libraries.]), [ diff --git a/filelist b/filelist index 74e2b927..c2caa08e 100644 --- a/filelist +++ b/filelist @@ -212,7 +212,6 @@ quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c -quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_transport_ctrl.c @@ -223,7 +222,6 @@ quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_platform.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_platform_acceldev_common.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_platform_acceldev_gen4.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_platform_common.h -quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_transport_ctrl.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_arbiter.h quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_cfg.h @@ -397,7 +395,11 @@ quickassist/lookaside/firmware/include/icp_qat_hw_20_comp.h quickassist/lookaside/firmware/include/icp_qat_hw_20_comp_defs.h 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 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_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 diff --git a/qatlib.spec.in b/qatlib.spec.in index 6e81a737..c5c3e9f2 100644 --- a/qatlib.spec.in +++ b/qatlib.spec.in @@ -11,7 +11,7 @@ Summary: Intel QuickAssist user space library License: BSD-3-Clause AND ( BSD-3-Clause OR GPL-2.0-only ) URL: https://github.com/intel/%{name} Source0: https://github.com/intel/%{name}/archive/%{version}/%{name}-%{version}.tar.gz -BuildRequires: systemd gcc make autoconf automake libtool systemd-devel openssl-devel zlib-devel nasm +BuildRequires: systemd gcc make autoconf automake libtool systemd-devel openssl-devel zlib-devel nasm numactl-devel Requires(pre): shadow-utils Recommends: qatlib-service # https://bugzilla.redhat.com/show_bug.cgi?id=1897661 @@ -132,6 +132,10 @@ exit 0 %{_mandir}/man8/qat_init.sh.8* %changelog +* Thu Sep 05 2024 Berenike Bronikowska - 24.09.0-1 +- Add dependency on numactl-devel. +- Update to qatlib 24.09.0 + * Thu Feb 08 2024 Xinghong Chen - 24.02.0-1 - Add the zuc_sample to tests package. - Update to qatlib 24.02.0 diff --git a/quickassist/lookaside/access_layer/include/icp_accel_devices.h b/quickassist/lookaside/access_layer/include/icp_accel_devices.h index a006d4f1..970b5685 100644 --- a/quickassist/lookaside/access_layer/include/icp_accel_devices.h +++ b/quickassist/lookaside/access_layer/include/icp_accel_devices.h @@ -231,6 +231,9 @@ typedef struct accel_dev_s device_type_t deviceType; /* Device Type */ char deviceName[ADF_DEVICE_TYPE_LENGTH + 1]; /* Device name for SAL */ Cpa32U accelCapabilitiesMask; /* Accelerator's capabilities mask */ + Cpa32U cipherCapabilitiesMask; /* Cipher algorithms capabilities mask */ + Cpa32U hashCapabilitiesMask; /* Hash algorithms capabilities mask */ + Cpa32U asymCapabilitiesMask; /* Asym algorithms capabilities mask */ Cpa32U dcExtendedFeatures; /* bit field of features */ OsalAtomic usageCounter; /* Prevents shutting down the dev if not 0 */ void *pSalHandle; /* For SAL */ @@ -242,7 +245,6 @@ typedef struct accel_dev_s void *accel; Cpa32U maxNumBanks; Cpa32U maxNumRingsPerBank; - void *pInstMgr; /* pointer to dynamic instance resource manager */ void *banks; /* banks information */ #ifdef KERNEL_SPACE const Cpa8U *pAccelName; /* Name given to accelerator */ diff --git a/quickassist/lookaside/access_layer/include/icp_adf_cfg.h b/quickassist/lookaside/access_layer/include/icp_adf_cfg.h index 3925da9b..a3452f34 100644 --- a/quickassist/lookaside/access_layer/include/icp_adf_cfg.h +++ b/quickassist/lookaside/access_layer/include/icp_adf_cfg.h @@ -100,8 +100,6 @@ #define ADF_DEV_NODE_ID ("Device_NodeId") /* Device package id, this is accel_dev id */ #define ADF_DEV_PKG_ID ("Device_PkgId") -/* String names for the exposed sections of config file. */ -#define DYN_SEC "DYN" /* * icp_adf_cfgGetParamValue diff --git a/quickassist/lookaside/access_layer/include/icp_adf_transport.h b/quickassist/lookaside/access_layer/include/icp_adf_transport.h index b9fb88cf..c497ecc4 100644 --- a/quickassist/lookaside/access_layer/include/icp_adf_transport.h +++ b/quickassist/lookaside/access_layer/include/icp_adf_transport.h @@ -115,51 +115,6 @@ typedef void *icp_comms_trans_handle; */ typedef void (*icp_trans_callback)(void *pMsg); -/* - * icp_adf_getDynInstance - * - * Description: - * Get an available instance from dynamic instance pool - * - * Returns: - * CPA_STATUS_SUCCESS on success - * CPA_STATUS_FAIL on failure - * - */ -CpaStatus icp_adf_getDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *pinstance_id); - -/* - * icp_adf_putDynInstance - * - * Description: - * Put back an instance to dynamic instance pool - * - * Returns: - * CPA_STATUS_SUCCESS on success - * CPA_STATUS_FAIL on failure - * - */ -CpaStatus icp_adf_putDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U instance_id); - -/* - * icp_adf_getNumAvailDynInstance - * - * Description: - * Get the number of the available dynamic instances - * - * Returns: - * CPA_STATUS_SUCCESS on success - * CPA_STATUS_FAIL on failure - * - */ -CpaStatus icp_adf_getNumAvailDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *num); - /* * icp_adf_transGetFdForHandle * diff --git a/quickassist/lookaside/access_layer/include/icp_sal_user.h b/quickassist/lookaside/access_layer/include/icp_sal_user.h index 579545a7..2d7feb37 100644 --- a/quickassist/lookaside/access_layer/include/icp_sal_user.h +++ b/quickassist/lookaside/access_layer/include/icp_sal_user.h @@ -143,15 +143,15 @@ CpaStatus icp_sal_userStartMultiProcess(const char *pProcessName, * ************************************************************************/ CpaStatus icp_sal_userStop(void); - +#ifndef ICP_DC_ONLY /************************************************************************* * @ingroup SalUser * @description * This function gets the number of the available dynamic allocated - * crypto instances + * crypto instances. * * @context - * This function is called from the user process context + * This function is called from the user process context. * * @assumptions * None @@ -164,9 +164,12 @@ CpaStatus icp_sal_userStop(void); * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ + CpaStatus icp_sal_userCyGetAvailableNumDynInstances(Cpa32U *pNumCyInstances); +#endif /************************************************************************* * @ingroup SalUser @@ -188,10 +191,13 @@ CpaStatus icp_sal_userCyGetAvailableNumDynInstances(Cpa32U *pNumCyInstances); * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ + CpaStatus icp_sal_userDcGetAvailableNumDynInstances(Cpa32U *pNumDcInstances); +#ifndef ICP_DC_ONLY /************************************************************************* * @ingroup SalUser * @description @@ -239,13 +245,14 @@ CpaStatus icp_sal_userCyGetAvailableNumDynInstancesByDevPkg( * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userCyGetAvailableNumDynInstancesByPkgAccel( Cpa32U *pNumCyInstances, Cpa32U devPkgID, Cpa32U accelerator_number); - +#endif /************************************************************************* * @ingroup SalUser * @description @@ -266,12 +273,14 @@ CpaStatus icp_sal_userCyGetAvailableNumDynInstancesByPkgAccel( * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userDcGetAvailableNumDynInstancesByDevPkg( Cpa32U *pNumDcInstances, Cpa32U devPkgID); +#ifndef ICP_DC_ONLY /************************************************************************* * @ingroup SalUser * @description @@ -295,6 +304,7 @@ CpaStatus icp_sal_userDcGetAvailableNumDynInstancesByDevPkg( * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userCyInstancesAlloc(Cpa32U numCyInstances, @@ -324,6 +334,7 @@ CpaStatus icp_sal_userCyInstancesAlloc(Cpa32U numCyInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userCyInstancesAllocByDevPkg(Cpa32U numCyInstances, @@ -354,6 +365,7 @@ CpaStatus icp_sal_userCyInstancesAllocByDevPkg(Cpa32U numCyInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userCyInstancesAllocByPkgAccel( @@ -385,10 +397,12 @@ CpaStatus icp_sal_userCyInstancesAllocByPkgAccel( * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userCyFreeInstances(Cpa32U numCyInstances, CpaInstanceHandle *pCyInstances); +#endif /************************************************************************* * @ingroup SalUser @@ -413,6 +427,7 @@ CpaStatus icp_sal_userCyFreeInstances(Cpa32U numCyInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userDcInstancesAlloc(Cpa32U numDcInstances, @@ -442,6 +457,7 @@ CpaStatus icp_sal_userDcInstancesAlloc(Cpa32U numDcInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userDcInstancesAllocByDevPkg(Cpa32U numDcInstances, @@ -471,6 +487,7 @@ CpaStatus icp_sal_userDcInstancesAllocByDevPkg(Cpa32U numDcInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_userDcFreeInstances(Cpa32U numDcInstances, @@ -497,6 +514,7 @@ CpaStatus icp_sal_userDcFreeInstances(Cpa32U numDcInstances, * * @retval CPA_STATUS_SUCCESS No error * @retval CPA_STATUS_FAIL Operation failed + * @retval CPA_STATUS_UNSUPPORTED Deprecated function * ************************************************************************/ CpaStatus icp_sal_find_new_devices(void); diff --git a/quickassist/lookaside/access_layer/include/icp_sal_versions.h b/quickassist/lookaside/access_layer/include/icp_sal_versions.h index b451aaf1..1f8cf6bb 100644 --- a/quickassist/lookaside/access_layer/include/icp_sal_versions.h +++ b/quickassist/lookaside/access_layer/include/icp_sal_versions.h @@ -142,7 +142,7 @@ extern "C" { /* Part name and number of the accelerator device */ #define SAL_INFO2_DRIVER_SW_VERSION_MAJ_NUMBER 24 -#define SAL_INFO2_DRIVER_SW_VERSION_MIN_NUMBER 2 +#define SAL_INFO2_DRIVER_SW_VERSION_MIN_NUMBER 9 #define SAL_INFO2_DRIVER_SW_VERSION_PATCH_NUMBER 0 #define SAL_INFO2_DRIVER_SW_VERSION_TYPE "in-tree" 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 2434bf5c..0f3de862 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_chain.c @@ -680,7 +680,7 @@ CpaStatus dcChainInitSessions(CpaInstanceHandle dcInstance, LAC_CHECK_NULL_PARAM(pCySessDesc); #endif LAC_SPINLOCK_DESTROY(&pCySessDesc->requestQueueLock); - LAC_DESTROY_MUTEX(&pCySessDesc->accessLock); + osalAtomicSet(0, &pCySessDesc->accessLock); } LAC_LOG_ERROR("Init compression session failure\n"); return status; @@ -857,7 +857,7 @@ CpaStatus cpaDcChainRemoveSession(const CpaInstanceHandle dcInstance, LAC_CHECK_NULL_PARAM(pCySessDesc); #endif LAC_SPINLOCK_DESTROY(&pCySessDesc->requestQueueLock); - LAC_DESTROY_MUTEX(&pCySessDesc->accessLock); + osalAtomicSet(0, &pCySessDesc->accessLock); return status; } 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 aaadd4ab..44a8af7a 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_datapath.c @@ -1227,7 +1227,7 @@ STATIC CpaStatus dcCheckDestinationData(sal_compression_service_t *pService, #endif { /* Ensure that the destination buffer size is greater or equal - * to devices min output buff size for static compression */ + * to devices min output buff size */ if (destBuffSize < pService->comp_device_data.minOutputBuffSize) { LAC_INVALID_PARAM_LOG1( diff --git a/quickassist/lookaside/access_layer/src/common/compression/dc_dp.c b/quickassist/lookaside/access_layer/src/common/compression/dc_dp.c index 56df6cf7..0a69cfcc 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_dp.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_dp.c @@ -316,11 +316,14 @@ STATIC CpaStatus dcDataPlaneParamCheck(const CpaDcDpOpData *pOpData) } /* Ensure that the destination buffer length for data is greater - * or equal to 128B */ - if (pOpData->bufferLenForData < DC_DEST_BUFFER_DYN_MIN_SIZE) + * or equal to minOutputBuffSizeDynamic */ + if (pOpData->bufferLenForData < + pService->comp_device_data.minOutputBuffSizeDynamic) { - LAC_INVALID_PARAM_LOG("Destination buffer length for data " - "should be greater or equal to 128B"); + LAC_INVALID_PARAM_LOG1( + "Destination buffer length for data " + "should be greater or equal to %d", + pService->comp_device_data.minOutputBuffSizeDynamic); return CPA_STATUS_INVALID_PARAM; } } 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 a3b42434..eec015fb 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 @@ -1022,6 +1022,18 @@ STATIC void dcNsCompHwBlockPopulateGen4( (pService->comp_device_data.enableDmm == CPA_TRUE) ? ICP_QAT_HW_COMP_20_EXTENDED_DELAY_MATCH_MODE_EDMM_ENABLED : ICP_QAT_HW_COMP_20_EXTENDED_DELAY_MATCH_MODE_EDMM_DISABLED; + if ((pSetupData->huffType == CPA_DC_HT_FULL_DYNAMIC) && + (pSetupData->compType == CPA_DC_DEFLATE) && + (pSetupData->compLevel == CPA_DC_L10 || + pSetupData->compLevel == CPA_DC_L11 || + pSetupData->compLevel == CPA_DC_L12)) + { + /* Enable Adaptive Block Drop with dynamic deflate + * compression when levels 10-12 are selected. + * This field is ignored by firmware for devices that + * do not support adaptive block drop */ + hw_comp_lower_csr.abd = ICP_QAT_HW_COMP_20_ABD_ABD_ENABLED; + } /* Hard-coded HW-specific values */ hw_comp_upper_csr.nice = 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 24f3e084..8de866ed 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/dc_session.c +++ b/quickassist/lookaside/access_layer/src/common/compression/dc_session.c @@ -472,6 +472,18 @@ STATIC void dcCompHwBlockPopulateGen4( ? ICP_QAT_HW_COMP_20_EXTENDED_DELAY_MATCH_MODE_EDMM_ENABLED : ICP_QAT_HW_COMP_20_EXTENDED_DELAY_MATCH_MODE_EDMM_DISABLED; + if ((CPA_DC_HT_FULL_DYNAMIC == pSessionDesc->huffType) && + (CPA_DC_DEFLATE == pSessionDesc->compType) && + (CPA_DC_L10 == pSessionDesc->compLevel || + CPA_DC_L11 == pSessionDesc->compLevel || + CPA_DC_L12 == pSessionDesc->compLevel)) + { + /* Enable Adaptive Block Drop with dynamic deflate + * compression when levels 10-12 are selected. + * This field is ignored by firmware for devices that + * do not support adaptive block drop */ + hw_comp_lower_csr.abd = ICP_QAT_HW_COMP_20_ABD_ABD_ENABLED; + } /* Hard-coded HW-specific values */ hw_comp_upper_csr.nice = ICP_QAT_HW_COMP_20_CONFIG_CSR_NICE_PARAM_DEFAULT_VAL; 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 098d228a..d44865e2 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 @@ -88,7 +88,6 @@ /* Restriction on the destination buffer size for compression due to * the management of skid buffers in the firmware */ -#define DC_DEST_BUFFER_DYN_MIN_SIZE (128) #define DC_DEST_BUFFER_STA_MIN_SIZE (64) #define DC_DEST_BUFFER_DYN_MIN_SIZE_GEN4 (512) #define DC_DEST_BUFFER_STA_MIN_SIZE_GEN4 (1024) diff --git a/quickassist/lookaside/access_layer/src/common/compression/reg_sizes.asm b/quickassist/lookaside/access_layer/src/common/compression/reg_sizes.asm index 235a309b..279d8dad 100644 --- a/quickassist/lookaside/access_layer/src/common/compression/reg_sizes.asm +++ b/quickassist/lookaside/access_layer/src/common/compression/reg_sizes.asm @@ -195,21 +195,15 @@ %define XWORD(reg) reg %+ x -%ifdef INTEL_CET_ENABLED - %ifdef __NASM_VER__ - %if AS_FEATURE_LEVEL >= 10 - %ifidn __OUTPUT_FORMAT__,elf32 +%ifidn __OUTPUT_FORMAT__,elf32 section .note.gnu.property note alloc noexec align=4 DD 0x00000004,0x0000000c,0x00000005,0x00554e47 DD 0xc0000002,0x00000004,0x00000003 - %endif - %ifidn __OUTPUT_FORMAT__,elf64 +%endif +%ifidn __OUTPUT_FORMAT__,elf64 section .note.gnu.property note alloc noexec align=8 DD 0x00000004,0x00000010,0x00000005,0x00554e47 DD 0xc0000002,0x00000004,0x00000003,0x00000000 - %endif - %endif - %endif %endif %ifidn __OUTPUT_FORMAT__,elf32 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 b109bd0e..c3c9d8e0 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 @@ -35,7 +35,7 @@ ***************************************************************************/ /** ***************************************************************************** - * @file lac_kpt2_provision.c + * @file lac_kpt_provision.c * * @ingroup LacKpt * diff --git a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_session.h b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_session.h index 3f26bf8a..9ced4144 100644 --- a/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_session.h +++ b/quickassist/lookaside/access_layer/src/common/crypto/sym/include/lac_session.h @@ -308,7 +308,7 @@ typedef struct lac_session_desc_s */ void *writeRingMsgFunc; /**< function which will be called to write ring message */ - OsalMutex accessLock; + OsalAtomic accessLock; /**< Session access lock */ Cpa32U accessReaders; /**< Session readers counter */ @@ -349,6 +349,8 @@ typedef struct lac_session_desc_s /**< The physical address of the ARC4 initial state, set at init ** session time . */ + Cpa64U totalHashPartialReq; + /**< Total size of partial hash requests in bytes. */ } lac_session_desc_t; /** 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 5bf35f6f..620bcd9f 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 @@ -131,17 +131,20 @@ (CPA_CY_SYM_HASH_SHA224 == (hashAlgo)) || \ (CPA_CY_SYM_HASH_SHA3_224 == (hashAlgo))) +#define MAX_HASH_PARTIALS_SIZE (4ULL * 1024 * 1024 * 1024) + static inline void LacAlgChain_LockSessionReader( lac_session_desc_t *pSessionDesc) { /* Session lock in TRAD API */ if (!pSessionDesc->isDPSession) { - LAC_LOCK_MUTEX(&pSessionDesc->accessLock, OSAL_WAIT_FOREVER); + while (osalAtomicTestAndSet(1, &pSessionDesc->accessLock)) + ; pSessionDesc->accessReaders++; - LAC_UNLOCK_MUTEX(&pSessionDesc->accessLock); + osalAtomicRelease(&pSessionDesc->accessLock); } } @@ -151,11 +154,12 @@ static inline void LacAlgChain_UnlockSessionReader( /* Session lock in TRAD API */ if (!pSessionDesc->isDPSession) { - LAC_LOCK_MUTEX(&pSessionDesc->accessLock, OSAL_WAIT_FOREVER); + while (osalAtomicTestAndSet(1, &pSessionDesc->accessLock)) + ; pSessionDesc->accessReaders--; - LAC_UNLOCK_MUTEX(&pSessionDesc->accessLock); + osalAtomicRelease(&pSessionDesc->accessLock); } } @@ -166,21 +170,14 @@ static inline CpaStatus LacAlgChain_LockSessionWriter( if (!pSessionDesc->isDPSession) { - /* Session lock in TRAD API */ - if (CPA_STATUS_SUCCESS != LAC_LOCK_MUTEX(&pSessionDesc->accessLock, - LOCK_SESSION_WRITER_TIMEOUT)) - { - status = CPA_STATUS_RETRY; - } + while (osalAtomicTestAndSet(1, &pSessionDesc->accessLock)) + ; - if (CPA_STATUS_SUCCESS == status) + if (pSessionDesc->accessReaders || + osalAtomicGet(&(pSessionDesc->u.pendingCbCount)) > 0) { - if (pSessionDesc->accessReaders || - osalAtomicGet(&(pSessionDesc->u.pendingCbCount)) > 0) - { - status = CPA_STATUS_RETRY; - LAC_UNLOCK_MUTEX(&pSessionDesc->accessLock); - } + status = CPA_STATUS_RETRY; + osalAtomicRelease(&pSessionDesc->accessLock); } } else @@ -201,7 +198,7 @@ static inline void LacAlgChain_UnlockSessionWriter( /* Session lock in TRAD API */ if (!pSessionDesc->isDPSession) { - LAC_UNLOCK_MUTEX(&pSessionDesc->accessLock); + osalAtomicRelease(&pSessionDesc->accessLock); } } @@ -1545,13 +1542,7 @@ CpaStatus LacAlgChain_SessionInit( } /* Initialise session readers writers */ - stat = LAC_INIT_MUTEX(&pSessionDesc->accessLock); - if (CPA_STATUS_SUCCESS != stat) - { - LAC_LOG_ERROR("Mutex init failed for accessLock"); - return CPA_STATUS_RESOURCE; - } - + osalAtomicSet(0, &pSessionDesc->accessLock); pSessionDesc->pRequestQueueHead = NULL; pSessionDesc->pRequestQueueTail = NULL; pSessionDesc->nonBlockingOpsInProgress = CPA_TRUE; @@ -2252,6 +2243,46 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, pSessionDesc->laCmdFlags, pSessionDesc->laExtCmdFlags); } + else if ((SPC_YES == pSessionDesc->singlePassState) && + (LAC_CIPHER_SPC_IV_SIZE != pOpData->ivLenInBytes)) + { + pSessionDesc->symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; + pSessionDesc->singlePassState = SPC_PROBABLE; + pSessionDesc->isCipher = CPA_TRUE; + pSessionDesc->isAuthEncryptOp = CPA_TRUE; + pSessionDesc->isAuth = CPA_TRUE; + pCdInfo = &(pSessionDesc->contentDescInfo); + pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData; + + if (CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT == + pSessionDesc->cipherDirection) + { + pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_CIPHER_HASH; + } + else + { + pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_HASH_CIPHER; + } + + laCmdId = pSessionDesc->laCmdId; + ICP_QAT_FW_LA_SINGLE_PASS_PROTO_FLAG_SET(pSessionDesc->laCmdFlags, 0); + ICP_QAT_FW_LA_PROTO_SET(pSessionDesc->laCmdFlags, + ICP_QAT_FW_LA_GCM_PROTO); + + LacSymQat_CipherHwBlockPopulateCfgData(pSessionDesc, + pHwBlockBaseInDRAM + + hwBlockOffsetInDRAM, + &sizeInBytes); + + SalQatMsg_CmnHdrWrite( + (icp_qat_fw_comn_req_t *)&(pSessionDesc->reqCacheHdr), + ICP_QAT_FW_COMN_REQ_CPM_FW_LA, + laCmdId, + pSessionDesc->cmnRequestFlags, + pSessionDesc->laCmdFlags, + pSessionDesc->laExtCmdFlags); + } + #ifdef ICP_PARAM_CHECK else if (LAC_CIPHER_IS_CHACHA(cipher) && (LAC_CIPHER_SPC_IV_SIZE != pOpData->ivLenInBytes)) @@ -2301,6 +2332,26 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, } } + if (CPA_CY_SYM_OP_HASH == pSessionDesc->symOperation && + CPA_CY_SYM_PACKET_TYPE_FULL != pOpData->packetType) + { + /* Accumulate the size of partial hash requests. */ + pSessionDesc->totalHashPartialReq += pOpData->messageLenToHashInBytes; + /* Check if hash request size is 4GB or more. */ + if (CPA_STATUS_SUCCESS == status && + MAX_HASH_PARTIALS_SIZE <= pSessionDesc->totalHashPartialReq) + { + LAC_LOG_ERROR("Partial Hash processing of size 4GB or more " + "not supported"); + pSessionDesc->totalHashPartialReq = 0; + status = CPA_STATUS_FAIL; + } + else if (CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL == pOpData->packetType) + { + pSessionDesc->totalHashPartialReq = 0; + } + } + /* Allocate cookie (used by callback function). * If calling from DC Chaining then cookie should already be * allocated. @@ -2532,20 +2583,6 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, #ifdef ICP_PARAM_CHECK status = LacCipher_PerformParamCheck(cipher, pOpData, srcPktSize); - if (CPA_STATUS_SUCCESS != status) - { - /* free the cookie */ - if ((NULL != pCookie) && - (((void *)CPA_STATUS_RETRY) != pCookie)) - { - Lac_MemPoolEntryFree(pCookie); - } - - /* Unlock session on error */ - LacAlgChain_UnlockSessionReader(pSessionDesc); - - return status; - } #endif if (CPA_STATUS_SUCCESS == status) @@ -2719,20 +2756,6 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, pOpData, srcPktSize, pVerifyResult); - if (CPA_STATUS_SUCCESS != status) - { - /* free the cookie */ - if ((NULL != pCookie) && - (((void *)CPA_STATUS_RETRY) != pCookie)) - { - Lac_MemPoolEntryFree(pCookie); - } - - /* Unlock session on error */ - LacAlgChain_UnlockSessionReader(pSessionDesc); - - return status; - } #endif if (CPA_STATUS_SUCCESS == status) { @@ -2924,6 +2947,13 @@ CpaStatus LacAlgChain_Perform(const CpaInstanceHandle instanceHandle, { Lac_MemPoolEntryFree(pSymCookie); } + if (CPA_CY_SYM_OP_HASH == pSessionDesc->symOperation && + CPA_CY_SYM_PACKET_TYPE_FULL != pOpData->packetType && + pSessionDesc->totalHashPartialReq) + { + pSessionDesc->totalHashPartialReq -= + pOpData->messageLenToHashInBytes; + } } return status; } 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 6caa1fe1..e97d7de9 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 @@ -933,7 +933,7 @@ CpaStatus cpaCySymRemoveSession(const CpaInstanceHandle instanceHandle_in, if (CPA_STATUS_SUCCESS == status) { LAC_SPINLOCK_DESTROY(&pSessionDesc->requestQueueLock); - LAC_DESTROY_MUTEX(&pSessionDesc->accessLock); + osalAtomicSet(0, &pSessionDesc->accessLock); if (CPA_FALSE == pSessionDesc->isDPSession) { LAC_SYM_STAT_INC(numSessionsRemoved, instanceHandle); 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 b6f18394..bfa9790d 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 @@ -750,6 +750,43 @@ void LacDp_WriteRingMsgFull(CpaCySymDpOpData *pRequest, pSessionDesc->laCmdFlags, pSessionDesc->laExtCmdFlags); } + else if ((SPC_YES == pSessionDesc->singlePassState) && + (LAC_CIPHER_SPC_IV_SIZE != pRequest->ivLenInBytes)) + { + pSessionDesc->symOperation = CPA_CY_SYM_OP_ALGORITHM_CHAINING; + pSessionDesc->singlePassState = SPC_PROBABLE; + pSessionDesc->isCipher = CPA_TRUE; + pSessionDesc->isAuthEncryptOp = CPA_TRUE; + pSessionDesc->isAuth = CPA_TRUE; + pCdInfo = &(pSessionDesc->contentDescInfo); + pHwBlockBaseInDRAM = (Cpa8U *)pCdInfo->pData; + + if (CPA_CY_SYM_CIPHER_DIRECTION_ENCRYPT == + pSessionDesc->cipherDirection) + { + pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_CIPHER_HASH; + } + else + { + pSessionDesc->laCmdId = ICP_QAT_FW_LA_CMD_HASH_CIPHER; + } + + ICP_QAT_FW_LA_SINGLE_PASS_PROTO_FLAG_SET(pSessionDesc->laCmdFlags, 0); + ICP_QAT_FW_LA_PROTO_SET(pSessionDesc->laCmdFlags, + ICP_QAT_FW_LA_GCM_PROTO); + + LacSymQat_CipherHwBlockPopulateCfgData(pSessionDesc, + pHwBlockBaseInDRAM + + hwBlockOffsetInDRAM, + &sizeInBytes); + SalQatMsg_CmnHdrWrite( + (icp_qat_fw_comn_req_t *)&(pSessionDesc->reqCacheHdr), + ICP_QAT_FW_COMN_REQ_CPM_FW_LA, + pSessionDesc->laCmdId, + pSessionDesc->cmnRequestFlags, + pSessionDesc->laCmdFlags, + pSessionDesc->laExtCmdFlags); + } else if (CPA_CY_SYM_HASH_AES_GMAC == pSessionDesc->hashAlgorithm) { pSessionDesc->aadLenInBytes = pRequest->messageLenToHashInBytes; 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 9b88ee9d..4f71663b 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 @@ -91,6 +91,8 @@ #include "icp_qat_fw_la.h" #define LAC_UNUSED_POS_MASK 0x3 +/* To determine an overflow on a 32 bit unsigned value */ +#define UINT_OVERFLOW (0xFFFFFFFF00000000UL) /***************************************************************************** * Internal data @@ -809,6 +811,7 @@ void LacSymQat_CipherHwBlockPopulateKeySetup( { Cpa8U *pCipherKey = (Cpa8U *)pCipherHwBlock; Cpa32U actualKeyLenInBytes = pCipherSetupData->cipherKeyLenInBytes; + Cpa64U tempKeyLenInBytes = 0; *pSizeInBytes = 0; @@ -834,7 +837,7 @@ void LacSymQat_CipherHwBlockPopulateKeySetup( /* Set the Cipher key field in the cipher block */ memcpy(pCipherKey, pCipherSetupData->pCipherKey, actualKeyLenInBytes); /* Pad the key with 0's if required */ - if (0 < (targetKeyLenInBytes - actualKeyLenInBytes)) + if (targetKeyLenInBytes > actualKeyLenInBytes) { LAC_OS_BZERO(pCipherKey + actualKeyLenInBytes, targetKeyLenInBytes - actualKeyLenInBytes); @@ -884,9 +887,15 @@ void LacSymQat_CipherHwBlockPopulateKeySetup( pTempKey[index] = pCipherKey[index] ^ pTempKey[index]; } pTempKey = (pCipherKey + targetKeyLenInBytes); - /* also add padding for AES F8 */ - *pSizeInBytes += 2 * targetKeyLenInBytes; - LAC_OS_BZERO(pTempKey, 2 * targetKeyLenInBytes); + tempKeyLenInBytes = 2UL * targetKeyLenInBytes; + + /* Check for overflow */ + if (!(tempKeyLenInBytes & UINT_OVERFLOW)) + { + /* also add padding for AES F8 */ + *pSizeInBytes += 2 * targetKeyLenInBytes; + LAC_OS_BZERO(pTempKey, 2 * targetKeyLenInBytes); + } } break; case CPA_CY_SYM_CIPHER_SNOW3G_UEA2: 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 2565aedf..c352af1d 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_compression.c @@ -489,15 +489,9 @@ STATIC CpaStatus SalCtr_DcInstInit(icp_accel_dev_t *device, sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; CpaStatus status = CPA_STATUS_SUCCESS; - char *section = DYN_SEC; + char *section = icpGetProcessName(); Cpa32S strSize = 0; - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCompressionService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - /* Get Config Info: Accel Num, bank Num, packageID, coreAffinity, nodeAffinity and response mode */ @@ -679,14 +673,7 @@ STATIC CpaStatus SalCtrl_DcDebugInit(icp_accel_dev_t *device, sal_statistics_collection_t *pStatsCollection = (sal_statistics_collection_t *)device->pQatStats; CpaStatus status = CPA_STATUS_SUCCESS; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCompressionService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + char *section = icpGetProcessName(); if (CPA_TRUE == pStatsCollection->bStatsEnabled) { /* Get instance name for stats */ @@ -791,7 +778,7 @@ CpaStatus SalCtrl_CompressionInit(icp_accel_dev_t *device, sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; Cpa32U msgSize = 0; - char *section = DYN_SEC; + char *section = NULL; #ifndef ICP_DC_ONLY sal_dc_chain_service_t *pChainService = NULL; #endif @@ -800,12 +787,7 @@ CpaStatus SalCtrl_CompressionInit(icp_accel_dev_t *device, pCompressionService->generic_service_info.state = SAL_SERVICE_STATE_INITIALIZING; - - if (CPA_FALSE == pCompressionService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); if (pStatsCollection == NULL) { return CPA_STATUS_FAIL; @@ -1173,18 +1155,13 @@ CpaStatus SalCtrl_CompressionRestarted(icp_accel_dev_t *device, sal_compression_service_t *pCompressionService = (sal_compression_service_t *)service; Cpa32U msgSize = 0; - char *section = DYN_SEC; + char *section = NULL; #ifndef ICP_DC_ONLY sal_dc_chain_service_t *pChainService = NULL; #endif SAL_SERVICE_GOOD_FOR_RESTARTED(pCompressionService); - - if (CPA_FALSE == pCompressionService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); if (pStatsCollection == NULL) { status = CPA_STATUS_FAIL; @@ -1926,7 +1903,7 @@ CpaStatus cpaDcInstanceGetInfo2(const CpaInstanceHandle instanceHandle, CpaStatus status = CPA_STATUS_SUCCESS; char keyStr[ADF_CFG_MAX_KEY_LEN_IN_BYTES] = {0}; char valStr[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char *section = DYN_SEC; + char *section = NULL; Cpa32S strSize = 0; #ifdef ICP_TRACE @@ -2018,12 +1995,7 @@ CpaStatus cpaDcInstanceGetInfo2(const CpaInstanceHandle instanceHandle, SAL_INFO2_PART_NAME, dev->deviceName); pInstanceInfo2->partName[CPA_INST_PART_NAME_SIZE - 1] = '\0'; - - if (CPA_FALSE == pCompressionService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); status = Sal_StringParsing(SAL_CFG_DC, pCompressionService->generic_service_info.instance, @@ -2340,7 +2312,7 @@ CpaStatus SalCtrl_DcDevErr_GenResponses(icp_accel_dev_t *accel_dev, Cpa32U enabled_services) { sal_t *service_container = NULL; - CpaStatus status = CPA_STATUS_INVALID_PARAM; + CpaStatus status = CPA_STATUS_SUCCESS; service_container = accel_dev->pSalHandle; if (SalCtrl_IsServiceEnabled(enabled_services, 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 bf1d8a1d..eb4fbaf7 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_crypto.c @@ -681,12 +681,7 @@ STATIC CpaStatus SalCtrl_AsymCreateTransHandle(icp_accel_dev_t *device, { rx_resp_type = ICP_RESP_TYPE_POLL; } - - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); /* Parse Asym ring details first */ status = Sal_StringParsing(SAL_CFG_CY, pCryptoService->generic_service_info.instance, @@ -752,12 +747,7 @@ STATIC CpaStatus SalCtrl_AsymReinitTransHandle(icp_accel_dev_t *device, { rx_resp_type = ICP_RESP_TYPE_POLL; } - - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); /* Parse Asym ring details first */ status = Sal_StringParsing(SAL_CFG_CY, pCryptoService->generic_service_info.instance, @@ -825,12 +815,7 @@ STATIC CpaStatus SalCtrl_SymCreateTransHandle(icp_accel_dev_t *device, { rx_resp_type = ICP_RESP_TYPE_POLL; } - - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); /* Parse Sym ring details */ status = Sal_StringParsing(SAL_CFG_CY, pCryptoService->generic_service_info.instance, @@ -897,12 +882,7 @@ STATIC CpaStatus SalCtrl_SymReinitTransHandle(icp_accel_dev_t *device, { rx_resp_type = ICP_RESP_TYPE_POLL; } - - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); /* Parse Sym ring details */ status = Sal_StringParsing(SAL_CFG_CY, pCryptoService->generic_service_info.instance, @@ -1678,13 +1658,7 @@ STATIC CpaStatus SalCtrl_AsymInit(icp_accel_dev_t *device, Cpa32U numAsymConcurrentReq = 0; char temp_string[SAL_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } + char *section = icpGetProcessName(); /* get num concurrent requests from config file */ if (CPA_STATUS_SUCCESS != @@ -1822,13 +1796,7 @@ STATIC CpaStatus SalCtrl_AsymReinit(icp_accel_dev_t *device, CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U numAsymConcurrentReq = 0; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } + char *section = icpGetProcessName(); /* get num concurrent requests from config file */ if (CPA_STATUS_SUCCESS != @@ -1872,13 +1840,7 @@ STATIC CpaStatus SalCtrl_SymInit(icp_accel_dev_t *device, Cpa32U numSymConcurrentReq = 0; char temp_string[SAL_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } + char *section = icpGetProcessName(); /* Set default value of HMAC mode */ @@ -1965,13 +1927,7 @@ STATIC CpaStatus SalCtrl_SymReinit(icp_accel_dev_t *device, CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U numSymConcurrentReq = 0; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } + char *section = icpGetProcessName(); /* Register callbacks for the symmetric services @@ -2052,13 +2008,7 @@ STATIC CpaStatus SalCtrl_DebugInit(icp_accel_dev_t *device, sal_statistics_collection_t *pStatsCollection = (sal_statistics_collection_t *)device->pQatStats; CpaStatus status = CPA_STATUS_SUCCESS; - char *section = DYN_SEC; - - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } + char *section = icpGetProcessName(); if (CPA_TRUE == pStatsCollection->bStatsEnabled) { @@ -2139,15 +2089,9 @@ STATIC CpaStatus SalCtr_InstInit(icp_accel_dev_t *device, char temp_string2[SAL_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; sal_crypto_service_t *pCryptoService = (sal_crypto_service_t *)service; CpaStatus status = CPA_STATUS_SUCCESS; - char *section = DYN_SEC; + char *section = icpGetProcessName(); Cpa32S strSize = 0; - /* Instance may not in the DYN section */ - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - /* Get Config Info: Accel Num, bank Num, packageID, coreAffinity, nodeAffinity and response mode */ @@ -3102,7 +3046,7 @@ CpaStatus cpaCyInstanceGetInfo2(const CpaInstanceHandle instanceHandle_in, CpaStatus status = CPA_STATUS_SUCCESS; char keyStr[ADF_CFG_MAX_KEY_LEN_IN_BYTES] = {0}; char valStr[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - char *section = DYN_SEC; + char *section = NULL; Cpa32S strSize = 0; #ifdef ICP_TRACE @@ -3200,12 +3144,7 @@ CpaStatus cpaCyInstanceGetInfo2(const CpaInstanceHandle instanceHandle_in, SAL_CFG_NAME, keyStr); LAC_CHECK_STATUS(status); - - if (CPA_FALSE == pCryptoService->generic_service_info.is_dyn) - { - section = icpGetProcessName(); - } - + section = icpGetProcessName(); status = icp_adf_cfgGetParamValue(dev, section, keyStr, valStr); LAC_CHECK_STATUS(status); @@ -3531,7 +3470,7 @@ CpaStatus SalCtrl_CyDevErr_GenResponses(icp_accel_dev_t *accel_dev, Cpa32U enabled_services) { sal_t *service_container = NULL; - CpaStatus status = CPA_STATUS_INVALID_PARAM; + CpaStatus status = CPA_STATUS_SUCCESS; service_container = accel_dev->pSalHandle; if (SalCtrl_IsServiceEnabled(enabled_services, 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 49859e11..e7c7647c 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 @@ -516,7 +516,6 @@ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, sal_service_type_t svc_type) { CpaStatus status = CPA_STATUS_SUCCESS; - sal_list_t *dyn_service = NULL; sal_service_t *inst = (sal_service_t *)SalList_getObject(*services); #ifndef KERNEL_SPACE Sal_CleanMiscErrStats(inst); @@ -530,17 +529,6 @@ STATIC CpaStatus SalCtrl_ServiceShutdown(icp_accel_dev_t *device, *debug_dir = NULL; } - dyn_service = *services; - while (dyn_service) - { - inst = (sal_service_t *)SalList_getObject(dyn_service); - if (CPA_TRUE == inst->is_dyn) - { - icp_adf_putDynInstance( - device, (adf_service_type_t)svc_type, inst->instance); - } - dyn_service = SalList_next(dyn_service); - } /* Free Sal services controller memory */ SalList_free(services); return status; diff --git a/quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c b/quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c index 8a895964..88de6760 100644 --- a/quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c +++ b/quickassist/lookaside/access_layer/src/common/ctrl/sal_instances.c @@ -194,6 +194,11 @@ CpaStatus Lac_GetCyNumInstancesByType( CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->asym_services; + if ((NULL == list_temp) && + (CPA_ACC_SVC_TYPE_CRYPTO != accelerationServiceType)) + { + list_temp = base_addr->crypto_services; + } while (NULL != list_temp) { num_inst++; @@ -205,6 +210,11 @@ CpaStatus Lac_GetCyNumInstancesByType( CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->sym_services; + if ((NULL == list_temp) && + (CPA_ACC_SVC_TYPE_CRYPTO != accelerationServiceType)) + { + list_temp = base_addr->crypto_services; + } while (NULL != list_temp) { num_inst++; @@ -360,6 +370,11 @@ CpaStatus Lac_GetCyInstancesByType( CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->asym_services; + if ((NULL == list_temp) && + (CPA_ACC_SVC_TYPE_CRYPTO != accelerationServiceType)) + { + list_temp = base_addr->crypto_services; + } while (NULL != list_temp) { if (index > (numInstances - 1)) @@ -375,6 +390,11 @@ CpaStatus Lac_GetCyInstancesByType( CPA_ACC_SVC_TYPE_CRYPTO == accelerationServiceType) { list_temp = base_addr->sym_services; + if ((NULL == list_temp) && + (CPA_ACC_SVC_TYPE_CRYPTO != accelerationServiceType)) + { + list_temp = base_addr->crypto_services; + } while (NULL != list_temp) { if (index > (numInstances - 1)) diff --git a/quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c b/quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c index 1cf3beef..65e74142 100644 --- a/quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c +++ b/quickassist/lookaside/access_layer/src/common/device/sal_dev_info.c @@ -106,7 +106,7 @@ CpaStatus cpaGetDeviceInfo(Cpa16U device, CpaDeviceInfo *deviceInfo) #ifdef ICP_PARAM_CHECK LAC_CHECK_NULL_PARAM(deviceInfo); #endif - status = icp_adf_getNumInstances(&numDevicesAvail); + icp_adf_getNumInstances(&numDevicesAvail); /* Check if the application is not attempting to access a * device that does not exist. */ 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 e249a25f..82edab5c 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_common.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_common.h @@ -235,22 +235,16 @@ char *icpGetProcessName(void); #undef INLINE #define STATIC -/**< @ingroup LacCommon - * When DEBUG is set STATIC evaluates to nothing. */ - #define INLINE /**< @ingroup LacCommon - * When DEBUG is set INLINE evaluates to nothing. */ + * When DEBUG is set STATIC/INLINE evaluates to nothing. */ #else #define STATIC static -/**< @ingroup LacCommon - * otherwise it evaluates to the static keyword */ - #define INLINE inline /**< @ingroup LacCommon - * otherwise it evaluates to the inline keyword */ + * otherwise it evaluates to the static/inline keyword */ #endif diff --git a/quickassist/lookaside/access_layer/src/common/include/lac_mem_pools.h b/quickassist/lookaside/access_layer/src/common/include/lac_mem_pools.h index 2af209b3..39ae57a4 100644 --- a/quickassist/lookaside/access_layer/src/common/include/lac_mem_pools.h +++ b/quickassist/lookaside/access_layer/src/common/include/lac_mem_pools.h @@ -418,25 +418,6 @@ CpaStatus Lac_MemPoolInitSymCookiesPhyAddr(lac_memory_pool_id_t poolID); CpaStatus Lac_MemPoolInitAsymCookies(lac_memory_pool_id_t poolID, CpaInstanceHandle instanceHandle); -/** - ******************************************************************************* - * @ingroup LacMemPool - * This function initialises the physical addresses of the compression cookie - * - * @blocking - * No - * @reentrant - * No - * @threadSafe - * No - * @param[in] poolID ID of the pool - * - * @retval CPA_STATUS_FAIL function failed - * @retval CPA_STATUS_SUCCESS function executed successfully - * - ******************************************************************************/ -CpaStatus Lac_MemPoolInitDcCookiePhyAddr(lac_memory_pool_id_t poolID); - /** ******************************************************************************* * @ingroup LacMemPool 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 eb47c80e..5dfc4944 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 @@ -187,8 +187,6 @@ typedef struct sal_service_s void *debug_parent_dir; /**< Pointer to parent proc dir entry */ - CpaBoolean is_dyn; - Cpa32U capabilitiesMask; /**< Capabilities mask of the device */ 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 fa4575a1..cd6e6602 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 @@ -568,45 +568,3 @@ CpaStatus Lac_MemPoolInitAsymCookies(lac_memory_pool_id_t poolID, #endif #endif -CpaStatus Lac_MemPoolInitDcCookiePhyAddr(lac_memory_pool_id_t poolID) -{ - lac_mem_pool_hdr_t *pPoolID = (lac_mem_pool_hdr_t *)poolID; - dc_compression_cookie_t *pCookie = NULL; - lac_mem_blk_t *pCurrentBlk = NULL; - - if (NULL == pPoolID) - { - LAC_LOG_ERROR("Invalid Pool ID"); - return CPA_STATUS_FAIL; - } - - if (NULL == pPoolID->trackBlks) - { - pCurrentBlk = top(&pPoolID->stack); - - while (pCurrentBlk != NULL) - { - pCookie = (dc_compression_cookie_t *)((LAC_ARCH_UINT)(pCurrentBlk) + - sizeof(lac_mem_blk_t)); - pCurrentBlk = pCurrentBlk->pNext; - - // pCookie->dcReqParamsBufferPhyAddr = - LAC_OS_VIRT_TO_PHYS_INTERNAL(pCookie->dcReqParamsBuffer); - } - } - else - { - Cpa32U count = 0; - - for (count = 0; count < pPoolID->numElementsInPool; count++) - { - pCurrentBlk = pPoolID->trackBlks[count]; - pCookie = (dc_compression_cookie_t *)((LAC_ARCH_UINT)(pCurrentBlk) + - sizeof(lac_mem_blk_t)); - - // pCookie->dcReqParamsBufferPhyAddr = - LAC_OS_VIRT_TO_PHYS_INTERNAL(pCookie->dcReqParamsBuffer); - } - } - return CPA_STATUS_SUCCESS; -} diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c index bb7e0648..ebdf3e21 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_process_proxy.c @@ -61,7 +61,6 @@ #include "icp_adf_init.h" #include "icp_adf_accel_mgr.h" #include "icp_adf_transport.h" -#include "adf_transport_ctrl.h" #include "adf_user_init.h" #include "adf_user_transport.h" #include "adf_init.h" @@ -108,7 +107,7 @@ CpaStatus icp_adf_resetUserProxy(void); * adf_process_proxy_stop * Sets the process proxy running state to stopped */ -STATIC inline void adf_process_proxy_stop(void) +STATIC INLINE void adf_process_proxy_stop(void) { osalAtomicSet(0, &process_proxy_status); } @@ -117,12 +116,12 @@ STATIC inline void adf_process_proxy_stop(void) * adf_process_proxy_start * Sets the process proxy running state to started */ -STATIC inline void adf_process_proxy_start(void) +STATIC INLINE void adf_process_proxy_start(void) { osalAtomicSet(1, &process_proxy_status); } -STATIC inline Cpa32U adf_process_proxy_running(void) +STATIC INLINE Cpa32U adf_process_proxy_running(void) { return (Cpa32U)osalAtomicGet(&process_proxy_status); } @@ -337,8 +336,6 @@ CpaStatus icp_adf_userProcessToStart(char const *const name_tml, char *name) void icp_adf_userProcessStop(void) { adf_io_userProcessStop(); - - return; } /* diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c index 94f17568..6ca09537 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ETring_mgr_dp.c @@ -47,7 +47,6 @@ #include "icp_accel_devices.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "adf_transport_ctrl.h" #include "adf_platform.h" #include "adf_dev_ring_ctl.h" @@ -202,13 +201,13 @@ CpaStatus icp_adf_pollQueue(icp_comms_trans_handle trans_hnd, pRingHandle->head); /* If there are valid messages then process them */ - while ((*msg != EMPTY_RING_ENTRY_SIG) && (msg_counter < response_quota)) + while ((*msg != EMPTY_RING_SIG_WORD) && (msg_counter < response_quota)) { /* Invoke the callback for the message */ pRingHandle->callback((Cpa32U *)msg); /* Mark the message as processed */ - *msg = EMPTY_RING_ENTRY_SIG; + *msg = EMPTY_RING_SIG_WORD; /* Advance the head offset and handle wraparound */ pRingHandle->head = diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c index 272d808c..4d3f2ea2 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_cfg.c @@ -56,6 +56,15 @@ Cpa16U icp_adf_cfgGetBusAddress(Cpa16U accelId) return adf_io_cfgGetBusAddress(accelId); } +/* + * icp_adf_cfgCheckUserSection + * check if user process section exists in device cfg + */ +int icp_adf_cfgCheckUserSection(int dev_id, uint8_t *pSectionPresent) +{ + return adf_io_cfgCheckUserSection(dev_id, pSectionPresent); +} + CpaStatus icp_adf_resetDevice(Cpa32U accelId) { if (!icp_adf_isDevIdValid(accelId)) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c index c0cb097a..cd88fd9e 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_device.c @@ -43,6 +43,7 @@ #include "icp_adf_user_proxy.h" #include "adf_user.h" +#include "adf_user_cfg.h" #include "adf_io_cfg.h" #include "adf_io_bundles.h" @@ -61,17 +62,17 @@ typedef struct adf_event_queue_s adf_event_node_t *tail; } adf_event_queue_t; -STATIC adf_event_queue_t adf_event_queue[ADF_MAX_DEVICES] = {{0}}; +STATIC adf_event_queue_t adf_event_queue[ADF_MAX_DEVICES] = { { 0 } }; /* * User space copy of acceleration devices */ -STATIC icp_accel_dev_t *accel_tbl[ADF_MAX_DEVICES] = {0}; +STATIC icp_accel_dev_t *accel_tbl[ADF_MAX_DEVICES] = { 0 }; /* * Need to keep track of what device is currently in error */ -STATIC char accel_dev_error_stat[ADF_MAX_DEVICES] = {0}; +STATIC char accel_dev_error_stat[ADF_MAX_DEVICES] = { 0 }; /* * Need to keep track of what device is currently in restarting @@ -153,12 +154,6 @@ int32_t adf_clean_device(int32_t dev_id) return CPA_STATUS_FAIL; } - if (accel_tbl[dev_id] == NULL) - { - ICP_MUTEX_UNLOCK(&accel_tbl_mutex); - return 0; - } - dev = accel_tbl[dev_id]; @@ -206,7 +201,7 @@ int32_t adf_init_devices(void) * adf_stop_system * Sets the user proxy running state to stopped */ -STATIC inline void adf_stop_system(icp_accel_dev_t *accel_dev) +STATIC INLINE void adf_stop_system(icp_accel_dev_t *accel_dev) { accel_dev->adfSubsystemStatus = 0; } @@ -215,7 +210,7 @@ STATIC inline void adf_stop_system(icp_accel_dev_t *accel_dev) * adf_start_system * Sets the user proxy running state to started */ -STATIC inline void adf_start_system(icp_accel_dev_t *accel_dev) +STATIC INLINE void adf_start_system(icp_accel_dev_t *accel_dev) { accel_dev->adfSubsystemStatus = 1; } @@ -242,7 +237,6 @@ STATIC void adf_event_queue_head(Cpa32U accelId, { *event = adf_event_queue[accelId].head->event; event_start->secs = adf_event_queue[accelId].head->start.secs; - return; } /* @@ -426,6 +420,7 @@ STATIC void adf_poll_enqueued_events(void) STATIC int32_t adf_proxy_get_device(int dev_id) { int32_t err; + uint8_t is_section_present = 0; if ((dev_id >= ADF_MAX_DEVICES) || (NULL != accel_tbl[dev_id])) return 0; /* Invalid dev_id or Already created. */ @@ -433,11 +428,19 @@ STATIC int32_t adf_proxy_get_device(int dev_id) if (!adf_io_accel_dev_exist(dev_id)) return 0; - if (adf_io_create_accel(&accel_tbl[dev_id], dev_id)) - { - err = ENOMEM; - goto adf_proxy_get_device_exit; - } + err = icp_adf_cfgCheckUserSection(dev_id, &is_section_present); + if (err) + return err; + + if (!is_section_present) + /* If user section is not present in dev_id cfg, then + * don't populate accel_tbl[dev_id] as it is redundant. + */ + return 0; + + err = adf_io_create_accel(&accel_tbl[dev_id], dev_id); + if (err) + return err; err = adf_user_transport_init(accel_tbl[dev_id]); if (0 != err) @@ -451,9 +454,8 @@ STATIC int32_t adf_proxy_get_device(int dev_id) return 0; adf_proxy_get_device_init_failed: - free(accel_tbl[dev_id]); + adf_io_destroy_accel(accel_tbl[dev_id]); accel_tbl[dev_id] = NULL; -adf_proxy_get_device_exit: return err; } @@ -490,7 +492,7 @@ STATIC int32_t adf_proxy_restart_device(int dev_id) adf_proxy_restart_device_init_failed: adf_user_transport_exit(accel_tbl[dev_id]); - free(accel_tbl[dev_id]); + adf_io_destroy_accel(accel_tbl[dev_id]); accel_tbl[dev_id] = NULL; adf_proxy_restart_device_exit: return err; @@ -498,7 +500,7 @@ STATIC int32_t adf_proxy_restart_device(int dev_id) STATIC int adf_proxy_get_dev_events(int dev_id) { - enum adf_event event[] = {ADF_EVENT_INIT, ADF_EVENT_START}; + enum adf_event event[] = { ADF_EVENT_INIT, ADF_EVENT_START }; size_t i = 0; if (accel_tbl[dev_id] != NULL) @@ -550,6 +552,12 @@ CpaStatus icp_adf_pollDeviceEvents(void) ADF_ERROR("Invalid accelId (%d) from event poll\n", accelId); continue; } + if (!accel_tbl[accelId]) + /* accel_tbl[accelId] is populated only if the accelId cfg has the + * user process section started by the application, else it will + * continue to be NULL. So, events on this accelId can be ignored. + */ + continue; if (adf_event_queue_is_empty(accelId)) { @@ -583,7 +591,6 @@ CpaStatus icp_adf_pollDeviceEvents(void) void icp_adf_qaDevGet(icp_accel_dev_t *pAccelDev) { __sync_fetch_and_add(&pAccelDev->usageCounter, 1); - return; } /* @@ -593,7 +600,6 @@ void icp_adf_qaDevGet(icp_accel_dev_t *pAccelDev) void icp_adf_qaDevPut(icp_accel_dev_t *pAccelDev) { __sync_fetch_and_sub(&pAccelDev->usageCounter, 1); - return; } /* diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c deleted file mode 100644 index 6b6453a8..00000000 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_dyn.c +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * - * BSD LICENSE - * - * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - ***************************************************************************/ -#include -#include - -CpaStatus icp_adf_getDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *pinstance_id) -{ - return CPA_STATUS_FAIL; -} - -CpaStatus icp_adf_putDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U instance_id) -{ - return CPA_STATUS_FAIL; -} - -CpaStatus icp_adf_getNumAvailDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *num) -{ - *num = 0; - return CPA_STATUS_FAIL; -} diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c index e88822b0..f2c6ccfc 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_init.c @@ -57,7 +57,7 @@ */ STATIC subservice_registation_handle_t *pSubsystemTable = NULL; STATIC subservice_registation_handle_t *pSubsystemTableHead = NULL; -STATIC ICP_MUTEX subsystemTableLock = {0}; +STATIC ICP_MUTEX subsystemTableLock = { 0 }; char *icp_module_name = "ADF_UIO_PROXY"; /* Slepping time before subsystem is started */ @@ -321,7 +321,6 @@ CpaStatus adf_user_subsystemInit(icp_accel_dev_t *accel_dev) { CpaStatus status = CPA_STATUS_FAIL; subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); while (NULL != subsystem_hdl) { @@ -363,7 +362,6 @@ CpaStatus adf_user_subsystemStart(icp_accel_dev_t *accel_dev) { CpaStatus status = CPA_STATUS_FAIL; subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); while (NULL != subsystem_hdl) { @@ -403,7 +401,6 @@ CpaStatus adf_user_subsystemStop(icp_accel_dev_t *accel_dev) CpaStatus status = CPA_STATUS_FAIL; subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; Cpa32U sleepflag = 0; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); while (NULL != subsystem_hdl) { @@ -462,7 +459,6 @@ CpaStatus adf_user_subsystemShutdown(icp_accel_dev_t *accel_dev) { CpaStatus status = CPA_STATUS_FAIL; subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); while (NULL != subsystem_hdl) { @@ -558,7 +554,6 @@ CpaStatus adf_subsystemRestarting(icp_accel_dev_t *accel_dev) subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; Cpa32U retryflag = 0; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); ICP_CHECK_PARAM_LT_MAX(accel_dev->accelId, ADF_MAX_DEVICES - 1); while (NULL != subsystem_hdl) @@ -671,7 +666,6 @@ CpaStatus adf_subsystemError(icp_accel_dev_t *accel_dev) Cpa32U pendingflag = 0; subservice_registation_handle_t *subsystem_hdl = pSubsystemTableHead; - ICP_CHECK_FOR_NULL_PARAM(accel_dev); ICP_CHECK_PARAM_LT_MAX(accel_dev->accelId, ADF_MAX_DEVICES - 1); while (NULL != subsystem_hdl) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c index cd66f33f..f1a665cc 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_ring.c @@ -42,7 +42,6 @@ #include #include #include -#include "adf_transport_ctrl.h" #include "adf_io_ring.h" static uint32_t validateRingSize(uint32_t num_msgs_on_ring, @@ -136,11 +135,11 @@ static void adf_unreserve_ring(adf_dev_bank_handle_t *bank, } -int32_t adf_user_put_msg(adf_dev_ring_handle_t *ring, - uint32_t *inBuf, - uint64_t *seq_num) +CpaStatus adf_user_put_msg(adf_dev_ring_handle_t *ring, + uint32_t *inBuf, + uint64_t *seq_num) { - int status; + CpaStatus status; uint32_t *targetAddr; int64_t flight; ICP_CHECK_FOR_NULL_PARAM(ring); @@ -196,57 +195,6 @@ int32_t adf_user_put_msg(adf_dev_ring_handle_t *ring, return status; } -/* - * Notifies the transport handle in question. - */ -int32_t adf_user_notify_msgs(adf_dev_ring_handle_t *ring) -{ - uint32_t *msg; - uint32_t msg_counter = 0; - - ICP_CHECK_FOR_NULL_PARAM(ring); - - msg = (uint32_t *)(((UARCH_INT)ring->ring_virt_addr) + ring->head); - - /* If there are valid messages then process them */ - while (*msg != EMPTY_RING_SIG_WORD) - { - /* Invoke the callback for the message */ - ring->callback((uint32_t *)msg); - - /* Mark the message as processed */ - *msg = EMPTY_RING_SIG_WORD; - - /* Advance the head offset and handle wraparound */ - ring->head = modulo((ring->head + ring->message_size), ring->modulo); - msg_counter++; - - /* Point to where the next message should be */ - msg = (uint32_t *)(((UARCH_INT)ring->ring_virt_addr) + ring->head); - } - - /* Update the head CSR if any messages were processed */ - if (msg_counter > 0) - { - __sync_sub_and_fetch(ring->in_flight, msg_counter); - /* Coalesce head writes to reduce impact of MMIO write */ - if (msg_counter > ring->coal_write_count) - { - ring->coal_write_count = ring->min_resps_per_head_write; - WRITE_CSR_RING_HEAD( - ring->csr_addr, ring->bank_offset, ring->ring_num, ring->head); - } - else - { - /* Not enough responses have been processed to warrant the cost - * of a head write. Updating the count for the next time. */ - ring->coal_write_count -= msg_counter; - } - } - - return 0; -} - int32_t adf_user_check_ring_error(adf_dev_ring_handle_t *ring) { uint8_t *csr_base_addr = NULL; @@ -306,7 +254,7 @@ CpaBoolean adf_user_check_resp_ring(adf_dev_ring_handle_t *ring) * empty or the response quota has been fulfilled. * If the response quota is zero, messages are read until the ring is drained. */ -int32_t adf_user_notify_msgs_poll(adf_dev_ring_handle_t *ring) +CpaStatus adf_user_notify_msgs_poll(adf_dev_ring_handle_t *ring) { volatile uint32_t *msg = NULL; uint32_t msg_counter = 0, response_quota; @@ -382,6 +330,8 @@ static int32_t adf_init_ring_internal(adf_dev_ring_handle_t *ring, uint32_t max_space = ring_size_bytes; device_type_t deviceType; + ICP_CHECK_FOR_NULL_PARAM(ring->accel_dev); + /* Exclusive access to one ring */ if (adf_reserve_ring(bank, ring_num)) { @@ -390,7 +340,6 @@ static int32_t adf_init_ring_internal(adf_dev_ring_handle_t *ring, return -EBUSY; } - ICP_CHECK_FOR_NULL_PARAM(ring->accel_dev); deviceType = ring->accel_dev->deviceType; ring->head = 0; @@ -464,7 +413,7 @@ int32_t adf_init_ring(adf_dev_ring_handle_t *ring, if ((NULL == ring->ring_virt_addr) || (0 == ring->ring_phys_base_addr)) { - ADF_ERROR("unable to get ringbuf(v:%p,p:%p) for rings in bank(%lu)\n", + ADF_ERROR("unable to get ringbuf(v:%p,p:%llx) for rings in bank(%u)\n", ring->ring_virt_addr, (void *)ring->ring_phys_base_addr, (unsigned long)ring->ring_num); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_transport_ctrl.c b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_transport_ctrl.c index e38848a2..2b4922e1 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_transport_ctrl.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/adf_user_transport_ctrl.c @@ -62,7 +62,6 @@ #include "adf_kernel_types.h" #include "icp_adf_init.h" #include "icp_adf_transport.h" -#include "adf_transport_ctrl.h" #include "adf_platform.h" #include "adf_dev_ring_ctl.h" #include "adf_user_transport.h" @@ -75,7 +74,7 @@ #include "adf_user_arbiter.h" #include "adf_user_cfg.h" -STATIC Cpa32U *ringInflights[ADF_MAX_DEVICES] = {NULL}; +STATIC Cpa32U *ringInflights[ADF_MAX_DEVICES] = { NULL }; extern void *adf_get_bank_base_addr(int accelId, int bankid, @@ -250,14 +249,11 @@ void adf_proxy_depopulate_bank_ring_info(icp_accel_dev_t *accel_dev) device_id = accel_dev->accelId; ICP_FREE(accel_dev->banks); ICP_FREE(ringInflights[device_id]); - - return; } void adf_proxy_depopulate_device_info(icp_accel_dev_t *accel_dev) { adf_proxy_depopulate_bank_ring_info(accel_dev); - return; } STATIC INLINE int adf_dev_bank_handle_get(adf_dev_bank_handle_t *bank) @@ -302,7 +298,6 @@ STATIC void adf_free_bundle(adf_dev_bank_handle_t *bank) ICP_FREE(bank->csr_addr_shadow); bank->csr_addr_shadow = NULL; } - return; } STATIC void adf_clean_bundle(adf_dev_bank_handle_t *bank) @@ -315,7 +310,6 @@ STATIC void adf_clean_bundle(adf_dev_bank_handle_t *bank) bank->bundle = NULL; bank->rings = NULL; } - return; } STATIC CpaStatus @@ -337,7 +331,6 @@ adf_populate_ring_info_internal(adf_dev_ring_handle_t *pRingHandle, Cpa32U in_flight_index = 0; pRingHandle->is_wireless = 0; - pRingHandle->is_dyn = 0; pRingHandle->ringResponseQuota = 0; pRingHandle->coal_write_count = 0; pRingHandle->csrTailOffset = 0; @@ -549,7 +542,7 @@ CpaStatus icp_adf_transCreateHandle(icp_accel_dev_t *accel_dev, adf_dev_bank_handle_t *bank = &banks[bank_nr]; int nodeid = accel_dev->numa_node; int ring_rnum = 0; - char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; + char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = { '\0' }; /* here init the bank: get a free bundle from UIO and mmap it * It's not suitable to put it into device init stage, @@ -706,7 +699,7 @@ CpaStatus icp_adf_transReinitHandle(icp_accel_dev_t *accel_dev, adf_dev_bank_handle_t *bank = &banks[bank_nr]; int nodeid = accel_dev->numa_node; int ring_rnum = 0; - char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES]; + char val[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = { '\0' }; pRingHandle = *trans_handle; @@ -928,10 +921,12 @@ CpaStatus icp_adf_transResetHandle(icp_comms_trans_handle trans_handle) adf_reset_ring(pRingHandle); if (NULL != pRingHandle->service_name) { - ICP_MEMSET( - pRingHandle->service_name, 0, strlen(pRingHandle->service_name)); - ICP_MEMSET( - pRingHandle->section_name, 0, strlen(pRingHandle->section_name)); + ICP_MEMSET(pRingHandle->service_name, + 0, + strnlen(pRingHandle->service_name, ICP_MAX_STR_LEN) + 1); + ICP_MEMSET(pRingHandle->section_name, + 0, + strnlen(pRingHandle->section_name, ICP_MAX_STR_LEN) + 1); } pbanks = accel_dev->banks; @@ -960,6 +955,7 @@ CpaStatus icp_adf_transGetRingNum(icp_comms_trans_handle trans_handle, ICP_CHECK_FOR_NULL_PARAM(trans_handle); pRingHandle = (adf_dev_ring_handle_t *)trans_handle; + ICP_CHECK_FOR_NULL_PARAM(pRingHandle->accel_dev); *ringNum = (pRingHandle->bank_num * pRingHandle->accel_dev->maxNumRingsPerBank) + pRingHandle->ring_num; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_dev_ring_ctl.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_dev_ring_ctl.h index 9148b1eb..1aa217dc 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_dev_ring_ctl.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_dev_ring_ctl.h @@ -92,7 +92,6 @@ typedef struct adf_dev_ring_handle_s uint32_t interrupt_user_mask; uint32_t pollingMask; uint32_t is_wireless : 1; - uint32_t is_dyn : 1; adf_dev_bank_handle_t *bank_data; /* userspace shadow values */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_transport_ctrl.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_transport_ctrl.h deleted file mode 100644 index ce8ae52c..00000000 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_transport_ctrl.h +++ /dev/null @@ -1,215 +0,0 @@ -/***************************************************************************** - * - * BSD LICENSE - * - * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - *****************************************************************************/ - -/***************************************************************************** - * @file adf_transport.h - * - * @description - * File contains simple interface for components to get - * a handle for appropriate transport type. - * - *****************************************************************************/ -#ifndef ADF_TRANSPORT_CTRL_H -#define ADF_TRANSPORT_CTRL_H - -#include "icp_adf_transport.h" - -/* Magic number used to indicated that this message is read, and the - * status is empty now - */ -#define EMPTY_RING_ENTRY_SIG (0x7F7F7F7F) - -/* - * Structure of a dyn instance handle - */ -typedef struct icp_dyn_instance_handle_s -{ - Cpa32U instance_id; - adf_service_type_t stype; - struct icp_dyn_instance_handle_s *pNext; - struct icp_dyn_instance_handle_s *pPrev; -} icp_dyn_instance_handle_t; - -/* - * Structure of a transport handle - */ -typedef struct icp_trans_handle_s -{ - /* Acceleration Handle for this transport */ - icp_accel_dev_t *accel_dev; - - /* Handle Identifier */ - icp_trans_identifier handle_id; - - /* Transport Type */ - icp_transport_type trans_type; - - /* Put a message onto the transport and wait for a response. - * Note: Not all transports support sync messages.*/ - - CpaStatus (*put_msg_sync)(struct icp_trans_handle_s *trans_handle, - Cpa32U *inBuf, - Cpa32U *outBuf, - Cpa32U buffsLen); - - /* Put a message onto the transport */ - CpaStatus (*put_msg)(struct icp_trans_handle_s *trans_handle, - Cpa32U *inBuf, - Cpa32U bufLen); - - /* register a callback for notification when something is available */ - CpaStatus (*reg_callback)(struct icp_trans_handle_s *trans_handle, - icp_trans_callback callback); - - /* notify handle to notify subscribed callbacks of messages */ - CpaStatus (*notify)(struct icp_trans_handle_s *trans_handle); - - /* notify handle for polling to notify subscribed callbacks of messages */ - CpaStatus (*polling_notify)(struct icp_trans_handle_s *trans_handle, - Cpa32U response_quota); - /* Transport specific data to ease processing */ - void *trans_data; - - CpaBoolean is_dyn; - - struct icp_trans_handle_s *pNext; - struct icp_trans_handle_s *pPrev; -} icp_trans_handle; - -/* - * Structure for dynamic instance resource management - */ -typedef struct adf_instancemgr_s -{ - Cpa32U serv_type; - ICP_MUTEX instance_lock; - Cpa32U max_instance; - Cpa32U *instances; - Cpa32U last_found; - Cpa32U avail; -} adf_instancemgr_t; - -/* - * Function Pointer for creating the transport handle - */ -typedef CpaStatus (*mgr_create_handle)(icp_accel_dev_t *accel_dev, - const char *section, - Cpa32U accel_nr, - Cpa32U bank_nr, - icp_trans_handle **trans_handle, - icp_adf_ringInfoService_t info, - const char *service_name, - const Cpa32U size, - const Cpa32U msg_size, - Cpa32U flags); - -/* - * Function Pointer for releasing the transport handle - */ -typedef CpaStatus (*mgr_release_handle)(icp_trans_handle *trans_handle); - -/* - * Function Pointer for finding an existing transport handle - */ -typedef CpaStatus (*mgr_find_handle)(icp_accel_dev_t *accel_dev, - icp_trans_identifier trans_id, - icp_trans_handle **trans_handle); - -/* - * Function Pointer for returning the ring number for a transport handle - */ -typedef CpaStatus (*mgr_get_ring_num)(icp_trans_handle *trans_handle, - Cpa32U *ringNum); -/* - * Struct representing a transport manager - */ -typedef struct icp_trans_mgr_s -{ - icp_transport_type trans_type; - mgr_create_handle create_handle; - mgr_release_handle release_handle; - mgr_find_handle find_handle; - mgr_get_ring_num get_ring_num; - void *privData; - struct icp_trans_mgr_s *pPrev; - struct icp_trans_mgr_s *pNext; -} icp_trans_mgr; - -/* - * Register the ring manager with the ring factory - */ -CpaStatus adf_trans_registerTransMgr(icp_trans_mgr *trans_mgr); - -/* - * Remove the ring manager from the ring factory - */ -CpaStatus adf_trans_deregisterTransMgr(icp_trans_mgr *trans_mgr); - -/* - * Initialize dynamic instance pool - */ -CpaStatus adf_trans_initDynInstancePool(icp_accel_dev_t *accel_dev, - Cpa32U crypto_num, - Cpa32U compress_num); - -/* - * Destroy dynamic instance pool - */ -CpaStatus adf_trans_destroyDynInstancePool(icp_accel_dev_t *accel_dev); - -/* - * Get an available dynamic instance from the dynamic instance pool - */ -CpaStatus adf_trans_getDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *pinstance_id); - -/* - * Put back a dynamic instance into the dynamic instance pool - */ -CpaStatus adf_trans_putDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U instance_id); - -/* - * Get the number of the available dynamic instances - * in the dynamic instance pool - */ -CpaStatus adf_trans_getNumAvailDynInstance(icp_accel_dev_t *accel_dev, - adf_service_type_t stype, - Cpa32U *num); - -#endif /* ADF_TRANSPORT_CTRL_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user.h index 931f0d6d..4da2dcea 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user.h @@ -33,9 +33,9 @@ * * ***************************************************************************/ -#ifndef UIO_USER_H +#ifndef ADF_USER_H -#define UIO_USER_H +#define ADF_USER_H #include "adf_io_bundles.h" @@ -148,4 +148,4 @@ int32_t adf_init_devices(void); CpaStatus adf_proxy_get_devices(void); int32_t adf_cleanup_devices(void); -#endif /* end of include guard: UIO_USER_H */ +#endif /* end of include guard: ADF_USER_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_arbiter.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_arbiter.h index 4190166e..617f7f7c 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_arbiter.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_arbiter.h @@ -41,8 +41,8 @@ * This file contains the arbiter related interfaces * *****************************************************************************/ -#ifndef ADF_UIO_USER_ARBITER_H -#define ADF_UIO_USER_ARBITER_H +#ifndef ADF_USER_ARBITER_H +#define ADF_USER_ARBITER_H #include #include @@ -80,4 +80,4 @@ static __inline__ void adf_update_ring_arb_enable(adf_dev_ring_handle_t *ring) #define adf_update_ring_arb_disable adf_update_ring_arb_enable -#endif /* ADF_UIO_USER_ARBITER_H */ +#endif /* ADF_USER_ARBITER_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_cfg.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_cfg.h index bf43d8a5..e0846200 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_cfg.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_cfg.h @@ -33,9 +33,8 @@ * * ***************************************************************************/ -#ifndef UIO_USER_CFG_H - -#define UIO_USER_CFG_H +#ifndef ADF_USER_CFG_H +#define ADF_USER_CFG_H #include "icp_accel_devices.h" @@ -45,5 +44,6 @@ CpaStatus icp_adf_cfgGetParamValue(icp_accel_dev_t *accel_dev, char *value); Cpa16U icp_adf_cfgGetBusAddress(Cpa16U accelId); Cpa32S icp_adf_cfgGetDomainAddress(Cpa16U accelId); +int icp_adf_cfgCheckUserSection(int dev_id, uint8_t *pSectionPresent); -#endif /* end of include guard: UIO_USER_CFG_H */ +#endif /* end of include guard: ADF_USER_CFG_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_ring.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_ring.h index b6ab8942..a2d1ddd1 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_ring.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_ring.h @@ -42,8 +42,8 @@ * *****************************************************************************/ -#ifndef ADF_UIO_USER_RING_H -#define ADF_UIO_USER_RING_H +#ifndef ADF_USER_RING_H +#define ADF_USER_RING_H #include @@ -66,13 +66,29 @@ void adf_cleanup_ring(adf_dev_ring_handle_t *ring); void adf_reset_ring(adf_dev_ring_handle_t *ring); int32_t adf_ring_freebuf(adf_dev_ring_handle_t *ring); -int32_t adf_user_put_msg(adf_dev_ring_handle_t *ring, - uint32_t *inBuf, - uint64_t *seq_num); +CpaStatus adf_user_put_msg(adf_dev_ring_handle_t *ring, + uint32_t *inBuf, + uint64_t *seq_num); + +/* + * adf_user_check_ring_error + * + * Description + * Function checks if the rp_exception or rp_halt bits are set in RINGSTAT + * register + * + * Return value + * -EINVAL if pRingHandle is NULL + * -EINTR if the rp_exception bit is set + * -EL2HLT if the rp_halt bit is set + * -EFAULT if the RINGSTAT rp_exception is not supported + * 0 if the rp_exception bit is not set + */ +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); -int32_t adf_user_notify_msgs(adf_dev_ring_handle_t *ring); -int32_t adf_user_notify_msgs_poll(adf_dev_ring_handle_t *ring); +CpaStatus adf_user_notify_msgs_poll(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); -#endif /* ADF_UIO_USER_RING_H */ +#endif /* ADF_USER_RING_H */ diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_transport.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_transport.h index 76743fff..c7be5798 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_transport.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/adf_user_transport.h @@ -45,45 +45,6 @@ #include "adf_dev_ring_ctl.h" -/* - * adf_user_put_msg - * - * Description - * Function puts the message onto the ring - */ -CpaStatus adf_user_put_msg(adf_dev_ring_handle_t *pRingHandle, - Cpa32U *inBuf, - uint64_t *seq_num); -/* - * adf_user_notify_msgs - * - * Description - * Function notifies client that there is response message - */ -CpaStatus adf_user_notify_msgs(adf_dev_ring_handle_t *pRingHandle); - -/* - * adf_user_check_ring_error - * - * Description - * Function checks if the rp_exception or rp_halt bits are set in RINGSTAT - * register - * - * Return value - * -EINTR if the rp_exception bit is set - * -EL2HLT if the rp_halt bit is set - * -EFAULT if the RINGSTAT rp_exception is not supported - * 0 if the rp_exception bit is not set - */ -int32_t adf_user_check_ring_error(adf_dev_ring_handle_t *pRingHandle); - -/* - * adf_user_notify_msgs_poll - * - * Description - * Function notifies client that there is response message on polling rings - */ -CpaStatus adf_user_notify_msgs_poll(adf_dev_ring_handle_t *pRingHandle); /* * adf_user_unmap_rings diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform.h index acc0fd5b..e0f46c23 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform.h @@ -263,21 +263,23 @@ } while (0) /* Logging macros */ +#ifndef QAT_XEN_PLATFORM extern char *icp_module_name; -#define xprintk(level, level_str, fmt, args...) \ - osalStdLog(level "%s %s: %s: " fmt, \ - icp_module_name, \ - level_str, \ - (__func__), \ - ##args) +#else +char *icp_module_name = "XEN"; +#endif + +#define xprintk(level, device, fmt, args...) \ + osalLog(level, device, "%s: %s: " fmt, icp_module_name, (__func__), ##args) #define ADF_PRINT(format, args...) printk(format, ##args) -#define ADF_ERROR(format, args...) xprintk(KERN_ERR, "err", format, ##args) +#define ADF_ERROR(format, args...) \ + xprintk(OSAL_LOG_LVL_ERROR, OSAL_LOG_DEV_STDERR, format, ##args) #ifdef _DEBUG_ #define ADF_DEBUG(format, args...) \ do \ { \ - xprintk(KERN_INFO, "debug", format, ##args); \ + xprintk(OSAL_LOG_LVL_DEBUG1, OSAL_LOG_DEV_STDOUT, format, ##args); \ } while (0) #else /*_DEBUG_*/ #define ADF_DEBUG(format, args...) \ @@ -311,7 +313,7 @@ extern char *icp_module_name; #define ICP_STRLCPY(dst, src, dstsize) \ ({ \ - if (((dst) != NULL) && ((src) != NULL) && ((dstsize) > 0)) \ + if ((dst != NULL) && (src != NULL) && (dstsize > 0)) \ snprintf(dst, dstsize, "%s", src); \ }) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform_user.h b/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform_user.h index 1c6ed205..635450a3 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform_user.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/common/include/icp_platform_user.h @@ -91,6 +91,10 @@ #define STATIC static #endif +#ifndef INLINE +#define INLINE inline +#endif + #define ICP_MMAP(addr, len, prot, flags, fd, offset) \ mmap(addr, len, prot, flags, fd, offset) #define ICP_MUNMAP(addr_v, len) munmap(addr_v, len) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_bundles.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_bundles.h index 1fa9d4b9..c0798ef6 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_bundles.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_bundles.h @@ -103,9 +103,31 @@ int adf_io_accel_dev_exist(int dev_id); * parameter. * @retval -ENOMEM The function failed allocating memory. * @retval -EINVAL The function failed due to an invalid dev_id. + * @retval -1 The function failed due to internal communication + * with external modules ie qatmgr. */ int adf_io_create_accel(icp_accel_dev_t **accel_dev, int dev_id); +/** + * @ingroup adf_io + * + * @description + * Checks if accelerator with given id exists and reinitialises *accel_dev + * with the parameters associated to the requested accelerator. + * + * @param[in,out] accel_dev Pointer to a pointer to an icp_accel_dev_t + * structure. In case of success *accel_dev is + * reinitialised with a icp_accel_dev_t structure + * content related to given accelerator + * + * @param[in] dev_id Id of the accelerator. + * + * @retval 0 The function executed successfully. + * An icp_accel_dev_t structure has been updated + * and returned through the accel_dev in-out + * parameter. + * @retval -EINVAL The function failed due to an invalid dev_id. + */ int adf_io_reinit_accel(icp_accel_dev_t **accel_dev, int dev_id); /** diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_cfg.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_cfg.h index 88589152..3215dcbb 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_cfg.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_cfg.h @@ -137,6 +137,21 @@ Cpa32S adf_io_cfgGetDomainAddress(Cpa16U accelId); */ Cpa16U adf_io_cfgGetBusAddress(Cpa16U accelId); +/** + * @ingroup adf_io + * + * @description + * This function checks if user process section + * exists in device cfg. + * + * @param[in] dev_id Id of the accelerator device to be checked. + * @param[out] pSectionPresent Pointer to the check result. + * @retval 0 Function executed successfully, the result is + * present in *pSectionPresent. + * @retval < 0 Function failed. + */ +int adf_io_cfgCheckUserSection(int dev_id, uint8_t *pSectionPresent); + /** * @ingroup adf_io * diff --git a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_user_proxy.h b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_user_proxy.h index c8c8211c..0eaf2ce2 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_user_proxy.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/include/adf_io_user_proxy.h @@ -87,6 +87,7 @@ CpaStatus adf_io_userProcessToStart(char const *const name_in, * @retval CPA_STATUS_SUCCESS Function executed successfully. * @retval CPA_STATUS_FAIL Function failed. * @retval CPA_STATUS_INVALID_PARAM Provided argument is invalid. + * @retval CPA_STATUS_RESOURCE Init mutex for process lock fails. */ CpaStatus adf_io_userProxyInit(char const *const name); @@ -115,7 +116,7 @@ void adf_io_userProxyShutdown(void); * This function is used to reset the data structures used by the * io specific layer of the ADF proxy in user space. * @retval CPA_STATUS_SUCCESS Function executed successfully. - * @retval CPA_STATUS_RESOURCE Function failed. + * @retval CPA_STATUS_RESOURCE Init mutex for process lock fails. */ CpaStatus adf_io_resetUserProxy(void); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_proto.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_proto.c index 3798ba2e..fc042cd1 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_proto.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_proto.c @@ -67,7 +67,7 @@ struct adf_pfvf_dev_data adf_init_pfvf_dev_data(void *pmiscbar_addr, int dev_id) { - struct adf_pfvf_dev_data dev = {0}; + struct adf_pfvf_dev_data dev = { 0 }; if (pmiscbar_addr == NULL) { @@ -157,7 +157,7 @@ int adf_send_vf2pf_msg(struct adf_pfvf_dev_data *dev, struct pfvf_message msg) struct pfvf_message adf_pfvf_gen4_recv(struct adf_pfvf_dev_data *dev) { uint32_t val; - struct pfvf_message msg = {0}; + struct pfvf_message msg = { 0 }; if (dev == NULL) { @@ -226,7 +226,7 @@ STATIC int adf_vf2pf_blkmsg_data_req(struct adf_pfvf_dev_data *dev, uint8_t *data, uint8_t is_crc) { - struct pfvf_message req = {0}; + struct pfvf_message req = { 0 }; struct pf2vf_blkmsg_resp resp; uint16_t max_payload_size; int err; @@ -334,12 +334,13 @@ static const unsigned char pfvf_crc8_table[] = { 0x14, 0x83, 0xAD, 0x3A, 0xF1, 0x66, 0x48, 0xDF, 0x10, 0x87, 0xA9, 0x3E, 0xF5, 0x62, 0x4C, 0xDB, 0x4D, 0xDA, 0xF4, 0x63, 0xA8, 0x3F, 0x11, 0x86, 0xAA, 0x3D, 0x13, 0x84, 0x4F, 0xD8, 0xF6, 0x61, 0xF7, 0x60, 0x4E, 0xD9, - 0x12, 0x85, 0xAB, 0x3C}; + 0x12, 0x85, 0xAB, 0x3C +}; 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) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_vf_msg.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_vf_msg.c index ae9858f5..b9811a02 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_vf_msg.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_pfvf_vf_msg.c @@ -41,22 +41,21 @@ #include "icp_platform.h" #include "qat_log.h" -#define VF2PF_MAYBE_AVAILABLE -1 +#define VF2PF_UNKNOWN -1 #define VF2PF_AVAILABLE 1 #define VF2PF_NOT_AVAILABLE 0 /* At the beginning we assume PF driver does not support PFVF. * If first init notification will be ACKed, VF2PF support will be marked as - * available. Any further error in communication will disabled it again */ -static int vf2pf_available = VF2PF_MAYBE_AVAILABLE; + * available. Any further error in communication will disable it again */ +static int vf2pf_available = VF2PF_UNKNOWN; STATIC void adf_set_vf2pf_available(int available) { /* VF2PF error at first attempt of communication, assuming PF driver has no * PFVF support */ - if (vf2pf_available == VF2PF_MAYBE_AVAILABLE && - available == VF2PF_NOT_AVAILABLE) + if (vf2pf_available == VF2PF_UNKNOWN && available == VF2PF_NOT_AVAILABLE) { qat_log(LOG_LEVEL_INFO, "PF has not support for PFVF\n"); } @@ -74,17 +73,16 @@ int adf_vf2pf_available() { if (vf2pf_available == VF2PF_NOT_AVAILABLE) { - qat_log( - LOG_LEVEL_INFO, - "VF2PF communication attempt, with no PFVF support on PF side\n"); + qat_log(LOG_LEVEL_INFO, "VF2PF is not available\n"); return 0; } return 1; } + int adf_vf2pf_notify_init(struct adf_pfvf_dev_data *dev) { - struct pfvf_message msg = {.type = ADF_VF2PF_MSGTYPE_INIT}; + struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_INIT }; ICP_CHECK_FOR_NULL_PARAM(dev); @@ -97,6 +95,7 @@ int adf_vf2pf_notify_init(struct adf_pfvf_dev_data *dev) adf_set_vf2pf_available(VF2PF_NOT_AVAILABLE); return -EFAULT; } + vf2pf_available = VF2PF_AVAILABLE; dev->pfvf_initialized = 1; return 0; } @@ -104,7 +103,7 @@ int adf_vf2pf_notify_init(struct adf_pfvf_dev_data *dev) void adf_vf2pf_notify_shutdown(struct adf_pfvf_dev_data *dev) { ICP_CHECK_FOR_NULL_PARAM_VOID(dev); - struct pfvf_message msg = {.type = ADF_VF2PF_MSGTYPE_SHUTDOWN}; + struct pfvf_message msg = { .type = ADF_VF2PF_MSGTYPE_SHUTDOWN }; if (!adf_vf2pf_available()) return; @@ -223,7 +222,7 @@ int adf_vf2pf_check_compat_version(struct adf_pfvf_dev_data *dev) int adf_vf2pf_get_ring_to_svc(struct adf_pfvf_dev_data *dev) { struct ring_to_svc_map_v1 rts_map_msg = { - {0}, + { 0 }, }; uint16_t len = sizeof(rts_map_msg); @@ -262,7 +261,7 @@ int adf_vf2pf_get_ring_to_svc(struct adf_pfvf_dev_data *dev) int adf_vf2pf_get_capabilities(struct adf_pfvf_dev_data *dev) { struct capabilities_v3 cap_msg = { - {0}, + { 0 }, }; uint16_t len = sizeof(cap_msg); int ret = 0; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_cfg.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_cfg.c index 9f0ed690..e116aa09 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_cfg.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_cfg.c @@ -57,8 +57,8 @@ CpaStatus adf_io_getNumDevices(unsigned int *num_devices) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; int ret; ICP_CHECK_FOR_NULL_PARAM(num_devices); @@ -433,7 +433,7 @@ CpaStatus adf_io_cfgGetParamValue(icp_accel_dev_t *accel_dev, const char *pParamName, char *pParamValue) { - struct qatmgr_msg_req req = {0}; + struct qatmgr_msg_req req = { 0 }; enum serv_type type; unsigned serv_num; Cpa16U msg_type; @@ -441,7 +441,7 @@ CpaStatus adf_io_cfgGetParamValue(icp_accel_dev_t *accel_dev, static __thread Cpa32U c_accelId = UINT32_MAX; static __thread enum serv_type c_serv_type; static __thread Cpa16U c_serv_num = UINT16_MAX; - static __thread struct qatmgr_msg_rsp rsp = {0}; + static __thread struct qatmgr_msg_rsp rsp = { 0 }; ICP_CHECK_FOR_NULL_PARAM(accel_dev); ICP_CHECK_FOR_NULL_PARAM(pSection); @@ -521,8 +521,8 @@ CpaStatus adf_io_cfgGetParamValue(icp_accel_dev_t *accel_dev, Cpa32S adf_io_cfgGetDomainAddress(Cpa16U accelId) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; unsigned node, b, d, f; req.device_num = accelId; @@ -542,10 +542,10 @@ Cpa32S adf_io_cfgGetDomainAddress(Cpa16U accelId) Cpa16U adf_io_cfgGetBusAddress(Cpa16U accelId) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; unsigned n, b, d, f; - unsigned bdf = 0; + unsigned bdf = ADF_IO_OPERATION_FAIL_CPA16U; req.device_num = accelId; if (qatmgr_query(&req, &rsp, QATMGR_MSGTYPE_DEVICE_ID)) @@ -570,6 +570,15 @@ CpaStatus adf_io_reset_device(Cpa32U accelId) { return CPA_STATUS_UNSUPPORTED; } +/* + * icp_adf_cfgCheckUserSection + * check if user process section exists in device cfg + */ +int adf_io_cfgCheckUserSection(int dev_id, uint8_t *pSectionPresent) +{ + *pSectionPresent = 1; + return 0; +} CpaBoolean adf_io_isDeviceAvailable(void) { diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_pf.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_pf.c index dbcb0c9f..bf6e7b92 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_pf.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_pf.c @@ -48,8 +48,10 @@ #include "qat_mgr.h" #include "qat_log.h" -#define DEVVFIO_DIR "/sys/bus/pci/drivers/4xxx" -#define DEVVFIO_DIR_420XX "/sys/bus/pci/drivers/420xx" +#define DEVVFIO_DIR "/sys/bus/pci/drivers" +#define DEVICE_NAME_LENGTH 5 + +char device_names[] = { "4xxx,420xx" }; static int filter_pf_in_use(const struct dirent *entry) { @@ -62,69 +64,95 @@ static int filter_pf_in_use(const struct dirent *entry) return 1; } -Cpa32S adf_vfio_init_pfs_info(icp_accel_pf_info_t *pf_info, size_t pf_info_len) +static int is_qat_dev_present(char *dev_name) { - unsigned node, bus, dev, func; + int i; + int status = CPA_STATUS_FAIL; struct dirent **namelist; - char *devvfio_dir; - int32_t i, number_of_pfs; - struct stat st = { 0 }; + int32_t number_of_dev; - ICP_CHECK_FOR_NULL_PARAM(pf_info); - - if (stat(DEVVFIO_DIR, &st) == 0) - { - number_of_pfs = - scandir(DEVVFIO_DIR, &namelist, &filter_pf_in_use, alphasort); - devvfio_dir = DEVVFIO_DIR; - } - else if (stat(DEVVFIO_DIR_420XX, &st) == 0) - { - number_of_pfs = - scandir(DEVVFIO_DIR_420XX, &namelist, &filter_pf_in_use, alphasort); - devvfio_dir = DEVVFIO_DIR_420XX; - } - else - { - /* This shows stat DIR failed, assume dir does not exist. */ - ADF_DEBUG("None of %s and %s paths exists in the system," - " unable to detect PFs\n", - DEVVFIO_DIR, - DEVVFIO_DIR_420XX); - return 0; - } + number_of_dev = scandir(DEVVFIO_DIR, &namelist, NULL, alphasort); - /* This shows scandir dir failed. */ - if (number_of_pfs < 0) + if (number_of_dev < 0) { - ADF_DEBUG("Failed to scan directory %s\n", devvfio_dir); - return CPA_STATUS_FAIL; + return status; } - if (pf_info_len < number_of_pfs) + for (i = 0; i < number_of_dev; i++) { - 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++) + if (strncmp(namelist[i]->d_name, dev_name, DEVICE_NAME_LENGTH) == 0) { - free(namelist[i]); + status = CPA_STATUS_SUCCESS; + break; } - free(namelist); - return CPA_STATUS_INVALID_PARAM; } - for (i = 0; i < number_of_pfs; i++) + for (i = 0; i < number_of_dev; i++) { - sscanf(namelist[i]->d_name, "%x:%x:%x.%x", &node, &bus, &dev, &func); - pf_info[i].pkg_id = i; - pf_info[i].domain = node; - pf_info[i].bdf = (node << 16) + ((0xFF & bus) << 8) + - ((0x1F & dev) << 3) + (0x07 & func); - strcpy(pf_info[i].device_gen, QAT_GEN4_STR); free(namelist[i]); } free(namelist); - return number_of_pfs; + return status; +} + +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; + int32_t i, number_of_pfs = 0, total_no_pfs = 0; + int status = CPA_STATUS_FAIL; + char dev_path[QATMGR_MAX_STRLEN] = { '\0' }; + char *device_name = strtok(device_names, ","); + + ICP_CHECK_FOR_NULL_PARAM(pf_info); + while (device_name != NULL) + { + status = is_qat_dev_present(device_name); + if (status == CPA_STATUS_SUCCESS) + { + snprintf( + dev_path, sizeof(dev_path), "%s/%s", DEVVFIO_DIR, device_name); + number_of_pfs = + scandir(dev_path, &namelist, &filter_pf_in_use, alphasort); + /* This shows scandir dir failed. */ + if (number_of_pfs < 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) + { + 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++) + { + free(namelist[i]); + } + free(namelist); + return CPA_STATUS_INVALID_PARAM; + } + for (i = 0; i < number_of_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 = + ((0xFF & bus) << 8) + ((0x1F & dev) << 3) + (0x07 & func); + strncpy( + pf_info[i].device_gen, device_name, ADF_DEVICE_TYPE_LENGTH); + free(namelist[i]); + } + free(namelist); + } + device_name = strtok(NULL, ","); /* Get the next device name */ + } + return total_no_pfs; } diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_bundles.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_bundles.c index 4fb8d52c..5387d717 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_bundles.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_bundles.c @@ -100,8 +100,8 @@ int adf_io_populate_bundle(icp_accel_dev_t *accel_dev, static int adf_vfio_populate_accel_dev(int dev_id, icp_accel_dev_t *accel_dev) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; int device_name_len; ICP_CHECK_FOR_NULL_PARAM(accel_dev); @@ -116,6 +116,9 @@ static int adf_vfio_populate_accel_dev(int dev_id, icp_accel_dev_t *accel_dev) accel_dev->accelId = rsp.device_info.device_num; accel_dev->maxNumBanks = rsp.device_info.max_banks; accel_dev->accelCapabilitiesMask = rsp.device_info.capability_mask; + accel_dev->cipherCapabilitiesMask = 0U; + accel_dev->hashCapabilitiesMask = 0U; + accel_dev->asymCapabilitiesMask = 0U; accel_dev->dcExtendedFeatures = rsp.device_info.extended_capabilities; accel_dev->numa_node = rsp.device_info.node_id; accel_dev->deviceType = rsp.device_info.device_type; @@ -131,14 +134,14 @@ static int adf_vfio_populate_accel_dev(int dev_id, icp_accel_dev_t *accel_dev) sizeof(rsp.device_info.device_name)); if (device_name_len < sizeof(accel_dev->deviceName)) { -#if defined(__GNUC__) && (__GNUC__ < 10) +#if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-truncation" #endif ICP_STRLCPY(accel_dev->deviceName, rsp.device_info.device_name, sizeof(accel_dev->deviceName)); -#if defined(__GNUC__) && (__GNUC__ < 10) +#if defined(__GNUC__) #pragma GCC diagnostic pop #endif } @@ -166,8 +169,8 @@ int get_vfio_fd(void) int adf_io_create_accel(icp_accel_dev_t **accel_dev, int dev_id) { CpaStatus status = CPA_STATUS_FAIL; - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; char vfio_file[QATMGR_MAX_STRLEN]; char device_id[QATMGR_MAX_STRLEN]; int ret; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_proxy.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_proxy.c index 74743a75..c11a0d76 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_proxy.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/adf_vfio_user_proxy.c @@ -108,8 +108,8 @@ CpaStatus adf_io_userProcessToStart(char const *const name_in, char *name, size_t name_len) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; int ret; ret = qatmgr_open(); @@ -156,8 +156,8 @@ CpaStatus adf_io_userProxyInit(char const *const name) void adf_io_userProcessStop(void) { - struct qatmgr_msg_req req = {0}; - struct qatmgr_msg_rsp rsp = {0}; + struct qatmgr_msg_req req = { 0 }; + struct qatmgr_msg_rsp rsp = { 0 }; assert(sizeof(req.name) == sizeof(currentProcess)); ICP_STRLCPY(req.name, currentProcess, sizeof(req.name)); @@ -167,8 +167,6 @@ void adf_io_userProcessStop(void) memset(currentProcess, 0, QATMGR_MAX_STRLEN); qatmgr_close(); - - return; } void adf_io_userProxyShutdown(void) diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr.h b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr.h index 00f738e4..1c10ce8d 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr.h +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr.h @@ -89,6 +89,29 @@ #define MAX_DEVS 512 +/* Below definitions are dependent on kernel drivers for creating the same + * mapping + */ +#define RING_PAIR_SHIFT 3 +#define SVC_MASK 0x7 +#define CFG_SERV_RING_PAIR_1_SHIFT 3 +#define CFG_SERV_RING_PAIR_2_SHIFT 6 +#define CFG_SERV_RING_PAIR_3_SHIFT 9 +#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) + +/* enum must be in alignment with the one defined by the kernel drivers */ +enum cfg_service_type +{ + UNUSED = 0, + CRYPTO, + COMP, + SYM, + ASYM, + USED +}; + enum serv_type { SERV_TYPE_DC = BIT(0), @@ -185,7 +208,7 @@ struct qatmgr_msg_rsp uint16_t max_rings_per_bank; uint16_t arb_mask; uint16_t services; - uint16_t pkg_id; + int16_t pkg_id; uint16_t node_id; uint16_t num_cy_instances; uint16_t num_dc_instances; @@ -240,7 +263,7 @@ struct qatmgr_device_data int device_type; uint16_t pci_id; /* PF index, describes which device it comes from */ - uint16_t pkg_id; + int16_t pkg_id; uint16_t services; /* This includes all cy insts whether asym-only, sym-only ro sym+asym */ int num_cy_inst; @@ -276,6 +299,14 @@ struct qatmgr_dev_data char vfio_file[32]; int group_fd; unsigned devid; + int numa_node; +}; + +struct qatmgr_cpu_data +{ + int idx; + int *cpu; + int cores_in_node; }; int qatmgr_query(struct qatmgr_msg_req *req, @@ -285,16 +316,14 @@ int qatmgr_open(void); int qatmgr_close(void); #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) -#define BDF_NODE(bdf) (bdf >> 16) +#define BDF_DOMAIN(bdf) (bdf >> 16) #define BDF_BUS(bdf) (bdf >> 8 & 0xFF) #define BDF_DEV(bdf) (bdf >> 3 & 0x1F) #define BDF_FUN(bdf) (bdf & 0x7) -/* This is the actual PF BDF. */ -#define BDF_PF(bdf) (bdf & 0xFFFFFF00) /* This is the PF BDF shifted >>8 and used as an index for hashing and for * capability caching. */ -#define PF(bdf) (BDF_BUS(bdf) + (BDF_NODE(bdf) << 8)) +#define PF(bdf) (BDF_BUS(bdf) + (BDF_DOMAIN(bdf) << 8)) void qat_mgr_cleanup_cfg(void); int qat_mgr_get_dev_list(unsigned *num_devices, diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_client.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_client.c index b17ff882..f707f2e8 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_client.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_client.c @@ -176,7 +176,7 @@ static int adf_vfio_build_sconfig() "Device %d, %X, %04x:%02x:%02x.%01x\n", i, dev_list[i].bdf, - BDF_NODE(dev_list[i].bdf), + BDF_DOMAIN(dev_list[i].bdf), BDF_BUS(dev_list[i].bdf), BDF_DEV(dev_list[i].bdf), BDF_FUN(dev_list[i].bdf)); diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_lib.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_lib.c index d29b1ef9..5d048b75 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_lib.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/qat_mgr_lib.c @@ -48,6 +48,8 @@ #include #include #include +#include + #include "adf_pfvf_vf_msg.h" #include "icp_accel_devices.h" #include "icp_platform.h" @@ -69,6 +71,16 @@ #define DEVICE_FILE IOMMUGROUP_DEV_DIR "%s/device" #define VENDOR_FILE IOMMUGROUP_DEV_DIR "%s/vendor" +#define NUMA_NODE IOMMUGROUP_DEV_DIR "%s/numa_node" + +#define SYSFS_VF_DIR "/sys/bus/pci/devices" + +#define SYSFS_VF_UEVENT "physfn/uevent" +#define PCI_DEV_SLOT_NAME "PCI_SLOT_NAME" + +/* clang-format off */ +#define PF_DEVICE_FORMAT PCI_DEV_SLOT_NAME"=%s" +/* clang-format on */ #define VFIO_ENTRY "vfio" #define PF_INFO_UNINITIALISED (-1) @@ -77,6 +89,10 @@ static struct qatmgr_section_data *section_data = NULL; static int num_section_data = 0; STATIC icp_accel_pf_info_t pf_data[ADF_MAX_PF_DEVICES] = { 0 }; STATIC int32_t num_pfs = PF_INFO_UNINITIALISED; +/* node_cpu_data contains available cpu ids for each node */ +static struct qatmgr_cpu_data *cpu_data = NULL; +static int num_nodes = 0; +static int num_cpus = 0; static pthread_mutex_t section_data_mutex; @@ -106,6 +122,7 @@ struct pf_capabilities uint32_t pf; uint32_t ext_dc_caps; uint32_t capabilities; + uint32_t ring_to_svc_map; struct pf_capabilities *next; }; @@ -148,46 +165,49 @@ static void cleanup_capabilities_cache() static int is_qat_device(int device_id) { - switch(device_id) { - case QAT_4XXXVF_DEVICE_ID: - case QAT_401XXVF_DEVICE_ID: - case QAT_402XXVF_DEVICE_ID: - case QAT_420XXVF_DEVICE_ID: - return 1; - default: - return 0; + switch (device_id) + { + case QAT_4XXXVF_DEVICE_ID: + case QAT_401XXVF_DEVICE_ID: + case QAT_402XXVF_DEVICE_ID: + case QAT_420XXVF_DEVICE_ID: + return 1; + default: + return 0; } return 0; } static int qat_device_type(int device_id) { - switch (device_id) { - case QAT_4XXXVF_DEVICE_ID: - case QAT_401XXVF_DEVICE_ID: - case QAT_402XXVF_DEVICE_ID: - return DEVICE_4XXXVF; - case QAT_420XXVF_DEVICE_ID: - return DEVICE_420XXVF; - default: - return 0; + switch (device_id) + { + case QAT_4XXXVF_DEVICE_ID: + case QAT_401XXVF_DEVICE_ID: + case QAT_402XXVF_DEVICE_ID: + return DEVICE_4XXXVF; + case QAT_420XXVF_DEVICE_ID: + return DEVICE_420XXVF; + default: + return 0; } return 0; } static char *qat_device_name(int device_id) { - switch (device_id) { - case QAT_4XXXVF_DEVICE_ID: - return "4xxxvf"; - case QAT_401XXVF_DEVICE_ID: - return "401xxvf"; - case QAT_402XXVF_DEVICE_ID: - return "402xxvf"; - case QAT_420XXVF_DEVICE_ID: - return "420xxvf"; - default: - return "unknown"; + switch (device_id) + { + case QAT_4XXXVF_DEVICE_ID: + return "4xxxvf"; + case QAT_401XXVF_DEVICE_ID: + return "401xxvf"; + case QAT_402XXVF_DEVICE_ID: + return "402xxvf"; + case QAT_420XXVF_DEVICE_ID: + return "420xxvf"; + default: + return "unknown"; } } @@ -212,6 +232,28 @@ int destroy_section_data_mutex() return 0; } +static void free_cpu_data() +{ + int i; + + if (cpu_data) + { + for (i = 0; i < num_nodes; i++) + { + if (cpu_data[i].cpu) + { + free(cpu_data[i].cpu); + cpu_data[i].cpu = NULL; + cpu_data[i].idx = 0; + cpu_data[i].cores_in_node = 0; + } + } + free(cpu_data); + cpu_data = NULL; + num_nodes = 0; + } +} + void qat_mgr_cleanup_cfg(void) { /* @@ -258,6 +300,8 @@ void qat_mgr_cleanup_cfg(void) num_section_data = 0; } + free_cpu_data(); + cleanup_capabilities_cache(); } @@ -359,8 +403,9 @@ int qat_mgr_get_dev_list(unsigned *num_devices, char devices_dir_name[256]; int vfiofile = -1; char *bdfname; - unsigned node, bus, dev, func; + unsigned domain, bus, dev, func; int found = 0; + int numa_node; if (!dev_list || !list_size || !num_devices) return -EINVAL; @@ -517,12 +562,12 @@ int qat_mgr_get_dev_list(unsigned *num_devices, /* Extract the BDF from the file name */ bdfname = basename(device_entry->d_name); - if (sscanf(bdfname, "%x:%x:%x.%x", &node, &bus, &dev, &func) != 4) + if (sscanf(bdfname, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) { qat_log(LOG_LEVEL_ERROR, "Failed to scan BDF string\n"); break; } - dev_list[num_devs].bdf = (node << 16) + ((0xFF & bus) << 8) + + dev_list[num_devs].bdf = (domain << 16) + ((0xFF & bus) << 8) + ((0x1F & dev) << 3) + (0x07 & func); if (snprintf(dev_list[num_devs].vfio_file, sizeof(dev_list[num_devs].vfio_file), @@ -542,6 +587,41 @@ int qat_mgr_get_dev_list(unsigned *num_devices, break; } + if (snprintf(filename, + sizeof(filename), + NUMA_NODE, + vfio_entry->d_name, + device_entry->d_name) >= sizeof(filename)) + { + qat_log(LOG_LEVEL_ERROR, "Filename truncated\n"); + break; + } + + sysfile_fd = open_file_with_link_check(filename, O_RDONLY); + if (sysfile_fd < 0) + break; + + sysfile = fdopen(sysfile_fd, "r"); + if (!sysfile) + { + qat_log(LOG_LEVEL_ERROR, "Failed to open %s\n", filename); + close(sysfile_fd); + break; + } + numa_node = 0; + if (fscanf(sysfile, "%d", &numa_node) != 1) + { + qat_log(LOG_LEVEL_ERROR, + "Failed to read numa node from %s\n", + filename); + } + fclose(sysfile); + /* numa_node may be reported as -1 on VM */ + if (numa_node < 0) + numa_node = 0; + + dev_list[num_devs].numa_node = numa_node; + found = 1; dev_list[num_devs].devid = device; @@ -582,7 +662,8 @@ static int qat_mgr_get_device_capabilities( int dev_id, bool *compatible, uint32_t *ext_dc_caps, - uint32_t *capabilities) + uint32_t *capabilities, + uint32_t *ring_to_svc_map) { int ret; vfio_dev_info_t vfio_dev; @@ -611,6 +692,15 @@ static int qat_mgr_get_device_capabilities( return ret; } + ret = adf_vf2pf_get_ring_to_svc(&vfio_dev.pfvf); + if (ret) + { + qat_log(LOG_LEVEL_ERROR, "Cannot query device ring to service map\n"); + close_vfio_dev(&vfio_dev); + device_data->group_fd = -1; + return ret; + } + ret = adf_vf2pf_get_capabilities(&vfio_dev.pfvf); if (ret) { @@ -622,6 +712,7 @@ static int qat_mgr_get_device_capabilities( *ext_dc_caps = vfio_dev.pfvf.ext_dc_caps; *capabilities = vfio_dev.pfvf.capabilities; + *ring_to_svc_map = vfio_dev.pfvf.ring_to_svc_map; close_vfio_dev(&vfio_dev); device_data->group_fd = -1; @@ -632,36 +723,68 @@ static int qat_mgr_get_device_capabilities( Calculate bank number for different device configurations. Note, this depends on corresponding mapping done by kernel driver. */ -static int calculate_bank_number(struct qatmgr_device_data *device, - enum serv_type instance_service, - int inst_idx) +static int calculate_bank_number(const enum cfg_service_type instance_service, + const int inst_idx, + const uint32_t ring_to_svc_map) { - switch (device->services) + int i, serv_type, serv_found = 0; + + /* Search for the matching service type in ring_to_svc_map */ + for (i = 0; i < INSTANCES_PER_DEVICE; i++) { - case SERV_TYPE_CY: - if (instance_service == SERV_TYPE_ASYM) - return (inst_idx % device->num_cy_inst) * 2; - else - return (inst_idx % device->num_cy_inst) * 2 + 1; - case SERV_TYPE_SYM: - return inst_idx % device->num_sym_inst; - case SERV_TYPE_ASYM: - return inst_idx % device->num_asym_inst; - case SERV_TYPE_DC: - return inst_idx % device->num_dc_inst; - case SERV_TYPE_ASYM_DC: - if (instance_service == SERV_TYPE_ASYM) - return (inst_idx % device->num_asym_inst) * 2 + 1; - else - return (inst_idx % device->num_dc_inst) * 2; - case SERV_TYPE_SYM_DC: - if (instance_service == SERV_TYPE_SYM) - return (inst_idx % device->num_sym_inst) * 2 + 1; - else - return (inst_idx % device->num_dc_inst) * 2; - default: - return inst_idx % INSTANCES_PER_DEVICE; + serv_type = (ring_to_svc_map >> (i * RING_PAIR_SHIFT)) & SVC_MASK; + if (instance_service == serv_type) + { + if (serv_found == inst_idx) + { + return i; + } + serv_found++; + } + } + + return -1; +} + +static uint16_t bdf_pf(const unsigned vf_bdf) +{ + uint16_t pf_bdf = 0; + unsigned int domain, bus, dev, func; + FILE *fp = NULL; + char dev_path[QATMGR_MAX_STRLEN] = { '\0' }; + char dev_info[QATMGR_MAX_STRLEN] = { '\0' }; + char pci_slot_name[DEVICE_NAME_SIZE] = { '\0' }; + + snprintf(dev_path, + sizeof(dev_path), + "%s/%04x:%02x:%02x.%1x/%s", + SYSFS_VF_DIR, + BDF_DOMAIN(vf_bdf), + BDF_BUS(vf_bdf), + BDF_DEV(vf_bdf), + BDF_FUN(vf_bdf), + SYSFS_VF_UEVENT); + + fp = fopen(dev_path, "r"); + if (fp == NULL) + { + qat_log( + LOG_LEVEL_ERROR, "Failed to open VF sysfs file : %s\n", dev_path); + return 0; + } + + while (fgets(dev_info, sizeof(dev_info), fp) != NULL) + { + if (strstr(dev_info, PCI_DEV_SLOT_NAME) != NULL) + { + sscanf(dev_info, PF_DEVICE_FORMAT, pci_slot_name); + sscanf(pci_slot_name, "%x:%x:%x.%x", &domain, &bus, &dev, &func); + pf_bdf = ((0xFF & bus) << 8) + ((0x1F & dev) << 3) + (0x07 & func); + break; + } } + fclose(fp); + return pf_bdf; } /** @@ -670,10 +793,11 @@ static int calculate_bank_number(struct qatmgr_device_data *device, * is empty (if qatlib is running inside VM) then assigns max value of pkg_id * and returns 0 */ -static int get_pkg_id(unsigned vf_bdf, uint16_t *vf_pkg_id) +static int get_pkg_id(unsigned vf_bdf, int32_t *vf_pkg_id) { - uint16_t pkg_id = 0; - uint16_t pf_bdf; + int32_t pkg_id = 0; + uint16_t pf_bdf = 0; + uint16_t domain; if (!num_pfs) { @@ -681,12 +805,15 @@ static int get_pkg_id(unsigned vf_bdf, uint16_t *vf_pkg_id) return 0; } - /* remove device and func */ - pf_bdf = BDF_PF(vf_bdf); + /* get PF BDF id using VF BDF id */ + pf_bdf = bdf_pf(vf_bdf); + if (!pf_bdf) + return -1; + domain = BDF_DOMAIN(vf_bdf); for (pkg_id = 0; pkg_id < num_pfs; pkg_id++) { - if (pf_data[pkg_id].bdf == pf_bdf) + if (pf_data[pkg_id].bdf == pf_bdf && pf_data[pkg_id].domain == domain) { *vf_pkg_id = pkg_id; return 0; @@ -696,6 +823,176 @@ static int get_pkg_id(unsigned vf_bdf, uint16_t *vf_pkg_id) return -1; } +static int init_cpu_node(int node) +{ + int i = 0; + for (i = 0; i < num_cpus; i++) + { + cpu_data[node].cpu[i] = i; + } + + cpu_data[node].cores_in_node = num_cpus; + cpu_data[node].idx = 0; + + return 0; +} + +static int init_cpu_node_numa(int node) +{ + int i = 0; + int j = 0; + int err = 0; + struct bitmask *cpus; + + cpus = numa_allocate_cpumask(); + if (!cpus) + { + return -1; + } + + err = numa_node_to_cpus(node, cpus); + if (err) + { + numa_bitmask_free(cpus); + return -1; + } + + for (i = 0; i < cpus->size; i++) + { + if (numa_bitmask_isbitset(cpus, i)) + { + cpu_data[node].cpu[j++] = i; + } + } + + cpu_data[node].cores_in_node = j; + cpu_data[node].idx = 0; + + numa_bitmask_free(cpus); + + return 0; +} + +static int init_cpu_node_data(int node) +{ + int ret; + + cpu_data[node].cpu = calloc(num_cpus, sizeof(int)); + + if (!cpu_data[node].cpu) + { + return -ENOMEM; + } + + if (num_nodes > 1) + { + ret = init_cpu_node_numa(node); + } + else + { + ret = init_cpu_node(node); + } + + return ret; +} + +/** + * Get next available cpu for given node. + */ +int get_core_affinity(int node) +{ + int cpu = 0; + int index = 0; + int cores_in_node = 0; + + index = cpu_data[node].idx; + cores_in_node = cpu_data[node].cores_in_node; + cpu = cpu_data[node].cpu[index]; + + cpu_data[node].idx = (index + 1) % cores_in_node; + + return cpu; +} + +static int init_cpu_data() +{ + int ret = 0; + int i; + + num_cpus = get_nprocs(); + + if (numa_available() < 0) + { + num_nodes = 1; + qat_log(LOG_LEVEL_DEBUG, "No NUMA nodes detected.\n"); + } + else + { + num_nodes = numa_max_node() + 1; + qat_log(LOG_LEVEL_DEBUG, "Detected %d NUMA nodes.\n", num_nodes); + } + + cpu_data = calloc(num_nodes, sizeof(struct qatmgr_cpu_data)); + if (!cpu_data) + { + qat_log(LOG_LEVEL_ERROR, "Unable to allocate cpu mapping data.\n"); + return -ENOMEM; + } + + for (i = 0; i < num_nodes; i++) + { + ret = init_cpu_node_data(i); + if (ret) + { + qat_log(LOG_LEVEL_ERROR, + "Unable to initialize cpu mapping data.\n"); + free_cpu_data(); + return -EAGAIN; + } + } + return 0; +} + +static int get_num_instances(struct qatmgr_device_data *device, + const unsigned devid, + const uint32_t ring_to_svc_map) +{ + int serv_type, i; + for (i = 0; i < INSTANCES_PER_DEVICE; i++) + { + serv_type = (ring_to_svc_map >> (i * RING_PAIR_SHIFT)) & SVC_MASK; + switch (serv_type) + { + case SYM: + if (device->accel_capabilities & + ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC) + device->num_sym_inst++; + break; + case ASYM: + if (device->accel_capabilities & + ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC) + device->num_asym_inst++; + break; + case COMP: + if (device->accel_capabilities & + ICP_ACCEL_CAPABILITIES_COMPRESSION) + device->num_dc_inst++; + break; + default: + return -1; + } + } + + + if (device->num_sym_inst == INSTANCES_PER_DEVICE || + device->num_asym_inst == INSTANCES_PER_DEVICE) + device->num_cy_inst = INSTANCES_PER_DEVICE; + else if (device->num_sym_inst == 2 || device->num_asym_inst == 2) + device->num_cy_inst = INSTANCES_PER_DEVICE / 2; + + return 0; +} + int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], const int num_vf_devices, int policy, @@ -709,14 +1006,13 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], int num_vf_groups; int vf_idx = 0; int num_vfs_this_section; - int num_procs; - int core = 0; int pf = 0; unsigned devid; char pf_str[10]; - ENTRY pf_entry = {pf_str, NULL}; - int pfs_per_vf_group[ADF_MAX_DEVICES] = {0}; + ENTRY pf_entry = { pf_str, NULL }; + int pfs_per_vf_group[ADF_MAX_DEVICES] = { 0 }; uint32_t ext_dc_caps, capabilities; + uint32_t ring_to_svc_map = DEFAULT_RING_TO_SRV_MAP; bool compatible; bool vm = false; int ret; @@ -724,13 +1020,11 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], int section_num_sym_inst = 0; int section_num_asym_inst = 0; int section_num_dc_inst = 0; - uint16_t vf_pkg_id = 0; + int32_t vf_pkg_id = 0; if (!num_vf_devices) return -EINVAL; - num_procs = get_nprocs(); - if (num_pfs == PF_INFO_UNINITIALISED) { num_pfs = adf_vfio_init_pfs_info(pf_data, @@ -750,6 +1044,13 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], "Unable to find pfs in the system, assuming " "qat_mgr_lib is running inside VM\n"); } + + ret = init_cpu_data(); + if (ret) + { + return ret; + } + /* * A VF group is a set of VFs with the same device/function * but from different PFs. @@ -765,6 +1066,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], if (hcreate(ADF_MAX_DEVICES) == 0) { qat_log(LOG_LEVEL_ERROR, "Error while creating hash table\n"); + free_cpu_data(); return -ENOMEM; } @@ -786,6 +1088,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], { qat_log(LOG_LEVEL_ERROR, "Error while creating hash table\n"); + free_cpu_data(); return -ENOMEM; } } @@ -795,6 +1098,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], if (hsearch(pf_entry, ENTER) == NULL) { qat_log(LOG_LEVEL_ERROR, "No space left in hash table\n"); + free_cpu_data(); return -ENOMEM; } } @@ -824,6 +1128,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], "available devices %d\n", policy, num_vf_devices); + free_cpu_data(); return -EINVAL; } qat_log(LOG_LEVEL_DEBUG, "num_section_data %d\n", num_section_data); @@ -839,6 +1144,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], "available devices %d\n", policy, num_vf_devices); + free_cpu_data(); return -EINVAL; } @@ -847,7 +1153,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], { qat_log(LOG_LEVEL_ERROR, "Malloc failed for section data\n"); num_section_data = 0; - qat_mgr_cleanup_cfg(); + free_cpu_data(); return -EAGAIN; } @@ -901,7 +1207,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], snprintf(device_data->device_id, sizeof(device_data->device_id), "%04x:%02x:%02x.%01x", - BDF_NODE(dev_list[vf_idx].bdf), + 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)); @@ -911,7 +1217,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], dev_list[vf_idx].vfio_file); device_data->group_fd = dev_list[vf_idx].group_fd; device_data->accelid = j; - device_data->node = BDF_NODE(dev_list[vf_idx].bdf); + device_data->node = dev_list[vf_idx].numa_node; if (get_pkg_id(dev_list[vf_idx].bdf, &vf_pkg_id)) { @@ -979,6 +1285,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], cached_capabilities->capabilities; device_data->extended_capabilities = cached_capabilities->ext_dc_caps; + ring_to_svc_map = cached_capabilities->ring_to_svc_map; } else if (adf_vf2pf_available()) { @@ -986,7 +1293,8 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], devid, &compatible, &ext_dc_caps, - &capabilities); + &capabilities, + &ring_to_svc_map); if (0 == ret) { device_data->accel_capabilities = capabilities; @@ -1014,6 +1322,7 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], cached_capabilities->pf = pf; cached_capabilities->capabilities = capabilities; cached_capabilities->ext_dc_caps = ext_dc_caps; + cached_capabilities->ring_to_svc_map = ring_to_svc_map; add_pf_capabilities(cached_capabilities); } } @@ -1056,61 +1365,12 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], /* populate configuration for a device * first determine num instances per device */ - switch (device_data->services) + ret = get_num_instances(device_data, devid, ring_to_svc_map); + if (ret) { - case SERV_TYPE_CY: { - qat_log(LOG_LEVEL_INFO, "Detected CY configuration\n"); - device_data->num_sym_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_asym_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_cy_inst = INSTANCES_PER_DEVICE / 2; - } - break; - - case SERV_TYPE_SYM: { - qat_log(LOG_LEVEL_INFO, "Detected SYM configuration\n"); - device_data->num_sym_inst = INSTANCES_PER_DEVICE; - device_data->num_cy_inst = - INSTANCES_PER_DEVICE; /* for SAL */ - } - break; - - case SERV_TYPE_ASYM: { - qat_log(LOG_LEVEL_INFO, "Detected ASYM configuration\n"); - device_data->num_asym_inst = INSTANCES_PER_DEVICE; - device_data->num_cy_inst = - INSTANCES_PER_DEVICE; /* for SAL */ - } - break; - - case SERV_TYPE_DC: { - qat_log(LOG_LEVEL_INFO, "Detected DC configuration\n"); - device_data->num_dc_inst = INSTANCES_PER_DEVICE; - } - break; - - case SERV_TYPE_ASYM_DC: { - qat_log(LOG_LEVEL_INFO, "Detected ASYM DC configuration\n"); - device_data->num_dc_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_asym_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_cy_inst = - INSTANCES_PER_DEVICE / 2; /* for SAL */ - } - break; - - case SERV_TYPE_SYM_DC: { - qat_log(LOG_LEVEL_INFO, "Detected SYM DC configuration\n"); - device_data->num_dc_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_sym_inst = INSTANCES_PER_DEVICE / 2; - device_data->num_cy_inst = - INSTANCES_PER_DEVICE / 2; /* for SAL */ - } - break; - - default: { - qat_log(LOG_LEVEL_ERROR, - "Detected unknown configuration\n"); - return -1; - } + qat_log(LOG_LEVEL_ERROR, "Detected unknown service\n"); + qat_mgr_cleanup_cfg(); + return -1; } if (device_data->num_dc_inst) @@ -1154,14 +1414,21 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], cy_inst->asym.accelid = device_data->accelid; cy_inst->asym.service_type = SERV_TYPE_ASYM; - cy_inst->asym.bank_number = calculate_bank_number( - device_data, cy_inst->asym.service_type, k); + cy_inst->asym.bank_number = + calculate_bank_number(ASYM, k, ring_to_svc_map); + if (cy_inst->asym.bank_number < 0) + { + qat_log(LOG_LEVEL_ERROR, + "Cannot find bank number for asym instance\n"); + qat_mgr_cleanup_cfg(); + return -1; + } cy_inst->asym.ring_tx = 0; cy_inst->asym.ring_rx = 1; cy_inst->asym.is_polled = 1; cy_inst->asym.num_concurrent_requests = 64; - cy_inst->asym.core_affinity = core; - core = (core + 1) % num_procs; + cy_inst->asym.core_affinity = + get_core_affinity(device_data->node); } cy_inst = device_data->cy_instance_data; @@ -1174,14 +1441,21 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], cy_inst->sym.accelid = device_data->accelid; cy_inst->sym.service_type = SERV_TYPE_SYM; - cy_inst->sym.bank_number = calculate_bank_number( - device_data, cy_inst->sym.service_type, k); + cy_inst->sym.bank_number = + calculate_bank_number(SYM, k, ring_to_svc_map); + if (cy_inst->sym.bank_number < 0) + { + qat_log(LOG_LEVEL_ERROR, + "Cannot find bank number for sym instance\n"); + qat_mgr_cleanup_cfg(); + return -1; + } cy_inst->sym.ring_tx = 0; cy_inst->sym.ring_rx = 1; cy_inst->sym.is_polled = 1; cy_inst->sym.num_concurrent_requests = 512; - cy_inst->sym.core_affinity = core; - core = (core + 1) % num_procs; + cy_inst->sym.core_affinity = + get_core_affinity(device_data->node); } dc_inst = device_data->dc_instance_data; @@ -1194,14 +1468,20 @@ int qat_mgr_build_data(const struct qatmgr_dev_data dev_list[], dc_inst->accelid = device_data->accelid; dc_inst->service_type = SERV_TYPE_DC; - dc_inst->bank_number = calculate_bank_number( - device_data, dc_inst->service_type, k); + dc_inst->bank_number = + calculate_bank_number(COMP, k, ring_to_svc_map); + if (dc_inst->bank_number < 0) + { + qat_log(LOG_LEVEL_ERROR, + "Cannot find bank number for dc instance\n"); + qat_mgr_cleanup_cfg(); + return -1; + } dc_inst->ring_tx = 0; dc_inst->ring_rx = 1; dc_inst->is_polled = 1; dc_inst->num_concurrent_requests = 512; - dc_inst->core_affinity = core; - core = (core + 1) % num_procs; + dc_inst->core_affinity = get_core_affinity(device_data->node); } } } @@ -1343,7 +1623,7 @@ static void dump_message(void *ptr, char *text) } printf("\n"); } - if (payload_size > MAX_PAYLOAD_SIZE) + else { qat_log( LOG_LEVEL_ERROR, @@ -1941,7 +2221,7 @@ static int get_section(pthread_t tid, char **derived_section_name) if (pthread_mutex_lock(§ion_data_mutex)) { qat_log(LOG_LEVEL_ERROR, "Unable to lock section_data mutex\n"); - return -1; + return -2; } for (i = 0; i < num_section_data; i++) @@ -1957,7 +2237,7 @@ static int get_section(pthread_t tid, char **derived_section_name) if (pthread_mutex_unlock(§ion_data_mutex)) { qat_log(LOG_LEVEL_ERROR, "Unable to unlock section_data mutex\n"); - return -1; + return -2; } if (assigned) @@ -2017,8 +2297,11 @@ static int handle_section_request(struct qatmgr_msg_req *req, if (sec < 0) { qat_log(LOG_LEVEL_ERROR, "Couldn't get section %s\n", req->name); - err_msg(rsp, "No section available"); - return -1; + if (sec == -2) + err_msg(rsp, "Internal error"); + else + err_msg(rsp, "No section available"); + return sec; } *index = sec; diff --git a/quickassist/lookaside/access_layer/src/qat_direct/vfio/vfio_lib.c b/quickassist/lookaside/access_layer/src/qat_direct/vfio/vfio_lib.c index ca001c33..185e54bd 100644 --- a/quickassist/lookaside/access_layer/src/qat_direct/vfio/vfio_lib.c +++ b/quickassist/lookaside/access_layer/src/qat_direct/vfio/vfio_lib.c @@ -155,8 +155,8 @@ int open_vfio_dev(const char *vfio_file, int already_enabled = 0; static pid_t pid = 0; - struct vfio_group_status group_status = {.argsz = sizeof(group_status)}; - struct vfio_device_info device_info = {.argsz = sizeof(device_info)}; + struct vfio_group_status group_status = { .argsz = sizeof(group_status) }; + struct vfio_device_info device_info = { .argsz = sizeof(device_info) }; ICP_CHECK_FOR_NULL_PARAM_RET_CODE(dev, -1); ICP_CHECK_FOR_NULL_PARAM_RET_CODE(vfio_file, -1); @@ -281,7 +281,7 @@ int open_vfio_dev(const char *vfio_file, for (i = 0; i < device_info.num_regions; i++) { - struct vfio_region_info reg = {.argsz = sizeof(reg)}; + struct vfio_region_info reg = { .argsz = sizeof(reg) }; reg.index = i; @@ -331,16 +331,6 @@ int open_vfio_dev(const char *vfio_file, return -1; } - /* Gratuitous device reset and go... */ - ret = ioctl(dev->vfio_dev_fd, VFIO_DEVICE_RESET); - if (ret) - { - ADF_ERROR("VFIO_DEVICE_RESET ioctl failed\n"); - close_vfio_dev(dev); - - return -1; - } - /* Init VF2PF communication */ dev->pfvf = adf_init_pfvf_dev_data(dev->pcs.bar[ADF_PMISC_BAR].ptr, pci_id); @@ -351,12 +341,19 @@ void close_vfio_dev(vfio_dev_info_t *dev) { int idx; pcs_t *pcs; + int ret = 0; ICP_CHECK_FOR_NULL_PARAM_VOID(dev); pcs = &dev->pcs; for (idx = pcs->nr_bar - 1; idx >= 0; idx--) - (void)munmap(pcs->bar[idx].ptr, pcs->bar[idx].size); + { + ret = munmap(pcs->bar[idx].ptr, pcs->bar[idx].size); + if (ret) + { + ADF_ERROR("close_vfio_dev : munmap error for idx = %d\n", idx); + } + } pcs->nr_bar = 0; pci_vfio_set_command(dev->vfio_dev_fd, PCI_COMMAND_MEMORY, false); diff --git a/quickassist/lookaside/access_layer/src/sample_code/busy_loop/busy_loop.c b/quickassist/lookaside/access_layer/src/sample_code/busy_loop/busy_loop.c index fce48db7..047a1fab 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/busy_loop/busy_loop.c +++ b/quickassist/lookaside/access_layer/src/sample_code/busy_loop/busy_loop.c @@ -97,6 +97,11 @@ unsigned int useCpuid = 1; uint32_t busyLoopCounter_g = 0; +void setUseCpuid(unsigned int a); +void testBusyLoop(uint32_t n); +void testBusyLoop2(uint32_t n); +void setBusyLoopCounter(uint32_t busyLoopCounter); + #ifdef USER_SPACE void __attribute__((noinline)) busyLoop(uint32_t n, volatile uint32_t *var) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/diffie_hellman_sample/cpa_dh_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/diffie_hellman_sample/cpa_dh_sample.c index 3f13c92a..68e46cd8 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/diffie_hellman_sample/cpa_dh_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/diffie_hellman_sample/cpa_dh_sample.c @@ -182,7 +182,7 @@ static CpaStatus sampleDhPerformOp(CpaInstanceHandle cyInstHandle) /* 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; + struct COMPLETION_STRUCT complete = { 0 }; void *pCallbackTagPh2 = (void *)&complete; /** Pointer that will contain the public value (returned by @@ -412,7 +412,7 @@ CpaStatus dhSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleAsymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/ec_montedwds_sample/cpa_ec_montedwds_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/ec_montedwds_sample/cpa_ec_montedwds_sample.c index 00e8039a..71895dc5 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/ec_montedwds_sample/cpa_ec_montedwds_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/ec_montedwds_sample/cpa_ec_montedwds_sample.c @@ -228,11 +228,13 @@ static CpaStatus ed448PointSamplePerform(CpaInstanceHandle cyInstHandle) status = OS_MALLOC(&pXk, sizeof(CpaFlatBuffer)); if (CPA_STATUS_SUCCESS == status) { + pXk->pData = NULL; + pXk->dataLenInBytes = dataLenInBytes; status = OS_MALLOC(&pYk, sizeof(CpaFlatBuffer)); } if (CPA_STATUS_SUCCESS == status) { - pXk->dataLenInBytes = dataLenInBytes; + pYk->pData = NULL; pYk->dataLenInBytes = dataLenInBytes; status = PHYS_CONTIG_ALLOC_ALIGNED( &pXk->pData, dataLenInBytes, BYTE_ALIGNMENT_64); @@ -368,11 +370,13 @@ static CpaStatus curve448GeneratorSamplePerform(CpaInstanceHandle cyInstHandle) status = OS_MALLOC(&pXk, sizeof(CpaFlatBuffer)); if (CPA_STATUS_SUCCESS == status) { + pXk->pData = NULL; + pXk->dataLenInBytes = dataLenInBytes; status = OS_MALLOC(&pYk, sizeof(CpaFlatBuffer)); } if (CPA_STATUS_SUCCESS == status) { - pXk->dataLenInBytes = dataLenInBytes; + pYk->pData = NULL; pYk->dataLenInBytes = dataLenInBytes; status = PHYS_CONTIG_ALLOC_ALIGNED( &pXk->pData, dataLenInBytes, BYTE_ALIGNMENT_64); @@ -494,11 +498,13 @@ static CpaStatus curve25519PointSamplePerform(CpaInstanceHandle cyInstHandle) status = OS_MALLOC(&pXk, sizeof(CpaFlatBuffer)); if (CPA_STATUS_SUCCESS == status) { + pXk->pData = NULL; + pXk->dataLenInBytes = dataLenInBytes; status = OS_MALLOC(&pYk, sizeof(CpaFlatBuffer)); } if (CPA_STATUS_SUCCESS == status) { - pXk->dataLenInBytes = dataLenInBytes; + pYk->pData = NULL; pYk->dataLenInBytes = dataLenInBytes; status = PHYS_CONTIG_ALLOC_ALIGNED( &pXk->pData, dataLenInBytes, BYTE_ALIGNMENT_64); @@ -611,7 +617,7 @@ CpaStatus ecMontEdwdsSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleAsymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.c index d042c3a2..6bb2b910 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/eddsa_sample/cpa_eddsa_sample.c @@ -210,14 +210,21 @@ static CpaStatus pointMuliplication(Cpa8U *pPointX, /* Allocate output flat buffers */ status = OS_MALLOC(&pGenX, sizeof(CpaFlatBuffer)); - status |= OS_MALLOC(&pGenY, sizeof(CpaFlatBuffer)); if (CPA_STATUS_SUCCESS != status) - PRINT_ERR("Memory alloc error\n"); + PRINT_ERR("Failed to allocate memory for pGenX\n"); else { - pGenY->dataLenInBytes = DATA_LEN; + pGenX->pData = NULL; pGenX->dataLenInBytes = DATA_LEN; } + status = OS_MALLOC(&pGenY, sizeof(CpaFlatBuffer)); + if (CPA_STATUS_SUCCESS != status) + PRINT_ERR("Failed to allocate memory for pGenY\n"); + else + { + pGenY->pData = NULL; + pGenY->dataLenInBytes = DATA_LEN; + } /* Alloc data for output buffers */ if (CPA_STATUS_SUCCESS == status) @@ -286,14 +293,23 @@ static CpaStatus pointMuliplication(Cpa8U *pPointX, } /* Free memory */ - PHYS_CONTIG_FREE(pOpData->x.pData); - PHYS_CONTIG_FREE(pOpData->y.pData); - PHYS_CONTIG_FREE(pOpData->k.pData); - PHYS_CONTIG_FREE(pGenX->pData); - PHYS_CONTIG_FREE(pGenY->pData); - OS_FREE(pOpData); - OS_FREE(pGenX); - OS_FREE(pGenY); + if (NULL != pOpData) + { + PHYS_CONTIG_FREE(pOpData->x.pData); + PHYS_CONTIG_FREE(pOpData->y.pData); + PHYS_CONTIG_FREE(pOpData->k.pData); + OS_FREE(pOpData); + } + if (NULL != pGenX) + { + PHYS_CONTIG_FREE(pGenX->pData); + OS_FREE(pGenX); + } + if (NULL != pGenY) + { + PHYS_CONTIG_FREE(pGenY->pData); + OS_FREE(pGenY); + } return status; } @@ -425,7 +441,7 @@ static CpaStatus edDsaSign(Cpa8U *privateKey, /* Copy data to buffer */ if (CPA_STATUS_SUCCESS == status) { - memcpy(dataToHash, prefix, DATA_LEN); + memmove(dataToHash, prefix, DATA_LEN); memcpy(dataToHash + DATA_LEN, PH_M, HASH_LEN); /* Alloc data for output */ @@ -707,7 +723,7 @@ CpaStatus ecMontEdwdsDsaSample(void) CpaStatus status = CPA_STATUS_FAIL; /* Get instance handle */ - sampleCyGetInstance(&cyInstHandle); + sampleAsymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample.c index d2050aa8..e993113c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/asym/prime_sample/cpa_prime_sample.c @@ -271,7 +271,7 @@ CpaStatus primeSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleAsymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; 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 6f749de1..980e3d3b 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 @@ -73,6 +73,7 @@ #include "cpa_sample_utils.h" #include "cpa_dc.h" +#include "cpa_cy_sym.h" #include "icp_sal_poll.h" /* @@ -106,41 +107,63 @@ CpaDcHuffType huffmanType_g = CPA_DC_HT_STATIC; * ************************************************************* */ +#ifdef DO_CRYPTO /* - * This function returns a handle to an instance of the cryptographic - * API. It does this by querying the API for all instances and - * returning the first such instance. + * 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. */ -// -#ifdef DO_CRYPTO -void sampleCyGetInstance(CpaInstanceHandle *pCyInstHandle) +static void sampleCryptoGetInstance(CpaAccelerationServiceType accelSrvType, + CpaInstanceHandle *pInstHandle) { - CpaInstanceHandle cyInstHandles[MAX_INSTANCES]; + CpaInstanceHandle instHandles[MAX_INSTANCES]; Cpa16U numInstances = 0; CpaStatus status = CPA_STATUS_SUCCESS; - *pCyInstHandle = NULL; - status = cpaCyGetNumInstances(&numInstances); - if (numInstances >= MAX_INSTANCES) + *pInstHandle = NULL; + status = cpaGetNumInstances(accelSrvType, &numInstances); + + 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 (numInstances > MAX_INSTANCES) { numInstances = MAX_INSTANCES; } - if ((status == CPA_STATUS_SUCCESS) && (numInstances > 0)) + if (0 == numInstances) + { + PRINT_ERR("No crypto instances found.\n"); + } + if (status == CPA_STATUS_SUCCESS) { - status = cpaCyGetInstances(numInstances, cyInstHandles); + status = cpaGetInstances(accelSrvType, numInstances, instHandles); if (status == CPA_STATUS_SUCCESS) - *pCyInstHandle = cyInstHandles[0]; + *pInstHandle = instHandles[0]; } - - if (0 == numInstances) + else { - PRINT_ERR("No instances found for 'SSL'\n"); - PRINT_ERR("Please check your section names"); - PRINT_ERR(" in the config file.\n"); - PRINT_ERR("Also make sure to use config file version 2.\n"); + PRINT_ERR("Error while getting a crypto instance.\n"); } } +void sampleSymGetInstance(CpaInstanceHandle *pSymInstHandle) +{ + sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_SYM, pSymInstHandle); +} + +void sampleAsymGetInstance(CpaInstanceHandle *pAsymInstHandle) +{ + sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, pAsymInstHandle); +} + +void sampleCyGetInstance(CpaInstanceHandle *pCyInstHandle) +{ + sampleCryptoGetInstance(CPA_ACC_SVC_TYPE_CRYPTO, pCyInstHandle); +} + void symSessionWaitForInflightReq(CpaCySymSessionCtx pSessionCtx) { @@ -157,7 +180,6 @@ void symSessionWaitForInflightReq(CpaCySymSessionCtx pSessionCtx) return; } #endif -// /* * This function polls a crypto instance. @@ -191,7 +213,8 @@ void sampleCyStartPolling(CpaInstanceHandle cyInstHandle) if ((status == CPA_STATUS_SUCCESS) && (info2.isPolled == CPA_TRUE)) { /* Start thread to poll instance */ - sampleThreadCreate(&gPollingThread, sal_polling, cyInstHandle); + sampleThreadCreate( + &gPollingThread, sal_polling, cyInstHandle, CPA_TRUE); } } #endif @@ -233,10 +256,7 @@ void sampleDcGetInstance(CpaInstanceHandle *pDcInstHandle) if (0 == numInstances) { - PRINT_ERR("No instances found for 'SSL'\n"); - PRINT_ERR("Please check your section names"); - PRINT_ERR(" in the config file.\n"); - PRINT_ERR("Also make sure to use config file version 2.\n"); + PRINT_ERR("No compression instances found.\n"); } } // @@ -271,7 +291,8 @@ void sampleDcStartPolling(CpaInstanceHandle dcInstHandle) if ((status == CPA_STATUS_SUCCESS) && (info2.isPolled == CPA_TRUE)) { /* Start thread to poll instance */ - sampleThreadCreate(&gPollingThreadDc, sal_dc_polling, dcInstHandle); + sampleThreadCreate( + &gPollingThreadDc, sal_dc_polling, dcInstHandle, CPA_TRUE); } } diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c index 43ce3caf..12ae6c1d 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/chaining_sample/cpa_chaining_sample.c @@ -269,6 +269,7 @@ static CpaStatus dcChainBuildBufferList(CpaBufferList **testBufferList, while (curBuff < numBuffers) { + pFlatBuff->pData = NULL; if (0 != bufferSize) { status = PHYS_CONTIG_ALLOC(&pMsg, bufferSize); @@ -281,10 +282,7 @@ static CpaStatus dcChainBuildBufferList(CpaBufferList **testBufferList, memset(pMsg, 0, bufferSize); pFlatBuff->pData = pMsg; } - else - { - pFlatBuff->pData = NULL; - } + pFlatBuff->dataLenInBytes = bufferSize; pFlatBuff++; curBuff++; @@ -351,7 +349,7 @@ static CpaStatus dcChainingPerformOp(CpaInstanceHandle dcInstHandle, CpaDcChainOperations operation = CPA_DC_CHAIN_HASH_THEN_COMPRESS; CpaCySymHashAlgorithm hashAlg = CPA_CY_SYM_HASH_SHA256; Cpa8U numSessions = NUM_SESSIONS_TWO; - struct COMPLETION_STRUCT complete; + struct COMPLETION_STRUCT complete = { 0 }; Cpa8U *pSWDigestBuffer = NULL; PRINT_DBG("cpaDcBufferListGetMetaSize\n"); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample.c index 3eab400e..908ba94b 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/dc_dp_sample/cpa_dc_dp_sample.c @@ -225,20 +225,21 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, { /* Allocate destination buffer the same size as source buffer but in an SGL with 1 buffer */ - bufferListMemSize = sizeof(CpaPhysBufferList) + dstBufferSize; + bufferListMemSize = + sizeof(CpaPhysBufferList) + sizeof(CpaPhysFlatBuffer); status = PHYS_CONTIG_ALLOC_ALIGNED(&pBufferListDst, bufferListMemSize, 8); } if (CPA_STATUS_SUCCESS == status) { - status = PHYS_CONTIG_ALLOC(&pDstBuffer, bufferSize); + status = PHYS_CONTIG_ALLOC(&pDstBuffer, dstBufferSize); } if (CPA_STATUS_SUCCESS == status) { /* Build destination bufferList */ pBufferListDst->numBuffers = 1; - pBufferListDst->flatBuffers[0].dataLenInBytes = bufferSize; + pBufferListDst->flatBuffers[0].dataLenInBytes = dstBufferSize; pBufferListDst->flatBuffers[0].bufferPhysAddr = virtAddrToDevAddr((SAMPLE_CODE_UINT *)(uintptr_t)pDstBuffer, dcInstHandle, @@ -581,11 +582,13 @@ CpaStatus dcDpSample(void) * Set the address translation function for the instance */ status = cpaDcSetAddressTranslation(dcInstHandle, sampleVirtToPhys); - - /* Start DataCompression component */ - PRINT_DBG("cpaDcStartInstance\n"); - status = - cpaDcStartInstance(dcInstHandle, numInterBuffLists, bufferInterArray); + if (CPA_STATUS_SUCCESS == status) + { + /* Start DataCompression component */ + PRINT_DBG("cpaDcStartInstance\n"); + status = cpaDcStartInstance( + dcInstHandle, numInterBuffLists, bufferInterArray); + } if (CPA_STATUS_SUCCESS == status) { diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_multi_op_checksum_sample/cpa_dc_stateless_multi_op_checksum_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_multi_op_checksum_sample/cpa_dc_stateless_multi_op_checksum_sample.c index 00dead91..e802c892 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_multi_op_checksum_sample/cpa_dc_stateless_multi_op_checksum_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_multi_op_checksum_sample/cpa_dc_stateless_multi_op_checksum_sample.c @@ -211,9 +211,9 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, CpaDcSessionSetupData sd) { CpaStatus status = CPA_STATUS_SUCCESS; - CpaBufferList bufferListSrcArray[NUM_SAMPLE_DATA_BUFFERS]; - CpaBufferList bufferListDstArray[NUM_SAMPLE_DATA_BUFFERS]; - CpaBufferList bufferListDstArray2[NUM_SAMPLE_DATA_BUFFERS]; + CpaBufferList bufferListSrcArray[NUM_SAMPLE_DATA_BUFFERS] = { 0 }; + CpaBufferList bufferListDstArray[NUM_SAMPLE_DATA_BUFFERS] = { 0 }; + CpaBufferList bufferListDstArray2[NUM_SAMPLE_DATA_BUFFERS] = { 0 }; Cpa32U srcBufferSize = SAMPLE_MAX_BUFF; Cpa32U dstBufferSize = srcBufferSize; Cpa32U numBuffers = NUM_SAMPLE_DATA_BUFFERS; @@ -224,7 +224,7 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, Cpa32U dataConsumed = 0; Cpa32U dataProduced = 0; Cpa32U checksum = 0; - struct COMPLETION_STRUCT complete; + struct COMPLETION_STRUCT complete = { 0 }; INIT_OPDATA(&opData, CPA_DC_FLUSH_FINAL); @@ -259,16 +259,19 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, { status = OS_MALLOC(&bufferListSrcArray[bufferNum].pBuffers, sizeof(CpaFlatBuffer)); + bufferListSrcArray[bufferNum].pBuffers->pData = NULL; } if (CPA_STATUS_SUCCESS == status) { status = OS_MALLOC(&bufferListDstArray[bufferNum].pBuffers, sizeof(CpaFlatBuffer)); + bufferListDstArray[bufferNum].pBuffers->pData = NULL; } if (CPA_STATUS_SUCCESS == status) { status = OS_MALLOC(&bufferListDstArray2[bufferNum].pBuffers, sizeof(CpaFlatBuffer)); + bufferListDstArray2[bufferNum].pBuffers->pData = NULL; } if (CPA_STATUS_SUCCESS == status) @@ -294,7 +297,8 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, PRINT_ERR( "cpaDcDeflateCompressBound API failed. (status = %d)\n", status); - return CPA_STATUS_FAIL; + status = CPA_STATUS_FAIL; + break; } } #endif @@ -524,13 +528,23 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, PHYS_CONTIG_FREE(bufferListDstArray[bufferNum].pPrivateMetaData); PHYS_CONTIG_FREE(bufferListDstArray2[bufferNum].pPrivateMetaData); - PHYS_CONTIG_FREE(bufferListSrcArray[bufferNum].pBuffers->pData); - PHYS_CONTIG_FREE(bufferListDstArray[bufferNum].pBuffers->pData); - PHYS_CONTIG_FREE(bufferListDstArray2[bufferNum].pBuffers->pData); + if (bufferListSrcArray[bufferNum].pBuffers != NULL) + { + PHYS_CONTIG_FREE(bufferListSrcArray[bufferNum].pBuffers->pData); + OS_FREE(bufferListSrcArray[bufferNum].pBuffers); + } - OS_FREE(bufferListSrcArray[bufferNum].pBuffers); - OS_FREE(bufferListDstArray[bufferNum].pBuffers); - OS_FREE(bufferListDstArray2[bufferNum].pBuffers); + if (bufferListDstArray[bufferNum].pBuffers != NULL) + { + PHYS_CONTIG_FREE(bufferListDstArray[bufferNum].pBuffers->pData); + OS_FREE(bufferListDstArray[bufferNum].pBuffers); + } + + if (bufferListDstArray2[bufferNum].pBuffers != NULL) + { + PHYS_CONTIG_FREE(bufferListDstArray2[bufferNum].pBuffers->pData); + OS_FREE(bufferListDstArray2[bufferNum].pBuffers); + } } COMPLETION_DESTROY(&complete); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_stateless_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_stateless_sample.c index e5e5043d..f49da952 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_stateless_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/dc/stateless_sample/cpa_dc_stateless_sample.c @@ -189,7 +189,7 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, * 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; + struct COMPLETION_STRUCT complete = { 0 }; INIT_OPDATA(&opData, CPA_DC_FLUSH_FINAL); PRINT_DBG("cpaDcBufferListGetMetaSize\n"); @@ -204,6 +204,10 @@ static CpaStatus compPerformOp(CpaInstanceHandle dcInstHandle, // status = cpaDcBufferListGetMetaSize(dcInstHandle, numBuffers, &bufferMetaSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaDcBufferListGetMetaSize failed. (status = %d)\n", status); + } /* Destination buffer size is set as sizeof(sampelData) for a * Deflate compression operation with DC_API_VERSION < 2.5. diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_utils.h b/quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_utils.h index 049c38d8..9b8f8fdb 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_utils.h +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/include/cpa_sample_utils.h @@ -535,7 +535,8 @@ static __inline CpaPhysicalAddr sampleVirtToPhys(void *virtAddr) static __inline CpaStatus sampleThreadCreate(sampleThread *thread, void *funct, - void *args) + void *args, + CpaBoolean thread_auto_detach) { #ifdef USER_SPACE if (pthread_create(thread, NULL, funct, args) != 0) @@ -543,11 +544,11 @@ static __inline CpaStatus sampleThreadCreate(sampleThread *thread, PRINT_ERR("Failed create thread\n"); return CPA_STATUS_FAIL; } - else + if (CPA_TRUE == thread_auto_detach) { pthread_detach(*thread); - return CPA_STATUS_SUCCESS; } + return CPA_STATUS_SUCCESS; #else *thread = kthread_create(funct, args, "SAMPLE_THREAD"); wake_up_process(*thread); @@ -555,6 +556,18 @@ static __inline CpaStatus sampleThreadCreate(sampleThread *thread, #endif } +static __inline CpaStatus sampleThreadJoin(sampleThread *thread) +{ +#ifdef USER_SPACE + if (pthread_join(*thread, NULL) != 0) + { + PRINT_ERR("Failed join thread\n"); + return CPA_STATUS_FAIL; + } +#endif + return CPA_STATUS_SUCCESS; +} + static __inline void sampleThreadExit(void) { #ifdef USER_SPACE @@ -563,6 +576,10 @@ static __inline void sampleThreadExit(void) } #ifdef DO_CRYPTO +void sampleAsymGetInstance(CpaInstanceHandle *pAsymInstHandle); + +void sampleSymGetInstance(CpaInstanceHandle *pSymInstHandle); + void sampleCyGetInstance(CpaInstanceHandle *pCyInstHandle); void sampleCyStartPolling(CpaInstanceHandle cyInstHandle); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/alg_chaining_sample/cpa_algchaining_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/alg_chaining_sample/cpa_algchaining_sample.c index f8ed949e..386149ea 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/alg_chaining_sample/cpa_algchaining_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/alg_chaining_sample/cpa_algchaining_sample.c @@ -172,7 +172,7 @@ static CpaStatus algChainPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -312,7 +312,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ccm_sample/cpa_ccm_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ccm_sample/cpa_ccm_sample.c index 8ce97156..dac76f22 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ccm_sample/cpa_ccm_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ccm_sample/cpa_ccm_sample.c @@ -178,7 +178,7 @@ static CpaStatus algChainPerformOpCCM(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -366,7 +366,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/cipher_sample/cpa_cipher_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/cipher_sample/cpa_cipher_sample.c index 37affa7b..243fe46a 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/cipher_sample/cpa_cipher_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/cipher_sample/cpa_cipher_sample.c @@ -173,7 +173,7 @@ static CpaStatus cipherPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -349,7 +349,7 @@ CpaStatus cipherSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/gcm_sample/cpa_gcm_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/gcm_sample/cpa_gcm_sample.c index 6d34c0e1..1bdece24 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/gcm_sample/cpa_gcm_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/gcm_sample/cpa_gcm_sample.c @@ -236,7 +236,7 @@ static CpaStatus algChainPerformOpGCM(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -426,7 +426,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; 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 7c5be51f..986f9980 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 @@ -143,7 +143,7 @@ static CpaStatus hashPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* Open file */ srcFile = fopen(gFileName, "r"); @@ -307,7 +307,7 @@ CpaStatus hashFileSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_sample/cpa_hash_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_sample/cpa_hash_sample.c index 42e0ffd6..7be08b2d 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_sample/cpa_hash_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hash_sample/cpa_hash_sample.c @@ -152,7 +152,7 @@ static CpaStatus hashPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -282,7 +282,7 @@ CpaStatus hashSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hkdf_sample/cpa_hkdf_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hkdf_sample/cpa_hkdf_sample.c index 691c4444..d0cfdd48 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hkdf_sample/cpa_hkdf_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/hkdf_sample/cpa_hkdf_sample.c @@ -164,6 +164,7 @@ static Cpa8U sampleIvExpected[] = {0xec, 0x63, 0xaa, 0x6d, 0x39, 0xc2, 0xb9, 0x94, 0x80, 0x3d, 0x24, 0xd9}; extern int gDebugParam; +CpaStatus hkdfSample(void); static void hkdfSampleCallback(void *pCallbackTag, CpaStatus status, @@ -228,7 +229,7 @@ static CpaStatus hkdfSampleExtractExpandLabelPerform( /* 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; + struct COMPLETION_STRUCT complete = { 0 }; CpaFlatBuffer hkdfOut; status = PHYS_CONTIG_ALLOC(&pHkdfData, hkdfDataSize); @@ -356,7 +357,7 @@ static CpaStatus hkdfSampleExtractExpandLabelSublabelsPerform( /* 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; + struct COMPLETION_STRUCT complete = { 0 }; CpaFlatBuffer hkdfOut; status = PHYS_CONTIG_ALLOC(&pHkdfData, hkdfDataSize); @@ -499,7 +500,7 @@ static CpaStatus hkdfSampleExtractExpandPerform(CpaInstanceHandle cyInstHandle) /* 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; + struct COMPLETION_STRUCT complete = { 0 }; CpaFlatBuffer hkdfOut; status = PHYS_CONTIG_ALLOC(&pHkdfData, hkdfDataSize); @@ -613,7 +614,7 @@ CpaStatus hkdfSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ipsec_sample/cpa_ipsec_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ipsec_sample/cpa_ipsec_sample.c index 81f14495..9335b44e 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ipsec_sample/cpa_ipsec_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ipsec_sample/cpa_ipsec_sample.c @@ -235,7 +235,7 @@ static CpaStatus algChainPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ status = @@ -429,7 +429,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { PRINT_DBG("No crypto instances available\n"); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ssl_sample/cpa_ssl_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ssl_sample/cpa_ssl_sample.c index df7feb42..e01a5717 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ssl_sample/cpa_ssl_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/ssl_sample/cpa_ssl_sample.c @@ -207,7 +207,7 @@ static CpaStatus algChainPerformOp(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ status = @@ -451,7 +451,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { PRINT_DBG("No crypto instances available\n"); diff --git a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/cpa_sym_dp_sample.c b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/cpa_sym_dp_sample.c index 3d9abf97..af8fb7f4 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/cpa_sym_dp_sample.c +++ b/quickassist/lookaside/access_layer/src/sample_code/functional/sym/symdp_sample/cpa_sym_dp_sample.c @@ -304,7 +304,7 @@ CpaStatus symDpSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { OS_FREE(info2); 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/cpa_zuc_sample.c index 3fdbd2b8..9e7895b8 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/cpa_zuc_sample.c @@ -183,7 +183,7 @@ static CpaStatus algChainPerformOpZUC(CpaInstanceHandle cyInstHandle, /* 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; + struct COMPLETION_STRUCT complete = { 0 }; /* get meta information size */ PRINT_DBG("cpaCyBufferListGetMetaSize\n"); @@ -349,7 +349,7 @@ CpaStatus algChainSample(void) * In this simplified version of instance discovery, we discover * exactly one instance of a crypto service. */ - sampleCyGetInstance(&cyInstHandle); + sampleSymGetInstance(&cyInstHandle); if (cyInstHandle == NULL) { return CPA_STATUS_FAIL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_utils.c b/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_utils.c index ba312aa4..77a371ac 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_utils.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/common/qat_perf_utils.c @@ -64,6 +64,7 @@ #include "cpa_sample_code_dc_perf.h" #include "cpa_sample_code_crypto_utils.h" #include "cpa_sample_code_dc_utils.h" +#include "qat_perf_latency.h" void qatPerfInitStats(perf_data_t *performanceStats, Cpa32U numLists, @@ -99,8 +100,7 @@ void qatPerfInitStats(perf_data_t *performanceStats, performanceStats->busyLoopResponses = 0; performanceStats->isIACycleCountProfiled = 0; performanceStats->response_process_time = 0; - performanceStats->start_times = 0; - performanceStats->response_times = 0; + qatFreeLatency(performanceStats); performanceStats->numLoops = numLoops; performanceStats->numOperations = (Cpa64U)numLists * (Cpa64U)numLoops; @@ -109,7 +109,7 @@ void qatPerfInitStats(perf_data_t *performanceStats, char *cpaStatusToString(CpaStatus status) { - char *retString = "NOT_SET"; + char *retString = NULL; switch (status) { 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 4a5cff62..cba5e740 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 @@ -100,6 +100,9 @@ extern volatile CpaBoolean backoff_dynamic_g; extern Cpa32U backoff_static_timer_g; static inline void printThreadDetails(single_thread_test_data_t *testSetup) __attribute__((unused)); +CpaStatus setDcPollingInterval(Cpa64U pollingInterval); +CpaStatus printDcPollingInterval(void); +void dcDpPerformance(single_thread_test_data_t *testSetup); /***************************************************************************** * @ingroup sampleCompressionDpPerf @@ -136,7 +139,7 @@ EXPORT_SYMBOL(printDcPollingInterval); * @description * Callback function after a call to the DC API ******************************************************************************/ -void dcDpCallbackFunction(CpaDcDpOpData *pOpData) +static void dcDpCallbackFunction(CpaDcDpOpData *pOpData) { CpaDcRqResults *pResults = &(pOpData->results); @@ -712,6 +715,8 @@ static CpaStatus performDcDpEnqueueOp(compression_test_params_t *setup, { PRINT_ERR("Failed to allocate memory for submission and response " "times\n"); + qaeMemFree((void **)&request_respnse_time); + qaeMemFree((void **)&request_submit_start); return CPA_STATUS_FAIL; } memset(request_submit_start, 0, request_mem_sz); @@ -1143,7 +1148,6 @@ static CpaStatus performOffloadCalculation(compression_test_params_t *setup, packetSize, pPerfData->endCyclesTimestamp - pPerfData->startCyclesTimestamp); - currentThroughput = baseThroughput; /* Find the lower bound(retries) and upper bound(no retries) for subsequent * binary search. @@ -2105,7 +2109,7 @@ EXPORT_SYMBOL(dcDpPerformance); * Check for Non Polling DC Instance. ******************************************************************************/ -CpaStatus checkDcNonPollingInstance(CpaBoolean *polled) +static CpaStatus checkDcNonPollingInstance(CpaBoolean *polled) { Cpa16U numInstances = 0; CpaInstanceHandle *instances = NULL; @@ -2311,7 +2315,6 @@ CpaStatus setupDcDpTest(CpaDcCompType algorithm, return CPA_STATUS_FAIL; } - numberOfBuffersPerFile = 0; } return status; 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 de1434b0..ec794768 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 @@ -493,6 +493,7 @@ CpaStatus setupDcLZ4Test(CpaDcCompType algorithm, Cpa32U numLoops); #endif + /** * ***************************************************************************** * @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 e607232a..42e1ad45 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 @@ -118,6 +118,16 @@ long dcPollingThreadsInterval_g = DEFAULT_POLL_INTERVAL_NSEC; EXPORT_SYMBOL(dcPollingThreadsInterval_g); CpaBoolean disableAdditionalCmpbufferSize_g = CPA_FALSE; EXPORT_SYMBOL(disableAdditionalCmpbufferSize_g); + +#if DC_API_VERSION_AT_LEAST(3, 1) +CpaStatus setLZ4BlockIndependence(CpaBoolean val); +#endif + +CpaStatus setTestOverFlow(CpaBoolean value); +CpaStatus setFuzzFile(const char *fileName); +CpaStatus printFuzzFile(void); + + #if DC_API_VERSION_AT_LEAST(3, 1) volatile CpaBoolean LZ4BlockIndependence_g = CPA_TRUE; CpaStatus setLZ4BlockIndependence(CpaBoolean val) @@ -142,6 +152,7 @@ CpaStatus setChecksum(CpaDcChecksum checksum) } EXPORT_SYMBOL(setChecksum); + CpaStatus setAutoSelectBestMode(CpaDcAutoSelectBest mode) { gAutoSelectBestMode = mode; @@ -334,29 +345,32 @@ static void freeDcBufferList(CpaBufferList **buffListArray, Cpa32U i = 0, j = 0; Cpa32U numberOfBuffers = 0; - i = numberOfBufferList; for (i = 0; i < numberOfBufferList; i++) { - numberOfBuffers = buffListArray[i]->numBuffers; - for (j = 0; j < numberOfBuffers; j++) + if (buffListArray[i] != NULL) { - if (buffListArray[i]->pBuffers[j].pData != NULL) + numberOfBuffers = buffListArray[i]->numBuffers; + if (buffListArray[i]->pBuffers != NULL) { - qaeMemFreeNUMA((void **)&buffListArray[i]->pBuffers[j].pData); - buffListArray[i]->pBuffers[j].pData = NULL; - } - } - if (buffListArray[i]->pBuffers != NULL) - { + for (j = 0; j < numberOfBuffers; j++) + { + if (buffListArray[i]->pBuffers[j].pData != NULL) + { + qaeMemFreeNUMA( + (void **)&buffListArray[i]->pBuffers[j].pData); + buffListArray[i]->pBuffers[j].pData = NULL; + } + } - qaeMemFreeNUMA((void **)&buffListArray[i]->pBuffers); - buffListArray[i]->pBuffers = NULL; - } + qaeMemFreeNUMA((void **)&buffListArray[i]->pBuffers); + buffListArray[i]->pBuffers = NULL; + } - if (buffListArray[i]->pPrivateMetaData != NULL) - { + if (buffListArray[i]->pPrivateMetaData != NULL) + { - qaeMemFreeNUMA((void **)&buffListArray[i]->pPrivateMetaData); + qaeMemFreeNUMA((void **)&buffListArray[i]->pPrivateMetaData); + } } } } @@ -1404,7 +1418,10 @@ CpaStatus dcPrintStats(thread_creation_data_t *data) * if the averageNumLoops does not equal the plan then that means * the thread exited early, so we need to use the average to calculate the * throughput*/ - do_div(averageNumLoops, data->numberOfThreads); + if (data->numberOfThreads != 0) + { + do_div(averageNumLoops, data->numberOfThreads); + } if (averageNumLoops != dcSetup->numLoops) { dcSetup->numLoops = averageNumLoops; @@ -1427,12 +1444,12 @@ CpaStatus dcPrintStats(thread_creation_data_t *data) } dcCalculateAndPrintCompressionRatio(bytesConsumed, bytesProduced); - if (iaCycleCount_g) + if (iaCycleCount_g && (data->numberOfThreads != 0)) { do_div(stats.offloadCycles, data->numberOfThreads); PRINT("Avg Offload Cycles %llu\n", stats.offloadCycles); } - if (latency_enable) + if (latency_enable && (data->numberOfThreads != 0)) { perf_cycles_t statsLatency = 0; perf_cycles_t cpuFreqKHz = sampleCodeGetCpuFreq(); @@ -1545,7 +1562,10 @@ CpaStatus dcChainPrintStats(thread_creation_data_t *data) * if the averageNumLoops does not equal the plan then that means * the thread exited early, so we need to use the average to calculate the * throughput*/ - do_div(averageNumLoops, data->numberOfThreads); + if (data->numberOfThreads != 0) + { + do_div(averageNumLoops, data->numberOfThreads); + } if (averageNumLoops != dcSetup->numLoops) { dcSetup->numLoops = averageNumLoops; @@ -1573,7 +1593,7 @@ CpaStatus dcChainPrintStats(thread_creation_data_t *data) } dcCalculateAndPrintCompressionRatio(bytesConsumed, bytesProduced); - if (latency_enable) + if (latency_enable && (data->numberOfThreads != 0)) { perf_cycles_t statsLatency = 0; perf_cycles_t cpuFreqKHz = sampleCodeGetCpuFreq(); 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 aba600af..a51eb5a9 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 @@ -130,6 +130,12 @@ extern volatile CpaBoolean LZ4BlockIndependence_g; void dcPerformCallback(void *pCallbackTag, CpaStatus status); void dcReadPerformCallback(void *pCallbackTag, CpaStatus status); +CpaStatus setAutoSelectBestMode(CpaDcAutoSelectBest mode); +CpaStatus disableAdditionalCmpbufferSize(CpaBoolean value); +CpaStatus compareBuffers2(CpaBufferList ***ppSrc, + CpaBufferList ***ppDst, + CpaBufferList ***ppComp, + compression_test_params_t *setup); /* corpus Data structure */ extern CpaBoolean useZlib_g; extern Cpa32U expansionFactor_g; 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 97b80714..d85606b9 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 @@ -826,7 +826,6 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) fileArray[setup->corpusFileIndex].corpusBinaryDataLen, testBufferSize); } - /* Initialize the compression session to use */ if (CPA_STATUS_SUCCESS == status) { @@ -950,14 +949,18 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) } for (listNum = 0; listNum < setup->numLists; listNum++) { - status = calcSWDigest( - srcBufferListArray[listNum].pBuffers, - pSWDigestBuffer, - setup->symSetupData.hashSetupData.hashAlgorithm); - if (CPA_STATUS_SUCCESS != status) { - PRINT_ERR("calcSWDigest returned status %d\n", - status); + status = calcSWDigest( + srcBufferListArray[listNum].pBuffers, + pSWDigestBuffer, + setup->symSetupData.hashSetupData + .hashAlgorithm); + + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("calcSWDigest returned status %d\n", + status); + } } if (CPA_STATUS_SUCCESS == status) { @@ -994,12 +997,18 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) destBufferListArray, testBufferSize, CPA_FALSE); + QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( + "qatCompressResetBufferList resets de-compression " + "bufferlist", + status); status = qatCompressResetBufferList(setup, cmpBufferListArray, testBufferSize, CPA_TRUE); QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( - "qatCompressResetBufferList", status); + "qatCompressResetBufferList resets compression " + "bufferlist", + status); } for (listNum = 0; listNum < setup->numLists; listNum++) { @@ -1018,7 +1027,13 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) .pBuffers->dataLenInBytes, &resultArray[listNum], &softChecksum); - + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "checkCrc32Checksum returned status %d " + "for CPA_DC_CRC32 checksum\n", + status); + } break; case CPA_DC_ADLER32: @@ -1030,7 +1045,13 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) .pBuffers->dataLenInBytes, &resultArray[listNum], &softChecksum); - + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "checkAdler32Checksum returned status " + "%d for CPA_DC_ADLER32 checksum\n", + status); + } break; case CPA_DC_CRC32_ADLER32: @@ -1042,6 +1063,13 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) .pBuffers->dataLenInBytes, &resultArray[listNum], &softChecksum); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR( + "checkCrc32Checksum returned status %d " + "for CPA_DC_CRC32_ADLER32 checksum\n", + status); + } softChecksum = 1; status = checkAdler32Checksum( @@ -1050,7 +1078,13 @@ CpaStatus qatDcChainPerform(compression_test_params_t *setup) .pBuffers->dataLenInBytes, &resultArray[listNum], &softChecksum); - + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("checkAdler32Checksum returned " + "status %d for " + "CPA_DC_CRC32_ADLER32 checksum\n", + status); + } break; #if DC_API_VERSION_AT_LEAST(3, 0) default: diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_e2e.c b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_e2e.c index 11bb6756..048a5ae3 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_e2e.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/compression/qat_compression_e2e.c @@ -63,6 +63,7 @@ #include "qat_compression_main.h" #include "cpa_sample_code_dc_perf.h" #include "qat_perf_utils.h" +#include "qat_compression_e2e.h" #ifdef KERNEL_SPACE #include 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 222c19b3..d620247d 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 @@ -110,6 +110,15 @@ static CpaStatus setupDcCommonTest(compression_test_params_t *dcSetup, corpus_type_t corpusType, sync_mode_t syncFlag, Cpa32U numLoops); +CpaStatus qatDcSubmitRequest(compression_test_params_t *setup, + const CpaInstanceInfo2 *pInstanceInfo2, + CpaDcSessionDir compressDirection, + CpaDcSessionHandle pSessionHandle, + CpaBufferList *arrayOfSrcBufferLists, + CpaBufferList *arrayOfDestBufferLists, + CpaBufferList *arrayOfCmpBufferLists, + Cpa32U listNum, + CpaDcRqResults *arrayOfResults); #if DC_API_VERSION_AT_LEAST(3, 1) CpaStatus setupDcLZ4Test(CpaDcCompType algorithm, @@ -149,6 +158,7 @@ CpaStatus setupDcLZ4Test(CpaDcCompType algorithm, EXPORT_SYMBOL(setupDcLZ4Test); #endif + /*register a test with the sample code framework*/ CpaStatus setupDcTest(CpaDcCompType algorithm, CpaDcSessionDir direction, @@ -833,12 +843,18 @@ CpaStatus qatDcPerform(compression_test_params_t *setup) destBufferListArray, testBufferSize, CPA_FALSE); + QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( + "qatCompressResetBufferList resets de-compression " + "bufferlist", + status); status = qatCompressResetBufferList(setup, cmpBufferListArray, testBufferSize, CPA_TRUE); QAT_PERF_PRINT_ERR_FOR_NON_SUCCESS_STATUS( - "qatCompressResetBufferList", status); + "qatCompressResetBufferList resets compression " + "bufferlist", + status); } } if (CPA_STATUS_SUCCESS != status) @@ -1714,8 +1730,21 @@ static CpaStatus qatInduceOverflow(compression_test_params_t *setup, destBufferListArray, setup->packetSizeInBytesArray, CPA_FALSE); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("qatCompressResetBufferList failed to reset " + "de-compression bufferlist. (status = %d)\n", + status); + } status = qatCompressResetBufferList( setup, cmpBufferListArray, setup->packetSizeInBytesArray, CPA_TRUE); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("qatCompressResetBufferList failed to reset compression " + "bufferlist. (status = %d)\n", + status); + } + if (stopTestsIsEnabled_g == CPA_TRUE && exitLoopFlag_g == CPA_TRUE) { break; 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 2d24b0da..2d4cb11e 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 @@ -412,6 +412,8 @@ CpaStatus qatCompressionSessionTeardown( CpaDcSessionHandle *pSessionHandle, CpaDcSessionHandle *pDecompressSessionHandle); +#ifdef USER_SPACE +#ifdef SC_CHAINING_ENABLED /** ***************************************************************************** * @file qat_compression_main.h @@ -476,6 +478,9 @@ CpaStatus qatDcChainSessionTeardown( CpaDcSessionHandle *pSessionHandle, CpaDcSessionHandle *pDecompressSessionHandle); +#endif +#endif + /** ***************************************************************************** * @file qat_compression_main.h 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 bbbab5f9..12196c15 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 @@ -69,6 +69,11 @@ #include "qat_perf_cycles.h" #include "qat_compression_zlib.h" + +CpaStatus qatFreeCompressionFlatBuffer(compression_test_params_t *setup, + CpaBufferList *bufferListArray); + + CpaStatus qatGetCompressBoundDestinationBufferSize( compression_test_params_t *setup, Cpa32U dcInputBufferSize, @@ -77,32 +82,34 @@ CpaStatus qatGetCompressBoundDestinationBufferSize( CpaStatus status = CPA_STATUS_SUCCESS; QAT_PERF_CHECK_NULL_POINTER_AND_UPDATE_STATUS(dcDestBufferSize, status); - if (setup->setupData.compType == CPA_DC_DEFLATE) { + if (setup->setupData.compType == CPA_DC_DEFLATE) + { - status = cpaDcDeflateCompressBound(setup->dcInstanceHandle, - setup->setupData.huffType, - dcInputBufferSize, - dcDestBufferSize); - } + status = cpaDcDeflateCompressBound(setup->dcInstanceHandle, + setup->setupData.huffType, + dcInputBufferSize, + dcDestBufferSize); + } #if DC_API_VERSION_AT_LEAST(3, 1) - else if (setup->setupData.compType == CPA_DC_LZ4) - { - status = cpaDcLZ4CompressBound( - setup->dcInstanceHandle, dcInputBufferSize, dcDestBufferSize); - } - else if (setup->setupData.compType == CPA_DC_LZ4S) - { - status = cpaDcLZ4SCompressBound( - setup->dcInstanceHandle, dcInputBufferSize, dcDestBufferSize); - } + else if (setup->setupData.compType == CPA_DC_LZ4) + { + status = cpaDcLZ4CompressBound( + setup->dcInstanceHandle, dcInputBufferSize, dcDestBufferSize); + } + else if (setup->setupData.compType == CPA_DC_LZ4S) + { + status = cpaDcLZ4SCompressBound( + setup->dcInstanceHandle, dcInputBufferSize, dcDestBufferSize); + } #endif - else - { - PRINT_ERR("%s : Unsupported Compression Type %d\n", - __func__, - setup->setupData.compType); - status = CPA_STATUS_FAIL; + else + { + PRINT_ERR("%s : Unsupported Compression Type %d\n", + __func__, + setup->setupData.compType); + status = CPA_STATUS_FAIL; + } } if (status == CPA_STATUS_SUCCESS) @@ -478,7 +485,7 @@ CpaStatus qatAllocateCompressionFlatBuffers( return status; } -CpaStatus qatAllocateCompressionFlatBuffer( +static CpaStatus qatAllocateCompressionFlatBuffer( compression_test_params_t *setup, CpaBufferList *bufferList, Cpa32U numBuffersInList, /*affects the metaSize of CpaBufferList*/ @@ -1046,11 +1053,11 @@ CpaStatus qatSwCompress(compression_test_params_t *setup, return status; } -CpaStatus qatHandleUnconsumedData(compression_test_params_t *setup, - CpaBufferList *bufferListArray, - Cpa32U listNum, - Cpa32U offset, - Cpa32U remainder) +static CpaStatus qatHandleUnconsumedData(compression_test_params_t *setup, + CpaBufferList *bufferListArray, + Cpa32U listNum, + Cpa32U offset, + Cpa32U remainder) { CpaFlatBuffer tempFB; CpaStatus status = CPA_STATUS_SUCCESS; @@ -1485,6 +1492,7 @@ static CpaStatus qatSwZlibDecompress(compression_test_params_t *setup, } + CpaStatus qatSwDecompress(compression_test_params_t *setup, CpaBufferList *destBuffListArray, CpaBufferList *cmpBuffListArray, @@ -1530,54 +1538,58 @@ CpaStatus qatSwChainDecompress(compression_test_params_t *setup, if (CPA_STATUS_SUCCESS == status) { - for (j = 0; j < setup->numLists; j++) - { - /* For stateful session setup stream once for all the buffers - * For stateless session stream is initialized for every packet - */ - if (setup->setupData.sessState != CPA_DC_STATEFUL || j == 0) - { - inflate_init(&stream, setup->setupData.sessState); - } - status = inflate_decompress( - &stream, - destBuffListArray[j].pBuffers->pData, - cmpResults[j].produced, - cmpBufferListArray[j].pBuffers->pData, - cmpBufferListArray[j].pBuffers->dataLenInBytes, - setup->setupData.sessState); - if (CPA_STATUS_SUCCESS != status) - { - PRINT("%02x%02x%02x%02x\n", - destBuffListArray[j].pBuffers->pData[0], - destBuffListArray[j].pBuffers->pData[1], - destBuffListArray[j].pBuffers->pData[2], - destBuffListArray[j].pBuffers->pData[3]); - PRINT_ERR("j: %d, srcLen: %d, destLen: %d \n", - j, - destBuffListArray[j].pBuffers->dataLenInBytes, - cmpBufferListArray[j].pBuffers->dataLenInBytes); - qatCompressDumpToFile( - setup, destBuffListArray, "destBuffer", "destBuffSize", 0); - 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*/ - 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. - */ - if (setup->setupData.sessState != CPA_DC_STATEFUL || - j == (setup->numLists - 1)) + for (j = 0; j < setup->numLists; j++) { - inflate_destroy(&stream); + /* For stateful session setup stream once for all the buffers + * For stateless session stream is initialized for every packet + */ + if (setup->setupData.sessState != CPA_DC_STATEFUL || j == 0) + { + inflate_init(&stream, setup->setupData.sessState); + } + status = inflate_decompress( + &stream, + destBuffListArray[j].pBuffers->pData, + cmpResults[j].produced, + cmpBufferListArray[j].pBuffers->pData, + cmpBufferListArray[j].pBuffers->dataLenInBytes, + setup->setupData.sessState); + if (CPA_STATUS_SUCCESS != status) + { + PRINT("%02x%02x%02x%02x\n", + destBuffListArray[j].pBuffers->pData[0], + destBuffListArray[j].pBuffers->pData[1], + destBuffListArray[j].pBuffers->pData[2], + destBuffListArray[j].pBuffers->pData[3]); + PRINT_ERR("j: %d, srcLen: %d, destLen: %d \n", + j, + destBuffListArray[j].pBuffers->dataLenInBytes, + cmpBufferListArray[j].pBuffers->dataLenInBytes); + qatCompressDumpToFile(setup, + destBuffListArray, + "destBuffer", + "destBuffSize", + 0); + 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*/ + 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. + */ + if (setup->setupData.sessState != CPA_DC_STATEFUL || + j == (setup->numLists - 1)) + { + inflate_destroy(&stream); + } } - } } return status; } @@ -1890,7 +1902,7 @@ CpaStatus performDcChainOffloadCalculationBusyLoop( packetSize, pPerfData->endCyclesTimestamp - pPerfData->startCyclesTimestamp); - currentThroughput = baseThroughput; + /* Find the lower bound(retries) and upper bound(no retries) for subsequent * binary search. */ @@ -2000,7 +2012,6 @@ CpaStatus performOffloadCalculationBusyLoop( packetSize, pPerfData->endCyclesTimestamp - pPerfData->startCyclesTimestamp); - currentThroughput = baseThroughput; /* Find the lower bound(retries) and upper bound(no retries) for subsequent * binary search. */ 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 61b501cf..d08a82e6 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 @@ -231,6 +231,7 @@ Cpa8U singleInstRequired_g = 0; extern Cpa32U packageIdCount_g; extern CpaBoolean devicesCounted_g; + #ifdef USER_SPACE #define MAX_SAMPLE_LOOPS 5 #define ONE_KILO 1000 @@ -325,6 +326,7 @@ int main(int argc, char *argv[]) Cpa32U lv_count = 0; Cpa16U i = 0; Cpa16S prevDevId = -1; + Cpa16U testsExecuted = 0; #ifdef INCLUDE_COMPRESSION Cpa16U numDcInst = 0; Cpa32U statefulMultiThreadCoreMap[NUMBER_SIMILTANEOUS_THREADS]; @@ -812,6 +814,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -835,6 +841,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -864,6 +874,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -892,6 +906,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -924,6 +942,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -956,6 +978,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -983,6 +1009,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1010,6 +1040,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1035,6 +1069,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1062,6 +1100,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1093,6 +1135,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1124,6 +1170,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -1156,6 +1206,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupRsaTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1187,6 +1241,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupKpt2RsaTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1212,6 +1270,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupKpt2EcdsaTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1247,6 +1309,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDhTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1273,6 +1339,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDsaTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1298,6 +1368,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupEcdsaTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1349,6 +1423,10 @@ int main(int argc, char *argv[]) } return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(ASYM); if (CPA_STATUS_SUCCESS != status) { @@ -1414,6 +1492,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1435,6 +1517,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1456,6 +1542,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1476,6 +1566,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1500,6 +1594,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1521,6 +1619,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1542,6 +1644,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1562,6 +1668,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1587,6 +1697,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1609,6 +1723,10 @@ int main(int argc, char *argv[]) { PRINT_ERR("Stateful setup failed\n"); } + else + { + testsExecuted++; + } /*set the array of cores to create threads on*/ for (lv_count = 0; @@ -1663,6 +1781,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1685,6 +1807,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1707,6 +1833,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1729,6 +1859,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1753,6 +1887,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1775,6 +1913,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1797,6 +1939,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1819,6 +1965,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1847,6 +1997,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1868,6 +2022,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1889,6 +2047,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1910,6 +2072,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1931,6 +2097,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1952,6 +2122,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1973,6 +2147,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -1994,6 +2172,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcLZ4Test\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -2035,6 +2217,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupHashTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2059,6 +2245,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupHashDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2087,6 +2277,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2112,6 +2306,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2145,6 +2343,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupAlgChainDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2173,6 +2375,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupCipherDpTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletionCrypto(SYM); if (CPA_STATUS_SUCCESS != status) { @@ -2224,6 +2430,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -2256,6 +2466,10 @@ int main(int argc, char *argv[]) PRINT_ERR("Error calling setupDcChainTest\n"); return CPA_STATUS_FAIL; } + else + { + testsExecuted++; + } status = createStartandWaitForCompletion(COMPRESSION); if (CPA_STATUS_SUCCESS != status) { @@ -2278,10 +2492,14 @@ int main(int argc, char *argv[]) } qaeMemDestroy(); #endif /* USER_SPACE */ - if (retStatus == CPA_STATUS_SUCCESS) + if ((retStatus == CPA_STATUS_SUCCESS) && (testsExecuted > 0)) { PRINT("Sample code completed successfully.\n"); return CPA_STATUS_SUCCESS; } + if (testsExecuted == 0) + { + PRINT("No tests were executed.\n"); + } return retStatus; } diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_cipher_perf2.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_cipher_perf2.c index a61cba0d..c481c295 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_cipher_perf2.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_cipher_perf2.c @@ -95,12 +95,12 @@ extern int signOfLife; * Callback function for result of perform operation * *****************************************************************************/ -void cipherPerformCallback(void *pCallbackTag, - CpaStatus status, - const CpaCySymOp operationType, - void *pOpData, - CpaBufferList *pDstBuffer, - CpaBoolean verifyResult) +static void cipherPerformCallback(void *pCallbackTag, + CpaStatus status, + const CpaCySymOp operationType, + void *pOpData, + CpaBufferList *pDstBuffer, + CpaBoolean verifyResult) { /*we declare the callback as per the API requirements, but we only use * the pCallbackTag parameter*/ @@ -249,12 +249,12 @@ static CpaStatus cipherPerformOpDataSetup(CpaCySymSessionCtx pSessionCtx, * @description * measures the performance of cipher encryption operations * ****************************************************************************/ -CpaStatus cipherPerform(symmetric_test_params_t *setup, - perf_data_t *pSymData, - Cpa32U numOfLoops, - CpaCySymOpData *ppOpData, - CpaBufferList *ppSrcBuffListArray, - CpaCySymCipherDirection cipherDirection) +static CpaStatus cipherPerform(symmetric_test_params_t *setup, + perf_data_t *pSymData, + Cpa32U numOfLoops, + CpaCySymOpData *ppOpData, + CpaBufferList *ppSrcBuffListArray, + CpaCySymCipherDirection cipherDirection) { CpaBoolean verifyResult = CPA_FALSE; CpaStatus status = CPA_STATUS_SUCCESS; @@ -359,10 +359,10 @@ CpaStatus cipherPerform(symmetric_test_params_t *setup, * @description * Free memory allocated in the sampleCipherPerform function * ****************************************************************************/ -void cipherPerformMemFree(symmetric_test_params_t *setup, - CpaBufferList *pSrcBuffListArray, - CpaCySymOpData *pOpData, - CpaCySymSessionCtx *pSessionCtx) +static void cipherPerformMemFree(symmetric_test_params_t *setup, + CpaBufferList *pSrcBuffListArray, + CpaCySymOpData *pOpData, + CpaCySymSessionCtx *pSessionCtx) { Cpa32U freeMemCount = 0; CpaBufferList *buffList = pSrcBuffListArray; @@ -403,7 +403,7 @@ void cipherPerformMemFree(symmetric_test_params_t *setup, * @description * Main executing function ******************************************************************************/ -CpaStatus sampleCipherPerform(symmetric_test_params_t *setup) +static CpaStatus sampleCipherPerform(symmetric_test_params_t *setup) { /* start of local variable declarations */ CpaCySymSessionCtx sessionCtx = NULL; @@ -550,7 +550,7 @@ CpaStatus sampleCipherPerform(symmetric_test_params_t *setup) * @description * Setup a cipher thread for a given packet size or mix ******************************************************************************/ -void sampleCipherPerformance(single_thread_test_data_t *testSetup) +static void sampleCipherPerformance(single_thread_test_data_t *testSetup) { symmetric_test_params_t symTestSetup; symmetric_test_params_t *pSetup = 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 ac9690c4..50ad7ebc 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 @@ -75,6 +75,7 @@ #include "cpa_sample_code_framework.h" #include "cpa_cy_common.h" #include "cpa_cy_prime.h" +#include "cpa_cy_sym.h" #include "icp_sal_poll.h" #define POLL_AND_SLEEP 1 @@ -123,6 +124,22 @@ Cpa16U numInstances_g = 0; Cpa16U numPolledInstances_g = 0; CpaBoolean allocateMemOnOppositeNode = CPA_FALSE; extern Cpa32U packageIdCount_g; +CpaStatus setCyPollWaitFn(Cpa32U poll_type, Cpa32U sleep_time); +CpaBoolean isFbALessThanFbB(CpaFlatBuffer *pFbA, CpaFlatBuffer *pFbB); +void setBusyLoopMethod(Cpa32U method); +void setTimeStampInLoop(CpaBoolean value); +CpaCySymCipherDirection getCipherDirection(void); +void setCipherDirection(CpaCySymCipherDirection direction); +CpaStatus setDigestAppend(CpaBoolean flag); + +#if CY_API_VERSION_AT_LEAST(3, 0) +volatile CpaBoolean asym_polling_started_g = CPA_FALSE; +CpaInstanceHandle *asymInstances_g = NULL; +Cpa16U numAsymInstances_g = 0; +Cpa16U numAsymPolledInstances_g = 0; +sample_code_thread_t *asymPollingThread_g; +#endif + Cpa32U packetSizes[] = {BUFFER_SIZE_64, BUFFER_SIZE_128, @@ -610,11 +627,11 @@ Cpa32U getOpsPerSecond(Cpa64U responses, perf_cycles_t cycles) } EXPORT_SYMBOL(getOpsPerSecond); -void accumulateAsymPerfData(Cpa32U numberOfThreads, - perf_data_t *performanceStats[], - perf_data_t *stats, - Cpa64U *buffersProcessed, - Cpa32U *responsesPerThread) +static void accumulateAsymPerfData(Cpa32U numberOfThreads, + perf_data_t *performanceStats[], + perf_data_t *stats, + Cpa64U *buffersProcessed, + Cpa32U *responsesPerThread) { Cpa32U i = 0; @@ -774,7 +791,6 @@ CpaStatus printAsymStatsAndStopServices(thread_creation_data_t *data) stats.offloadCycles += stats2[i].offloadCycles; } } - numOfCycles = (stats.endCyclesTimestamp - stats.startCyclesTimestamp); PRINT("Number of Threads %u\n", data->numberOfThreads); PRINT("Total Submissions %llu\n", (unsigned long long)stats.numOperations); @@ -895,7 +911,7 @@ CpaStatus setCyPollInterval(Cpa32U interval) } EXPORT_SYMBOL(setCyPollInterval); -void sampleCodePoll(CpaInstanceHandle instanceHandle_in) +static void sampleCodePoll(CpaInstanceHandle instanceHandle_in) { CpaStatus status = CPA_STATUS_FAIL; while (cy_service_started_g == CPA_TRUE) @@ -1049,6 +1065,30 @@ CpaStatus stopCyServices(void) qaeMemFree((void **)&cyInstances_g); cyInstances_g = NULL; } +#if CY_API_VERSION_AT_LEAST(3, 0) + + /*free the polling threads*/ + if (asym_polling_started_g == CPA_TRUE) + { + /* set polling flag to false */ + asym_polling_started_g = CPA_FALSE; + /* Wait for all threads_g to complete */ + for (i = 0; i < numAsymPolledInstances_g; i++) + { + sampleCodeThreadJoin(&asymPollingThread_g[i]); + } + if (0 < numAsymPolledInstances_g) + { + qaeMemFree((void **)&asymPollingThread_g); + numAsymPolledInstances_g = 0; + } + } + if (asymInstances_g != NULL) + { + qaeMemFree((void **)&asymInstances_g); + asymInstances_g = NULL; + } +#endif return returnStatus; } @@ -1643,7 +1683,8 @@ CpaBoolean isFbALessThanFbB(CpaFlatBuffer *pFbA, CpaFlatBuffer *pFbB) } /*Function assumes each number is the same length in bytes*/ -CpaFlatBuffer *findSmallestNumber(CpaFlatBuffer *numbers, Cpa32U numNumbers) +static CpaFlatBuffer *findSmallestNumber(CpaFlatBuffer *numbers, + Cpa32U numNumbers) { CpaFlatBuffer *result = numbers; Cpa32U i = 0; @@ -1797,10 +1838,10 @@ static void incrementPrimeCandidate(CpaFlatBuffer *primeCandidate) } } -void primeCallback(void *pCallbackTag, - CpaStatus status, - void *pOpData, - CpaBoolean testPassed) +static void primeCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaBoolean testPassed) { perf_data_t *pPerfData = (perf_data_t *)pCallbackTag; if (CPA_STATUS_SUCCESS != status) @@ -1841,7 +1882,8 @@ void primeCallback(void *pCallbackTag, } } -void generatePrimeCandidates(CpaFlatBuffer *primeCandidate, Cpa32U numCandiates) +static void generatePrimeCandidates(CpaFlatBuffer *primeCandidate, + Cpa32U numCandiates) { Cpa32U i = 0; /*generate a random number to test for prime*/ @@ -2505,6 +2547,11 @@ CpaStatus calcDigest(CpaInstanceHandle instanceHandle, /* Determine size of session context to allocate */ status = cpaCySymSessionCtxGetSize( instanceHandle, &sessionSetupData, &sessionCtxSize); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("cpaCySymSessionCtxGetSize failed with status %u\n", status); + return CPA_STATUS_FAIL; + } /* Allocate session context */ pSessionCtx = qaeMemAllocNUMA(sessionCtxSize, node, BYTE_ALIGNMENT_64); if (NULL == pSessionCtx) @@ -2620,6 +2667,11 @@ CpaStatus calcDigest(CpaInstanceHandle instanceHandle, /* Remove the session - session init has already succeeded */ status = removeSymSession(instanceHandle, pSessionCtx); + if (CPA_STATUS_SUCCESS != status) + { + PRINT_ERR("removeSymSession failed with status %u\n", status); + ret = CPA_STATUS_FAIL; + } FREE_CALC_DIGEST_MEM(); @@ -3081,6 +3133,7 @@ CpaStatus cyCreatePollingThreadsIfPollingIsEnabled(void) } EXPORT_SYMBOL(cyCreatePollingThreadsIfPollingIsEnabled); + CpaBoolean cyCheckAllInstancesArePolled(void) { CpaInstanceInfo2 *instanceInfo2 = NULL; @@ -3466,12 +3519,12 @@ void printSymTestType(symmetric_test_params_t *setup) } -void accumulateSymPerfData(Cpa32U numberOfThreads, - perf_data_t *performanceStats[], - perf_data_t *stats, - symmetric_test_params_t *setup, - Cpa64U *buffersProcessed, - Cpa32U *responsesPerThread) +static void accumulateSymPerfData(Cpa32U numberOfThreads, + perf_data_t *performanceStats[], + perf_data_t *stats, + symmetric_test_params_t *setup, + Cpa64U *buffersProcessed, + Cpa32U *responsesPerThread) { Cpa32U i = 0; @@ -3540,6 +3593,8 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) Cpa32U *threadCountPerDevice; perf_data_t *stats2; perf_data_t **tempPerformanceStats = NULL; + Cpa32U numberOfUnsupportedThreads = 0; + Cpa32U totalThreadsRan = 0; /* Cpa32U perfDataDeviceOffsets[packageIdCount_g]; Cpa32U threadCountPerDevice[packageIdCount_g]; @@ -3591,7 +3646,13 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) } for (i = 0; i < data->numberOfThreads; i++) { - if (CPA_STATUS_FAIL == data->performanceStats[i]->threadReturnStatus) + if (CPA_STATUS_UNSUPPORTED == + data->performanceStats[i]->threadReturnStatus) + { + numberOfUnsupportedThreads++; + } + else if (CPA_STATUS_FAIL == + data->performanceStats[i]->threadReturnStatus) { qaeMemFree((void **)&stats2); qaeMemFree((void **)&perfDataDeviceOffsets); @@ -3600,10 +3661,21 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) return CPA_STATUS_FAIL; } } + totalThreadsRan = data->numberOfThreads - numberOfUnsupportedThreads; + + if (totalThreadsRan == 0) + { + qaeMemFree((void **)&stats2); + qaeMemFree((void **)&perfDataDeviceOffsets); + qaeMemFree((void **)&threadCountPerDevice); + qaeMemFree((void **)&tempPerformanceStats); + return CPA_STATUS_FAIL; + } + /* Block to re-group the data per device */ for (j = 0; j < (packageIdCount_g + 1); j++) { - for (i = 0; i < data->numberOfThreads; i++) + for (i = 0; i < totalThreadsRan; i++) { if (data->performanceStats[i]->packageId == j) { @@ -3611,7 +3683,7 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) } } } - for (i = 0; i < data->numberOfThreads; i++) + for (i = 0; i < totalThreadsRan; i++) { data->performanceStats[i] = tempPerformanceStats[i]; } @@ -3638,7 +3710,7 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) * same setup executed*/ getLongestCycleCount2(stats2, data->performanceStats, - data->numberOfThreads, + totalThreadsRan, perfDataDeviceOffsets, threadCountPerDevice); @@ -3690,6 +3762,11 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) setup->performanceStats->averagePacketSizeInBytes); } PRINT("Number of Threads %u\n", data->numberOfThreads); + if (numberOfUnsupportedThreads) + { + PRINT("Unsupported Threads %u\n", numberOfUnsupportedThreads); + } + PRINT("Total Threads ran %u\n", totalThreadsRan); PRINT("Total Submissions %llu\n", (unsigned long long)stats.numOperations); PRINT("Total Responses %llu\n", (unsigned long long)stats.responses); @@ -3715,22 +3792,22 @@ CpaStatus printSymmetricPerfDataAndStopCyService(thread_creation_data_t *data) /*Display how long it took on average to process a buffer in uSecs. *Also include min/max to show variance */ - do_div(stats.minLatency, data->numberOfThreads); + do_div(stats.minLatency, totalThreadsRan); statsLatency = 1000 * stats.minLatency; do_div(statsLatency, cpuFreqKHz); PRINT("Min. Latency (uSecs) %llu\n", statsLatency); - do_div(stats.aveLatency, data->numberOfThreads); + do_div(stats.aveLatency, totalThreadsRan); statsLatency = 1000 * stats.aveLatency; do_div(statsLatency, cpuFreqKHz); PRINT("Ave. Latency (uSecs) %llu\n", statsLatency); - do_div(stats.maxLatency, data->numberOfThreads); + do_div(stats.maxLatency, totalThreadsRan); statsLatency = 1000 * stats.maxLatency; do_div(statsLatency, cpuFreqKHz); PRINT("Max. Latency (uSecs) %llu\n", statsLatency); } if (iaCycleCount_g) { - do_div(stats.offloadCycles, data->numberOfThreads); + do_div(stats.offloadCycles, totalThreadsRan); PRINT("Avg Offload Cycles %llu\n", (long long unsigned int)stats.offloadCycles); } @@ -3875,7 +3952,7 @@ CpaStatus getCyInstanceCapabilities(CpaCyCapabilitiesInfo *pCap) CpaStatus status = CPA_STATUS_FAIL; CpaInstanceHandle instanceHandle = CPA_INSTANCE_HANDLE_SINGLE; - status = cpaCyGetInstances(1, &instanceHandle); + cpaCyGetInstances(1, &instanceHandle); if (instanceHandle == NULL) { return CPA_STATUS_FAIL; @@ -3953,13 +4030,11 @@ CpaStatus getSymAsymInstanceCapabilities(CpaCyCapabilitiesInfo *pCap, if (SYM == instType) { - status = - cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, 1, &instanceHandle); + cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_SYM, 1, &instanceHandle); } else { - status = - cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, 1, &instanceHandle); + cpaGetInstances(CPA_ACC_SVC_TYPE_CRYPTO_ASYM, 1, &instanceHandle); } if (instanceHandle == NULL) 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 38a8be1d..c48aa053 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 @@ -79,6 +79,7 @@ #include "cpa_cy_dh.h" #include "cpa_cy_im.h" #include "cpa_cy_key.h" +#include "cpa_cy_dsa.h" #include "qat_perf_utils.h" #include "cpa_sample_code_utils.h" #include "cpa_sample_code_framework.h" @@ -2189,6 +2190,7 @@ CpaStatus calcSWDigest(CpaFlatBuffer *msg, CpaFlatBuffer *digest, CpaCySymHashAlgorithm hashAlg); + CpaStatus getCyInstanceCapabilities(CpaCyCapabilitiesInfo *pCap); CpaStatus getCySpecificInstanceCapabilities(CpaInstanceHandle instanceHandle, @@ -2535,6 +2537,7 @@ CpaStatus waitForResponses(perf_data_t *perfData, *****************************************************************************/ CpaStatus cyCreatePollingThreadsIfPollingIsEnabled(void); + /** ***************************************************************************** * @ingroup cryptoThreads @@ -2667,6 +2670,11 @@ CpaStatus sampleCodeSymPollInstance(CpaInstanceHandle instanceHandle, * @param[in] data pointer to test data structure ********************************************************************************/ CpaStatus stopCyServicesFromCallback(thread_creation_data_t *data); + +CpaStatus dsaGenZ(CpaInstanceHandle instanceHandle, + CpaFlatBuffer *msg, + CpaCySymHashAlgorithm hashAlg, + CpaFlatBuffer *dsaZ); #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 176bb27b..cd1fbcd6 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 @@ -108,6 +108,8 @@ #include "qat_perf_cycles.h" extern Cpa32U packageIdCount_g; +void dhPerformance(single_thread_test_data_t *testSetup); + /***************************************************************************** * @ingroup dhThreads * @@ -133,8 +135,8 @@ void dhCallback(void *pCallbackTag, * phase 1 operation ie x in PublicValue = g^x mod p * ****************************************************************************/ -void dhPhase1GenX(CpaCyDhPhase1KeyGenOpData *pCpaDhOpDataP1, - asym_test_params_t *setup) +static void dhPhase1GenX(CpaCyDhPhase1KeyGenOpData *pCpaDhOpDataP1, + asym_test_params_t *setup) { /*Choose x by some random method, where 0 < x < p-1*/ generateRandomData(pCpaDhOpDataP1->privateValueX.pData, @@ -1207,7 +1209,7 @@ static CpaStatus dhPerform(asym_test_params_t *setup) * @description * Print the diffie hellman performance stats *****************************************************************************/ -CpaStatus dhPrintStats(thread_creation_data_t *data) +static CpaStatus dhPrintStats(thread_creation_data_t *data) { if (DH_PHASE_1 == ((asym_test_params_t *)data->setupPtr)->phase) { @@ -1313,7 +1315,8 @@ void dhPerformance(single_thread_test_data_t *testSetup) #ifdef SC_DEV_INFO_ENABLED /* check whether asym service enabled or not for the instance */ - status = cpaGetDeviceInfo(instanceInfo->physInstId.packageId, &deviceInfo); + status = + cpaGetDeviceInfo(instanceInfo->physInstId.acceleratorId, &deviceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("%s::%d cpaGetDeviceInfo failed", __func__, __LINE__); diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_drbg_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_drbg_perf.c index 85f6f40e..21f7c104 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_drbg_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_drbg_perf.c @@ -104,6 +104,7 @@ static CpaStatus drbgPerformOp(drbg_test_params_t *setup, CpaCyDrbgSessionHandle *pSessionHdl, Cpa32U node); +extern void nrbgUnregisterDrbgImplFunctions(void); /* Previously set GetEntropy function pointer */ static IcpSalDrbgGetEntropyInputFunc pPrevGetEntropyInputFunc = NULL; @@ -131,10 +132,10 @@ static sample_code_semaphore_t semaphoreImplFunction; * is performed by calling the client-supplied callback function. * *****************************************************************************/ -void drbgPerformCallback(void *pCallbackTag, - CpaStatus status, - void *pOpData, - CpaFlatBuffer *pOut) +static void drbgPerformCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaFlatBuffer *pOut) { perf_data_t *pDrbgPerf = (perf_data_t *)pCallbackTag; @@ -204,7 +205,7 @@ static void nrbgCallback(void *pCallbackTag, * @description * Print the performance stats of the elliptic curve dsa operations ***************************************************************************/ -CpaStatus drbgPrintStats(thread_creation_data_t *data) +static CpaStatus drbgPrintStats(thread_creation_data_t *data) { PRINT("DRBG Size %23u\n", data->packetSize); printSymmetricPerfDataAndStopCyService(data); @@ -690,7 +691,7 @@ static CpaStatus drbgRemoveSession(drbg_test_params_t *setup, * 'Get Entropy Input' function by calling cpaCyNrbgGetEntropy API. * *****************************************************************************/ -CpaStatus drbgPerform(drbg_test_params_t *setup) +static CpaStatus drbgPerform(drbg_test_params_t *setup) { CpaStatus status = CPA_STATUS_SUCCESS, sessionStatus; perf_data_t *pDrbgPerf = NULL; @@ -817,7 +818,7 @@ CpaStatus drbgPerform(drbg_test_params_t *setup) * thread * *****************************************************************************/ -void drbgPerformance(single_thread_test_data_t *testSetup) +static void drbgPerformance(single_thread_test_data_t *testSetup) { drbg_test_params_t drbgSetup; Cpa16U numInstances = 0; 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 96de83ab..7fb3aae4 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 @@ -221,6 +221,20 @@ static Cpa8U dsa_3072_256_q[] = { 0x3c, 0x9c, 0xb8, 0xa3, 0x06, 0xee, 0x25, 0x68, 0xdc, 0x22, 0x8c, 0x4a, 0x39, 0x96, 0x01, 0xe3, 0x57, 0x93, 0xf4, 0x4e, 0x41}; extern Cpa32U packageIdCount_g; +void dsaGenRandom(CpaFlatBuffer *dsaRand, CpaFlatBuffer *dsaQ); +CpaStatus dsaGenG(CpaInstanceHandle instanceHandle, + CpaCyDsaGParamGenOpData *gOpData, + CpaFlatBuffer *dsaG); +CpaStatus dsaGenY(CpaInstanceHandle instanceHandle, + CpaCyDsaYParamGenOpData *yOpData, + CpaFlatBuffer *dsaY); +CpaStatus dsaGenRS(CpaInstanceHandle instanceHandle, + CpaCyDsaRSSignOpData *rsOpData, + CpaFlatBuffer *dsaR, + CpaFlatBuffer *dsaS); +void dsaPerformance(single_thread_test_data_t *testSetup); +CpaStatus dsaPerform(dsa_test_params_t *setup); +void dsaSignPerformance(single_thread_test_data_t *testSetup); /** ***************************************************************************** @@ -733,20 +747,20 @@ CpaStatus dsaGenZ(CpaInstanceHandle instanceHandle, * free all memory used in DSA performance code in this file * *****************************************************************************/ -void freeDsaMem(dsa_test_params_t *setup, - CpaFlatBuffer *dsaX, - CpaFlatBuffer *dsaY, - CpaFlatBuffer *dsaK, - CpaFlatBuffer *dsaM, - CpaFlatBuffer *dsaZ, - CpaFlatBuffer *dsaR, - CpaFlatBuffer *dsaS, - CpaCyDsaVerifyOpData *verifyOpData, - CpaCyDsaRSSignOpData *rsOpData, - CpaFlatBuffer dsaG, - CpaFlatBuffer dsaP, - CpaFlatBuffer dsaH, - CpaFlatBuffer dsaQ) +static void freeDsaMem(dsa_test_params_t *setup, + CpaFlatBuffer *dsaX, + CpaFlatBuffer *dsaY, + CpaFlatBuffer *dsaK, + CpaFlatBuffer *dsaM, + CpaFlatBuffer *dsaZ, + CpaFlatBuffer *dsaR, + CpaFlatBuffer *dsaS, + CpaCyDsaVerifyOpData *verifyOpData, + CpaCyDsaRSSignOpData *rsOpData, + CpaFlatBuffer dsaG, + CpaFlatBuffer dsaP, + CpaFlatBuffer dsaH, + CpaFlatBuffer dsaQ) { freeArrayFlatBufferNUMA(dsaX, setup->numBuffers); freeArrayFlatBufferNUMA(dsaY, setup->numBuffers); @@ -1300,7 +1314,7 @@ EXPORT_SYMBOL(dsaPerform); * and signed. * *****************************************************************************/ -CpaStatus dsaSignPerform(dsa_test_params_t *setup) +static CpaStatus dsaSignPerform(dsa_test_params_t *setup) { Cpa32U i = 0; Cpa32U outerLoop = 0; @@ -1743,7 +1757,7 @@ CpaStatus dsaSignPerform(dsa_test_params_t *setup) * Print out the DSA performance * *****************************************************************************/ -CpaStatus dsaPrintStats(thread_creation_data_t *data) +static CpaStatus dsaPrintStats(thread_creation_data_t *data) { PRINT("DSA VERIFY\n"); PRINT("Modulus Size %19d\n", data->packetSize * NUM_BITS_IN_BYTE); @@ -1760,7 +1774,7 @@ CpaStatus dsaPrintStats(thread_creation_data_t *data) * Print out the DSA sign only performance * *****************************************************************************/ -CpaStatus dsaSignPrintStats(thread_creation_data_t *data) +static CpaStatus dsaSignPrintStats(thread_creation_data_t *data) { PRINT("DSA SIGN\n"); PRINT("Modulus Size %19d\n", data->packetSize * NUM_BITS_IN_BYTE); @@ -1787,7 +1801,7 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, CpaInstanceHandle *cyInstances = NULL; CpaStatus status = CPA_STATUS_FAIL; dsa_test_params_t *params = (dsa_test_params_t *)testSetup->setupPtr; - CpaInstanceInfo2 instanceInfo = {0}; + CpaInstanceInfo2 *instanceInfo = NULL; #ifdef SC_DEV_INFO_ENABLED CpaDeviceInfo deviceInfo = {0}; #endif @@ -1830,10 +1844,19 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } + instanceInfo = qaeMemAlloc(sizeof(CpaInstanceInfo2)); + if (instanceInfo == NULL) + { + PRINT_ERR("Failed to allocate memory for instanceInfo"); + dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; + sampleCodeThreadExit(); + } + memset(instanceInfo, 0, sizeof(CpaInstanceInfo2)); cyInstances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances); if (NULL == cyInstances) { PRINT_ERR("Could not allocate memory for logical instances\n"); + qaeMemFree((void **)&instanceInfo); dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } @@ -1843,23 +1866,26 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, dsaSetup.cyInstanceHandle = cyInstances[(testSetup->logicalQaInstance) % numInstances]; - status = cpaCyInstanceGetInfo2(dsaSetup.cyInstanceHandle, &instanceInfo); + status = cpaCyInstanceGetInfo2(dsaSetup.cyInstanceHandle, instanceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("%s::%d cpaCyInstanceGetInfo2 failed", __func__, __LINE__); qaeMemFree((void **)&cyInstances); + qaeMemFree((void **)&instanceInfo); dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; sampleCodeThreadExit(); } #ifdef SC_DEV_INFO_ENABLED /* check whether asym service enabled or not for the instance */ - status = cpaGetDeviceInfo(instanceInfo.physInstId.packageId, &deviceInfo); + status = + cpaGetDeviceInfo(instanceInfo->physInstId.acceleratorId, &deviceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("%s::%d cpaGetDeviceInfo failed", __func__, __LINE__); dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; qaeMemFree((void **)&cyInstances); + qaeMemFree((void **)&instanceInfo); sampleCodeThreadExit(); } if (CPA_FALSE == deviceInfo.cyAsymEnabled) @@ -1870,14 +1896,15 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, __LINE__); dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; qaeMemFree((void **)&cyInstances); + qaeMemFree((void **)&instanceInfo); sampleCodeThreadExit(); } #endif - if (instanceInfo.physInstId.packageId > packageIdCount_g) + if (instanceInfo->physInstId.packageId > packageIdCount_g) { - packageIdCount_g = instanceInfo.physInstId.packageId; + packageIdCount_g = instanceInfo->physInstId.packageId; } - dsaSetup.performanceStats->packageId = instanceInfo.physInstId.packageId; + dsaSetup.performanceStats->packageId = instanceInfo->physInstId.packageId; /*launch function that does all the work */ @@ -1900,6 +1927,7 @@ static void dsaPerformanceGen(single_thread_test_data_t *testSetup, dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; } qaeMemFree((void **)&cyInstances); + qaeMemFree((void **)&instanceInfo); sampleCodeThreadComplete(testSetup->threadID); } diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ec_montedwds_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ec_montedwds_perf.c index 8880b2a1..2de7b998 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ec_montedwds_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ec_montedwds_perf.c @@ -92,6 +92,8 @@ #if CY_API_VERSION_AT_LEAST(2, 3) extern Cpa32U packageIdCount_g; +void ecMontEdwdsPerformance(single_thread_test_data_t *testSetup); + CpaBoolean isECMontEdwdsSupported(void) { CpaStatus status = CPA_STATUS_FAIL; 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 5f74c240..b9c44438 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 @@ -98,6 +98,51 @@ extern Cpa32U packageIdCount_g; CpaBoolean msgFlagSym2 = CPA_FALSE; +void ecdsaPerformCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaBoolean verifyStatus); +void ecdsaPointMultiplyPerformCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaBoolean multiplyStatus, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS); +void ecdsaSignOnlyPerformCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaBoolean multiplyStatus, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS); +CpaStatus getCurveData(ecdsa_test_params_t *setup); +CpaStatus calcEcPoint(ecdsa_test_params_t *setup, + CpaFlatBuffer *k, + CpaFlatBuffer *pXk, + CpaFlatBuffer *pYk); +CpaStatus ecdsaSignRSOpDataSetup(ecdsa_test_params_t *setup, + CpaFlatBuffer *d, + CpaFlatBuffer *r, + CpaFlatBuffer *s, + CpaFlatBuffer *message, + CpaFlatBuffer *z, + CpaFlatBuffer *pDigest, + perf_data_t *pEcdsaData, + CpaCyEcdsaSignRSOpData *pSignRSOpData); +CpaStatus ecdsaPerform(ecdsa_test_params_t *setup); +void ecdsaPerformance(single_thread_test_data_t *testSetup); +void ecdsaPerformRsOnlyMemFree( + ecdsa_test_params_t *setup, + CpaFlatBuffer *pX, + CpaFlatBuffer *pY, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS, + CpaFlatBuffer *msg, + CpaFlatBuffer *pZ, + CpaFlatBuffer **ppDigests, + CpaCyEcdsaSignRSOpData **ppSignRSOpData, + CpaCyEcPointMultiplyOpData **ppPointMultiplyOpData, + CpaFlatBuffer privateKey); + ///* // * *********************************************************************** // * elliptic curve definitions as defined in: @@ -606,14 +651,14 @@ EXPORT_SYMBOL(ecdsaSignRSOpDataSetup); * Sign the digest of a random message using elliptic curve data in setup * parameter ***************************************************************************/ -CpaStatus ecdsaSignRS(ecdsa_test_params_t *setup, - CpaFlatBuffer *d, - CpaFlatBuffer *r, - CpaFlatBuffer *s, - CpaFlatBuffer *message, - CpaFlatBuffer *z, - CpaCyEcdsaSignRSCbFunc cbFunc, - perf_data_t *pEcdsaData) +static CpaStatus ecdsaSignRS(ecdsa_test_params_t *setup, + CpaFlatBuffer *d, + CpaFlatBuffer *r, + CpaFlatBuffer *s, + CpaFlatBuffer *message, + CpaFlatBuffer *z, + CpaCyEcdsaSignRSCbFunc cbFunc, + perf_data_t *pEcdsaData) { CpaStatus status = CPA_STATUS_FAIL; CpaBoolean signStatus = CPA_FALSE; @@ -914,15 +959,15 @@ CpaStatus ecdsaSignRS(ecdsa_test_params_t *setup, ecdsaMemFree(setup, pX, pY, pR, pS, msg, pZ, ppOpData, privateKey); \ } while (0) -void ecdsaMemFree(ecdsa_test_params_t *setup, - CpaFlatBuffer *pX, - CpaFlatBuffer *pY, - CpaFlatBuffer *pR, - CpaFlatBuffer *pS, - CpaFlatBuffer *msg, - CpaFlatBuffer *pZ, - CpaCyEcdsaVerifyOpData **ppOpData, - CpaFlatBuffer privateKey) +static void ecdsaMemFree(ecdsa_test_params_t *setup, + CpaFlatBuffer *pX, + CpaFlatBuffer *pY, + CpaFlatBuffer *pR, + CpaFlatBuffer *pS, + CpaFlatBuffer *msg, + CpaFlatBuffer *pZ, + CpaCyEcdsaVerifyOpData **ppOpData, + CpaFlatBuffer privateKey) { Cpa32U k = 0; @@ -1664,7 +1709,7 @@ EXPORT_SYMBOL(ecdsaPerform); * @description * Print the performance stats of the elliptic curve dsa operations ***************************************************************************/ -CpaStatus ecdsaPrintStats(thread_creation_data_t *data) +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) @@ -1798,7 +1843,8 @@ void ecdsaPerformance(single_thread_test_data_t *testSetup) #ifdef SC_DEV_INFO_ENABLED /* check whether asym service enabled or not for the instance */ - status = cpaGetDeviceInfo(instanceInfo->physInstId.packageId, &deviceInfo); + status = + cpaGetDeviceInfo(instanceInfo->physInstId.acceleratorId, &deviceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("%s::%d cpaGetDeviceInfo failed", __func__, __LINE__); 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 a471e43d..79bd8914 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 @@ -115,6 +115,17 @@ CpaStatus dsaGenZ(CpaInstanceHandle instanceHandle, CpaCySymHashAlgorithm hashAlg, CpaFlatBuffer *dsaZ); +CpaStatus setupIkeDsaTest(Cpa32U pLenInBits, + Cpa32U qLenInBits, + sync_mode_t syncMode, + Cpa32U numBuffs, + Cpa32U numLoops); +void ikeDsaCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaFlatBuffer *pOut); +void ikeDsaPerformance(single_thread_test_data_t *testSetup); + /***************************************************************** * Declare a static 1024/160 bit P/Q pair that satisfies FIPS186-3 * ***************************************************************/ @@ -277,12 +288,12 @@ void ikeDsaCallback(void *pCallbackTag, * This function frees all Operation Data memory setup in this file. * The code checks for any unallocated memory before it attempts to free it. ******************************************************************************/ -void dsaFreeDataMemory(dsa_test_params_t *setup, - CpaCyDsaRSSignOpData *pSignOpdata[], - CpaCyDsaVerifyOpData *pVerifyOpData[], - CpaCyDsaVerifyOpData *pVerifyOpData2[], - CpaFlatBuffer *pR[], - CpaFlatBuffer *pS[]) +static void dsaFreeDataMemory(dsa_test_params_t *setup, + CpaCyDsaRSSignOpData *pSignOpdata[], + CpaCyDsaVerifyOpData *pVerifyOpData[], + CpaCyDsaVerifyOpData *pVerifyOpData2[], + CpaFlatBuffer *pR[], + CpaFlatBuffer *pS[]) { Cpa32U bufferCount = 0; @@ -387,8 +398,8 @@ static void ikeDsaMemFreeDsaData(ike_dsa_client_data_t *client) * This function allocates the client memory for an IKE-DSA * transaction used in ikeDsaPerform ******************************************************************************/ -CpaStatus allocDsaClientMem(dsa_test_params_t *setup, - ike_dsa_client_data_t *client) +static CpaStatus allocDsaClientMem(dsa_test_params_t *setup, + ike_dsa_client_data_t *client) { if (CPA_STATUS_SUCCESS != allocArrayOfPointers(setup->cyInstanceHandle, @@ -474,14 +485,14 @@ CpaStatus allocDsaClientMem(dsa_test_params_t *setup, * free all memory used in DSA IKE code in this file * *****************************************************************************/ -void freeIkeDsaMem(dsa_test_params_t *setup, - CpaFlatBuffer *dsaX, - CpaFlatBuffer *dsaY, - CpaFlatBuffer *dsaK, - CpaFlatBuffer *dsaP, - CpaFlatBuffer *dsaQ, - CpaFlatBuffer *dsaG, - CpaFlatBuffer *dsaH) +static void freeIkeDsaMem(dsa_test_params_t *setup, + CpaFlatBuffer *dsaX, + CpaFlatBuffer *dsaY, + CpaFlatBuffer *dsaK, + CpaFlatBuffer *dsaP, + CpaFlatBuffer *dsaQ, + CpaFlatBuffer *dsaG, + CpaFlatBuffer *dsaH) { freeArrayFlatBufferNUMA(dsaX, setup->numBuffers); freeArrayFlatBufferNUMA(dsaY, setup->numBuffers); @@ -524,12 +535,12 @@ void freeIkeDsaMem(dsa_test_params_t *setup, * this function allocates space and generates arrays of DSA keys, based on the * parameters within the setup * ****************************************************************************/ -CpaStatus genDsaPara(dsa_test_params_t *setup, - CpaCyDsaRSSignOpData **ppSignOpData, - CpaCyDsaVerifyOpData **ppVerifyOpData, - CpaCyDsaVerifyOpData **ppVerifyOpData2, - CpaFlatBuffer **ppdsaR, - CpaFlatBuffer **ppdsaS) +static CpaStatus genDsaPara(dsa_test_params_t *setup, + CpaCyDsaRSSignOpData **ppSignOpData, + CpaCyDsaVerifyOpData **ppVerifyOpData, + CpaCyDsaVerifyOpData **ppVerifyOpData2, + CpaFlatBuffer **ppdsaR, + CpaFlatBuffer **ppdsaS) { Cpa32U i = 0; Cpa32U status = 0; @@ -1001,12 +1012,12 @@ CpaStatus genDsaPara(dsa_test_params_t *setup, * It is assumed all the encrypt data and keys have been been set using * functions defined in this file * ****************************************************************************/ -CpaStatus sampleDsaSign(dsa_test_params_t *setup, - CpaCyDsaRSSignOpData *pRSSignOpData[], - CpaFlatBuffer *dsaR[], - CpaFlatBuffer *dsaS[], - Cpa32U numBuffers, - Cpa32U numLoops) +static CpaStatus sampleDsaSign(dsa_test_params_t *setup, + CpaCyDsaRSSignOpData *pRSSignOpData[], + CpaFlatBuffer *dsaR[], + CpaFlatBuffer *dsaS[], + Cpa32U numBuffers, + Cpa32U numLoops) { Cpa32U outerLoop = 0; Cpa32U i = 0; @@ -1098,11 +1109,11 @@ static void ikeDsaMemFree(dsa_test_params_t *setup, * store the output * ****************************************************************************/ -CpaStatus dsaZSetup(CpaFlatBuffer **ppPublicValues, - CpaCyDsaRSSignOpData **ppSignatureOpData, - CpaCyDsaVerifyOpData **ppVerifyOpData, - CpaCyDsaVerifyOpData **ppVerifyOpData2, - dsa_test_params_t *setup) +static CpaStatus dsaZSetup(CpaFlatBuffer **ppPublicValues, + CpaCyDsaRSSignOpData **ppSignatureOpData, + CpaCyDsaVerifyOpData **ppVerifyOpData, + CpaCyDsaVerifyOpData **ppVerifyOpData2, + dsa_test_params_t *setup) { Cpa32U i = 0; CpaStatus status = CPA_STATUS_SUCCESS; @@ -1713,7 +1724,7 @@ static CpaStatus ikeDsaPerform(dsa_test_params_t *setup) * @description * This function prints the IKE-DSA performance stats ******************************************************************************/ -CpaStatus ikeDsaPrintStats(thread_creation_data_t *data) +static CpaStatus ikeDsaPrintStats(thread_creation_data_t *data) { PRINT("IKE_DSA SIMULATION\n"); PRINT("Modulus Size %17u\n", data->packetSize); diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_rsa_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_rsa_perf.c index 46df2af5..fc97e86c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_rsa_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_ike_rsa_perf.c @@ -111,6 +111,14 @@ typedef struct ike_rsa_client_data_s CpaCyRsaDecryptOpData **ppDecryptOpData; CpaFlatBuffer **ppSignatures; } ike_rsa_client_data_t; + +void ikeRsaCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaFlatBuffer *pOut); +CpaStatus allocClientMem(asym_test_params_t *setup, + ike_rsa_client_data_t *client); + /***************************************************************************** * @ingroup IKE_RSA Threads * @@ -854,7 +862,7 @@ static CpaStatus ikeRsaPerform(asym_test_params_t *setup) * @description * This function prints the IKE-RSA performance stats ******************************************************************************/ -CpaStatus ikeRsaPrintStats(thread_creation_data_t *data) +static CpaStatus ikeRsaPrintStats(thread_creation_data_t *data) { PRINT("IKE_RSA SIMULATION\n"); PRINT("Modulus Size %17u\n", data->packetSize); @@ -868,7 +876,7 @@ CpaStatus ikeRsaPrintStats(thread_creation_data_t *data) * @description * This function sets up an IKE-RSA thread ******************************************************************************/ -void ikeRsaPerformance(single_thread_test_data_t *testSetup) +static void ikeRsaPerformance(single_thread_test_data_t *testSetup) { asym_test_params_t ikeRsaSetup; asym_test_params_t *setup = (asym_test_params_t *)testSetup->setupPtr; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_nrbg_perf.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_nrbg_perf.c index 514d7040..dcefe810 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_nrbg_perf.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_nrbg_perf.c @@ -87,16 +87,16 @@ * IcpSalDrbgGetEntropyInputCbFunc * *****************************************************************************/ -void nrbgPerformCallback(void *pCallbackTag, - CpaStatus status, - void *pOpData, - CpaFlatBuffer *pOut) +static void nrbgPerformCallback(void *pCallbackTag, + CpaStatus status, + void *pOpData, + CpaFlatBuffer *pOut) { processCallback(pCallbackTag); } -void nrbgMemFree(nrbg_test_params_t *setup, - CpaFlatBuffer *pEntropy, - CpaCyNrbgOpData **pOpData) +static void nrbgMemFree(nrbg_test_params_t *setup, + CpaFlatBuffer *pEntropy, + CpaCyNrbgOpData **pOpData) { Cpa32U k = 0; @@ -133,7 +133,7 @@ void nrbgMemFree(nrbg_test_params_t *setup, * *****************************************************************************/ -CpaStatus nrbgPerform(nrbg_test_params_t *setup) +static CpaStatus nrbgPerform(nrbg_test_params_t *setup) { Cpa32U i = 0; Cpa32U numLoops = 0; @@ -297,7 +297,7 @@ CpaStatus nrbgPerform(nrbg_test_params_t *setup) * @description * Print the performance stats of the elliptic curve dsa operations ***************************************************************************/ -CpaStatus nrbgPrintStats(thread_creation_data_t *data) +static CpaStatus nrbgPrintStats(thread_creation_data_t *data) { PRINT("NRBG\n"); PRINT("NRBG Size %23u\n", data->packetSize); @@ -311,7 +311,7 @@ CpaStatus nrbgPrintStats(thread_creation_data_t *data) * @description * setup an elliptic curve performance thread ***************************************************************************/ -void nrbgPerformance(single_thread_test_data_t *testSetup) +static void nrbgPerformance(single_thread_test_data_t *testSetup) { nrbg_test_params_t nrbgSetup; Cpa16U numInstances = 0; 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 663d6ba8..8a99ec14 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 @@ -146,6 +146,18 @@ Cpa8U rsaPublicExponent_g[] = {0x01, 0x00, 0x01}; // Cpa8U rsaPublicExponent_g[] = {0x11}; extern Cpa32U packageIdCount_g; +void sampleRsaThreadSetup(single_thread_test_data_t *testSetup); +CpaStatus setupRsaBackpressureTest(Cpa32U numLoops); +CpaStatus setAsymPollingInterval(Cpa64U pollingInterval); +#if CY_API_VERSION_AT_LEAST(3, 0) +#ifdef SC_KPT2_ENABLED +void kpt2RsaCallback(void *pCallbackTag, + CpaStatus status, + void *pOpdata, + CpaFlatBuffer *pOut); +#endif +#endif + /****************************************************************************** * @ingroup sampleRSACode @@ -154,11 +166,11 @@ extern Cpa32U packageIdCount_g; * Callback for RSA KeyGen operations, we declare function signature as per the * API but we only use the pCallbackTag parameter * ****************************************************************************/ -void rsaKeyGenCallback(void *pCallbackTag, - CpaStatus status, - void *pKeyGenOpData, - CpaCyRsaPrivateKey *pPrivateKey, - CpaCyRsaPublicKey *pPublicKey) +static void rsaKeyGenCallback(void *pCallbackTag, + CpaStatus status, + void *pKeyGenOpData, + CpaCyRsaPrivateKey *pPrivateKey, + CpaCyRsaPublicKey *pPublicKey) { perf_data_t *pPerfData = (perf_data_t *)pCallbackTag; @@ -187,10 +199,10 @@ void rsaKeyGenCallback(void *pCallbackTag, * Callback for RSA operations, we declare function signature as per the API * but we only use the pCallbackTag parameter * ****************************************************************************/ -void rsaCallback(void *pCallbackTag, - CpaStatus status, - void *pOpdata, - CpaFlatBuffer *pOut) +static void rsaCallback(void *pCallbackTag, + CpaStatus status, + void *pOpdata, + CpaFlatBuffer *pOut) { processCallback(pCallbackTag); } @@ -310,14 +322,14 @@ CpaStatus generateRSAKey(CpaInstanceHandle instanceHandle, /*allocate space for the key data modulusN*/ ALLOC_FLAT_BUFF_DATA(instanceHandle, &(pPrivateKey->privateKeyRep1.modulusN), - modulusLenInBytes, + kSize, NULL, 0, FREE_GENERATE_RSA_KEY_MEM()); /*allocate space for the key data privateExponentD*/ ALLOC_FLAT_BUFF_DATA(instanceHandle, &(pPrivateKey->privateKeyRep1.privateExponentD), - modulusLenInBytes, + kSize, NULL, 0, FREE_GENERATE_RSA_KEY_MEM()); @@ -1310,6 +1322,8 @@ CpaStatus sampleRsaDecrypt(asym_test_params_t *setup, { PRINT_ERR("Failed to allocate memory for submission and" " response times\n"); + qaeMemFree((void **)&request_respnse_time); + qaeMemFree((void **)&request_submit_start); return CPA_STATUS_FAIL; } memset(request_submit_start, 0, request_mem_sz); @@ -1834,7 +1848,7 @@ CpaStatus sampleRsaPerform(asym_test_params_t *setup) return status; } -CpaStatus sampleRsaEncryptPerform(asym_test_params_t *setup) +static CpaStatus sampleRsaEncryptPerform(asym_test_params_t *setup) { /* start of local variable declarations */ CpaStatus status = CPA_STATUS_SUCCESS; @@ -2022,7 +2036,8 @@ void sampleRsaThreadSetup(single_thread_test_data_t *testSetup) #ifdef SC_DEV_INFO_ENABLED /* check whether asym service enabled or not for the instance */ - status = cpaGetDeviceInfo(instanceInfo->physInstId.packageId, &deviceInfo); + status = + cpaGetDeviceInfo(instanceInfo->physInstId.acceleratorId, &deviceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("%s::%d cpaGetDeviceInfo failed", __func__, __LINE__); 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 1f2d7b38..b853e15e 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 @@ -462,12 +462,15 @@ static CpaStatus sm2PerfDataSetup(sm2_test_params_t *setup) keyexOutput.x.pData = setup->x1[i].pData; keyexOutput.y.dataLenInBytes = setup->y1[i].dataLenInBytes; keyexOutput.y.pData = setup->y1[i].pData; - status = cpaCyEcsm2KeyExPhase1( - setup->cyInstanceHandle, - NULL, /* Sync mode */ - NULL, - &keyexOp, /* Key exchange p1 request data */ - &keyexOutput /* Key exchange p1 response data */); + do + { + status = cpaCyEcsm2KeyExPhase1( + setup->cyInstanceHandle, + NULL, /* Sync mode */ + NULL, + &keyexOp, /* Key exchange p1 request data */ + &keyexOutput /* Key exchange p1 response data */); + } while (CPA_STATUS_RETRY == status); /* fill the input and output structure for key exchange phase 1 * using the random value in inverse order */ @@ -605,7 +608,8 @@ void sm2Performance(single_thread_test_data_t *testSetup) goto exit; } /* check whether asym service enabled or not for the instance */ - status = cpaGetDeviceInfo(instanceInfo.physInstId.packageId, &deviceInfo); + status = + cpaGetDeviceInfo(instanceInfo.physInstId.acceleratorId, &deviceInfo); if (CPA_STATUS_SUCCESS != status) { PRINT_ERR("cpaGetDeviceInfo failed\n"); 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 2f7cfeb5..3c9a03c1 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 @@ -378,9 +378,9 @@ static CpaStatus symmetricSetupSession(CpaCySymCbFunc pSymCb, * @description * Free memory allocated in the symmetricPerformOpDataSetup function * ****************************************************************************/ -void opDataMemFree(CpaCySymOpData *pOpdata[], - Cpa32U numBuffers, - CpaBoolean digestAppend) +static void opDataMemFree(CpaCySymOpData *pOpdata[], + Cpa32U numBuffers, + CpaBoolean digestAppend) { Cpa32U k = 0; @@ -631,12 +631,12 @@ static CpaStatus symmetricPerformOpDataSetup(CpaCySymSessionCtx pSessionCtx, * @description * measures the performance of symmetric encryption operations * ****************************************************************************/ -CpaStatus symPerform(symmetric_test_params_t *setup, - perf_data_t *pSymData, - Cpa32U numOfLoops, - CpaCySymOpData **ppOpData, - CpaBufferList **ppSrcBuffListArray, - CpaCySymCipherDirection cipherDirection) +static CpaStatus symPerform(symmetric_test_params_t *setup, + perf_data_t *pSymData, + Cpa32U numOfLoops, + CpaCySymOpData **ppOpData, + CpaBufferList **ppSrcBuffListArray, + CpaCySymCipherDirection cipherDirection) { CpaBoolean verifyResult = CPA_FALSE; CpaStatus status = CPA_STATUS_SUCCESS; @@ -699,6 +699,8 @@ CpaStatus symPerform(symmetric_test_params_t *setup, PRINT_ERR("Failed to allocate memory for submission and response " "times\n"); qaeMemFree((void **)&instanceInfo2); + qaeMemFree((void **)&request_respnse_time); + qaeMemFree((void **)&request_submit_start); return CPA_STATUS_FAIL; } memset(request_submit_start, 0, request_mem_sz); @@ -971,11 +973,11 @@ CpaStatus symPerform(symmetric_test_params_t *setup, * @description * Free memory allocated in the sampleSymmetricPerform function * ****************************************************************************/ -void symPerformMemFree(symmetric_test_params_t *setup, - CpaFlatBuffer **ppSrcBuffPtrArray, - CpaBufferList **ppSrcBuffListArray, - CpaCySymOpData **ppOpData, - CpaCySymSessionCtx *pSessionCtx) +static void symPerformMemFree(symmetric_test_params_t *setup, + CpaFlatBuffer **ppSrcBuffPtrArray, + CpaBufferList **ppSrcBuffListArray, + CpaCySymOpData **ppOpData, + CpaCySymSessionCtx *pSessionCtx) { /*free bufferLists, flatBuffers and data*/ sampleFreeBuffers(ppSrcBuffPtrArray, ppSrcBuffListArray, setup); @@ -1037,7 +1039,6 @@ static CpaStatus performOffloadCalculation( packetSize, pPerfData->endCyclesTimestamp - pPerfData->startCyclesTimestamp); - currentThroughput = baseThroughput; /* Find the lower bound(retries) and upper bound(no retries) for subsequent * binary search. @@ -1491,12 +1492,14 @@ void sampleSymmetricPerformance(single_thread_test_data_t *testSetup) testSetup->threadID); testSetup->statsPrintFunc = (stats_print_func_t)printSymmetricPerfDataAndStopCyService; - symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; - error_flag_g = CPA_TRUE; + symTestSetup.performanceStats->threadReturnStatus = + CPA_STATUS_UNSUPPORTED; + error_flag_g = CPA_FALSE; sampleCodeBarrier(); goto exit; } + /*launch function that does all the work*/ status = sampleSymmetricPerform(&symTestSetup); if (CPA_STATUS_SUCCESS != status) 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 0808f657..5b18b96a 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 @@ -118,6 +118,11 @@ extern volatile CpaBoolean backoff_dynamic_g; extern uint32_t backoff_static_timer_g; extern CpaInstanceHandle *cyInstances_g; +CpaStatus setSymPollingInterval(Cpa64U pollingInterval); +CpaStatus printDigestAppend(CpaBoolean flag); +CpaStatus printSymPollingInterval(void); +void sampleSymmetricDpPerformance(single_thread_test_data_t *testSetup); + /***************************************************************************** * * Internal Function Interfaces @@ -170,9 +175,9 @@ EXPORT_SYMBOL(printSymPollingInterval); * @description * Poll the number of DP operations * ***************************************************************************/ -CpaStatus cyDpPollNumOperations(perf_data_t *pPerfData, - CpaInstanceHandle instanceHandle, - Cpa64U numOperations) +static CpaStatus cyDpPollNumOperations(perf_data_t *pPerfData, + CpaInstanceHandle instanceHandle, + Cpa64U numOperations) { CpaStatus status = CPA_STATUS_FAIL; @@ -326,6 +331,8 @@ static void symDpSetDigestBuffer(Cpa32U messageLenToCipherInBytes, { pDigestResult = (Cpa8U *)(pBufferList->pBuffers[0].pData + messageLenToCipherInBytes); + /* reset the digest memory to 0 */ + memset((void *)pDigestResult, value, digestLengthInBytes); } else { @@ -335,22 +342,20 @@ static void symDpSetDigestBuffer(Cpa32U messageLenToCipherInBytes, pDigestResult = (Cpa8U *)(pBufferList->pBuffers[indexBuffer].pData + (messageLenToCipherInBytes % bufferSizeInByte)); - } - - /* reset the digest memory to 0 */ - - memset( - (void *)pDigestResult, - value, - (pBufferList->pBuffers[0].dataLenInBytes - - messageLenToCipherInBytes % pBufferList->pBuffers[0].dataLenInBytes)); - - indexBuffer++; - for (i = indexBuffer; i < pBufferList->numBuffers; i++) - { - memset((void *)(uintptr_t)pBufferList->pBuffers[i].pData, + /* reset the digest memory to 0 */ + memset((void *)pDigestResult, value, - pBufferList->pBuffers[i].dataLenInBytes); + (pBufferList->pBuffers[0].dataLenInBytes - + messageLenToCipherInBytes % + pBufferList->pBuffers[0].dataLenInBytes)); + + indexBuffer++; + for (i = indexBuffer; i < pBufferList->numBuffers; i++) + { + memset((void *)(uintptr_t)pBufferList->pBuffers[i].pData, + value, + pBufferList->pBuffers[i].dataLenInBytes); + } } } /***************************************************************************** @@ -458,9 +463,9 @@ static void symDpPerformMemFree(symmetric_test_params_t *setup, * When the number of response is equal to the number of operations, * it will release one semaphore for async operation. *****************************************************************************/ -void symDpPerformCallback(CpaCySymDpOpData *pOpData, - CpaStatus status, - CpaBoolean verifyResult) +static void symDpPerformCallback(CpaCySymDpOpData *pOpData, + CpaStatus status, + CpaBoolean verifyResult) { /* pCallbacktag in the pOpData structure is used to store * index of to the perf_data_t associated the thread @@ -1075,11 +1080,11 @@ static CpaStatus symmetricDpPerformOpDataSetup( * The request is submitted to be performed by invoking the function * @ref cpaCySymDpPerformOpNow. * ***************************************************************************/ -CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, - Cpa32U numOfLoops, - CpaCySymDpOpData **ppOpData, - CpaBufferList **ppSrcBuffListArray, - CpaCySymCipherDirection cipherDirection) +static CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, + Cpa32U numOfLoops, + CpaCySymDpOpData **ppOpData, + CpaBufferList **ppSrcBuffListArray, + CpaCySymCipherDirection cipherDirection) { CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U outsideLoopCount = 0; @@ -1153,6 +1158,8 @@ CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, { PRINT_ERR("Failed to allocate memory for submission and response " "times\n"); + qaeMemFree((void **)&request_respnse_time); + qaeMemFree((void **)&request_submit_start); return CPA_STATUS_FAIL; } memset(request_submit_start, 0, request_mem_sz); @@ -1484,8 +1491,15 @@ CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, setup->performanceStats->startCyclesTimestamp) - setup->performanceStats->totalBusyLoopCycles; - do_div(setup->performanceStats->offloadCycles, - setup->performanceStats->responses); + if (setup->performanceStats->responses == 0) + { + PRINT_ERR("The response count is 0\n"); + } + else + { + do_div(setup->performanceStats->offloadCycles, + setup->performanceStats->responses); + } } coo_average(pSymData); @@ -1500,11 +1514,12 @@ CpaStatus symDpPerformEnqueueOp(symmetric_test_params_t *setup, * @description * Enqueue multiple requests with one operation, perform later * ***************************************************************************/ -CpaStatus symDpPerformEnqueueOpBatch(symmetric_test_params_t *setup, - Cpa32U numOfLoops, - CpaCySymDpOpData **ppOpData, - CpaBufferList **ppSrcBuffListArray, - CpaCySymCipherDirection cipherDirection) +static CpaStatus symDpPerformEnqueueOpBatch( + symmetric_test_params_t *setup, + Cpa32U numOfLoops, + CpaCySymDpOpData **ppOpData, + CpaBufferList **ppSrcBuffListArray, + CpaCySymCipherDirection cipherDirection) { CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U outsideLoopCount = 0; @@ -1750,7 +1765,6 @@ static CpaStatus performOffloadCalculation( packetSize, pPerfData->endCyclesTimestamp - pPerfData->startCyclesTimestamp); - currentThroughput = baseThroughput; /* Find the lower bound(retries) and upper bound(no retries) for subsequent * binary search. @@ -2387,8 +2401,9 @@ void sampleSymmetricDpPerformance(single_thread_test_data_t *testSetup) testSetup->threadID); testSetup->statsPrintFunc = (stats_print_func_t)printSymmetricPerfDataAndStopCyService; - symTestSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL; - error_flag_g = CPA_TRUE; + symTestSetup.performanceStats->threadReturnStatus = + CPA_STATUS_UNSUPPORTED; + error_flag_g = CPA_FALSE; sampleCodeBarrier(); symTestSetup.packetSizeInBytesArray = NULL; goto exit; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update.c index dc80d8dd..a07f300c 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update.c @@ -1419,7 +1419,8 @@ static CpaStatus updatePerform(symmetric_test_params_t *setup) return status; } -void sampleSymmetricUpdatePerformance(single_thread_test_data_t *testSetup) +static void sampleSymmetricUpdatePerformance( + single_thread_test_data_t *testSetup) { symmetric_test_params_t updateTestSetup; symmetric_test_params_t *pSetup = diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.c index 068bf64f..dfba4d35 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.c @@ -110,69 +110,80 @@ CpaStatus cpaCySymSessionInUse(CpaCySymSessionCtx sessionCtx, #if CY_API_VERSION_AT_LEAST(2, 2) // Init variables -const testSetupCipher_t cipherSetup[ALGCHAIN_CIPHER_NUM] = { - {0, 0}, - {CPA_CY_SYM_CIPHER_NULL, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_ARC4, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_AES_ECB, SIZE_BIT_IN_BYTES(192)}, - {CPA_CY_SYM_CIPHER_AES_CBC, SIZE_BIT_IN_BYTES(256)}, - {CPA_CY_SYM_CIPHER_AES_CTR, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_AES_CCM, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_AES_GCM, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_DES_ECB, SIZE_BIT_IN_BYTES(64)}, - {CPA_CY_SYM_CIPHER_DES_CBC, SIZE_BIT_IN_BYTES(64)}, - {CPA_CY_SYM_CIPHER_3DES_ECB, SIZE_BIT_IN_BYTES(192)}, - {CPA_CY_SYM_CIPHER_3DES_CBC, SIZE_BIT_IN_BYTES(192)}, - {CPA_CY_SYM_CIPHER_3DES_CTR, SIZE_BIT_IN_BYTES(192)}, - {CPA_CY_SYM_CIPHER_KASUMI_F8, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_SNOW3G_UEA2, SIZE_BIT_IN_BYTES(128)}, - {CPA_CY_SYM_CIPHER_AES_F8, SIZE_BIT_IN_BYTES(256)}, - {CPA_CY_SYM_CIPHER_AES_XTS, SIZE_BIT_IN_BYTES(256)}, - {CPA_CY_SYM_CIPHER_ZUC_EEA3, SIZE_BIT_IN_BYTES(128)}}; - -const testSetupHash_t hashSetup[ALGCHAIN_HASH_NUM] = { - {CPA_CY_SYM_HASH_NONE, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_MD5, SIZE_BIT_IN_BYTES(192), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_SHA1, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_SHA224, SIZE_BIT_IN_BYTES(224), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_SHA256, SIZE_BIT_IN_BYTES(256), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_SHA384, SIZE_BIT_IN_BYTES(384), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_SHA512, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_AES_XCBC, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_AES_CCM, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_AES_GCM, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_KASUMI_F9, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_4}, - {CPA_CY_SYM_HASH_SNOW3G_UIA2, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_4}, - {CPA_CY_SYM_HASH_AES_CMAC, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_AES_GMAC, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_AES_CBC_MAC, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16}, - {CPA_CY_SYM_HASH_ZUC_EIA3, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_4}, - {CPA_CY_SYM_HASH_SHA3_256, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16}}; - -const Cpa32U algChainAlgs[][ALGCHAIN_HASH_NUM] = { - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}}; - -const Cpa32U cipherAlgs[CIPHER_ALG_NUM] = - {1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; -const Cpa32U hashAlgs[HASH_ALG_NUM] = - {1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, 15, 16}; + +#define CIPHER_ALGORITHM_LIST \ + { { 0, 0 }, \ + { CPA_CY_SYM_CIPHER_NULL, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_ARC4, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_AES_ECB, SIZE_BIT_IN_BYTES(192) }, \ + { CPA_CY_SYM_CIPHER_AES_CBC, SIZE_BIT_IN_BYTES(256) }, \ + { CPA_CY_SYM_CIPHER_AES_CTR, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_AES_CCM, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_AES_GCM, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_DES_ECB, SIZE_BIT_IN_BYTES(64) }, \ + { CPA_CY_SYM_CIPHER_DES_CBC, SIZE_BIT_IN_BYTES(64) }, \ + { CPA_CY_SYM_CIPHER_3DES_ECB, SIZE_BIT_IN_BYTES(192) }, \ + { CPA_CY_SYM_CIPHER_3DES_CBC, SIZE_BIT_IN_BYTES(192) }, \ + { CPA_CY_SYM_CIPHER_3DES_CTR, SIZE_BIT_IN_BYTES(192) }, \ + { CPA_CY_SYM_CIPHER_KASUMI_F8, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_SNOW3G_UEA2, SIZE_BIT_IN_BYTES(128) }, \ + { CPA_CY_SYM_CIPHER_AES_F8, SIZE_BIT_IN_BYTES(256) }, \ + { CPA_CY_SYM_CIPHER_AES_XTS, SIZE_BIT_IN_BYTES(256) }, \ + { CPA_CY_SYM_CIPHER_ZUC_EEA3, SIZE_BIT_IN_BYTES(128) } }; +#define HASH_ALGORITHM_LIST \ + { { CPA_CY_SYM_HASH_NONE, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_MD5, SIZE_BIT_IN_BYTES(192), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_SHA1, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_SHA224, SIZE_BIT_IN_BYTES(224), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_SHA256, SIZE_BIT_IN_BYTES(256), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_SHA384, SIZE_BIT_IN_BYTES(384), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_SHA512, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_AES_XCBC, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_AES_CCM, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_AES_GCM, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_KASUMI_F9, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_4 }, \ + { CPA_CY_SYM_HASH_SNOW3G_UIA2, \ + SIZE_BIT_IN_BYTES(128), \ + DIGEST_LENGTH_4 }, \ + { CPA_CY_SYM_HASH_AES_CMAC, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_AES_GMAC, SIZE_BIT_IN_BYTES(512), DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_AES_CBC_MAC, \ + SIZE_BIT_IN_BYTES(128), \ + DIGEST_LENGTH_16 }, \ + { CPA_CY_SYM_HASH_ZUC_EIA3, SIZE_BIT_IN_BYTES(128), DIGEST_LENGTH_4 }, \ + { CPA_CY_SYM_HASH_SHA3_256, \ + SIZE_BIT_IN_BYTES(128), \ + DIGEST_LENGTH_16 } }; +#define ALGORITHM_CHAIN_BIT_MASK \ + { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, \ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }, \ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1 }, \ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 } }; +#define CIPHER_ALGORITHM_NUM \ + { 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; +#define HASH_ALGORITHM_NUM { 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, 15, 16 }; + + +const testSetupCipher_t cipherSetup[ALGCHAIN_CIPHER_NUM] = + CIPHER_ALGORITHM_LIST; +const testSetupHash_t hashSetup[ALGCHAIN_HASH_NUM] = HASH_ALGORITHM_LIST; +const Cpa32U algChainAlgs[][ALGCHAIN_HASH_NUM] = ALGORITHM_CHAIN_BIT_MASK; +const Cpa32U cipherAlgs[CIPHER_ALG_NUM] = CIPHER_ALGORITHM_NUM; +const Cpa32U hashAlgs[HASH_ALG_NUM] = HASH_ALGORITHM_NUM; extern CpaStatus getCryptoInstanceMapping(void); extern Cpa16U numInstances_g; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.h b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.h index c27ee108..caf03887 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_common.h @@ -93,9 +93,12 @@ #define HASH_ALG_NUM (13) #define ALGCHAIN_CIPHER_NUM (18) #define ALGCHAIN_HASH_NUM (17) + + #define SIZE_BIT_IN_BYTES(bits) ((bits + 7) / 8) #define DIGEST_LENGTH_16 (16) #define DIGEST_LENGTH_4 (4) +#define DIGEST_LENGTH_8 (8) #if CY_API_VERSION_AT_LEAST(2, 2) // Test config struct diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_dp.c b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_dp.c index d5157ec3..1158f986 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_dp.c +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/crypto/cpa_sample_code_sym_update_dp.c @@ -93,9 +93,9 @@ Cpa32U symDpPollingInterval_g = SYM_DP_OPS_DEFAULT_POLLING_INTERVAL; #if CY_API_VERSION_AT_LEAST(2, 2) -void symDpPerformUpdateCallback(CpaCySymDpOpData *pOpData, - CpaStatus status, - CpaBoolean verifyResult) +static void symDpPerformUpdateCallback(CpaCySymDpOpData *pOpData, + CpaStatus status, + CpaBoolean verifyResult) { /* pCallbacktag in the pOpData structure is used to store * index of to the perf_data_t associated the thread */ @@ -1447,7 +1447,8 @@ static CpaStatus updatePerformDp(symmetric_test_params_t *setup) return status; } -void sampleSymmetricDpUpdatePerformance(single_thread_test_data_t *testSetup) +static void sampleSymmetricDpUpdatePerformance( + single_thread_test_data_t *testSetup) { symmetric_test_params_t updateTestSetup; symmetric_test_params_t *pSetup = 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 e2d9a9af..f87e4d0b 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 @@ -79,11 +79,17 @@ extern void symPerformCallback(void *pCallbackTag, void *pOpData, CpaBufferList *pDstBuffer, CpaBoolean verifyResult); +CpaStatus cipherNewPerformanceTest(CpaBoolean mode, + Cpa32U mask, + Cpa32U bufferSize, + Cpa32U numBuffers, + Cpa32U numLoops); +void qatSymmetricPerformance(single_thread_test_data_t *testSetup); /*allocates buffers store a file for compression. The buffers are sent to * hardware, performance is recorded and stored in the setup parameter * the sample code framework prints out results after the thread completes*/ -CpaStatus scSymPoc(symmetric_test_params_t *setup_sym) +static CpaStatus scSymPoc(symmetric_test_params_t *setup_sym) { CpaStatus status = CPA_STATUS_SUCCESS; Cpa32U *testBufferSize = setup_sym->packetSizeInBytesArray; @@ -544,7 +550,7 @@ void qatSymmetricPerformance(single_thread_test_data_t *testSetup) sampleCodeThreadComplete(testSetup->threadID); } -CpaStatus setupNewSymmetricTest( +static CpaStatus setupNewSymmetricTest( CpaCySymOp opType, CpaCySymCipherAlgorithm cipherAlg, Cpa32U cipherKeyLengthInBytes, 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 8378d9bb..441e4d6d 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 @@ -690,7 +690,8 @@ CpaStatus qatSymOpDataSetup(symmetric_test_params_t *pSetup, pSetup->packetSizeInBytesArray[idx]; } - if (CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm) + if ((CPA_CY_SYM_CIPHER_AES_CCM == cipherAlgorithm) && + (CPA_CY_SYM_HASH_AES_GMAC != hashAlgorithm)) { /*generate a random IV*/ generateRandomData(&(pOpdata[idx].pIv[1]), 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 a5064431..cdd66d44 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 @@ -237,9 +237,15 @@ volatile CpaBoolean enableReadInstance_g = CPA_FALSE; /* 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; +CpaStatus setHwVerify(CpaBoolean val); +CpaStatus setSwWrite(CpaBoolean val); +CpaStatus setKeyCorrupt(CpaBoolean val); +CpaStatus enableReadInstance(CpaBoolean val); + CpaStatus setDcNsFlag(CpaBoolean val) { if (val != 0) @@ -788,6 +794,7 @@ CpaStatus startThreads(void) CpaStatus waitForThreadCompletion(void) { CpaStatus status = CPA_STATUS_SUCCESS; + CpaStatus statusPrintFunc = CPA_STATUS_SUCCESS; Cpa32U i = 0; stats_print_func_t statsPrintFunc; FUNC_ENTRY(); @@ -845,7 +852,7 @@ CpaStatus waitForThreadCompletion(void) statsPrintFunc = *(testSetupData_g[i].statsPrintFunc); if (statsPrintFunc != NULL) { - statsPrintFunc(&testSetupData_g[i]); + statusPrintFunc = statsPrintFunc(&testSetupData_g[i]); } else { @@ -861,6 +868,10 @@ CpaStatus waitForThreadCompletion(void) PRINT("---------------------------------------\n\n"); } } + if (statusPrintFunc == CPA_STATUS_FAIL) + { + status = CPA_STATUS_FAIL; + } #ifndef NEWDISLAY PRINT("---------------------------------------\n\n"); #endif 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 c1aab164..8fb97e0f 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 @@ -234,6 +234,8 @@ CpaStatus setUseStaticPrime(int val); CpaStatus setDcNsFlag(CpaBoolean val); extern volatile CpaBoolean isNsRequest_g; +CpaStatus setDataIntegrity(CpaBoolean val); +CpaStatus setDataIntegrityVerify(CpaBoolean val); CpaStatus printReliability(void); extern volatile CpaBoolean fineTune_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 0c269b30..53a6e9c6 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 @@ -87,7 +87,12 @@ #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +// check GLIBC version used. +#define GLIBC_VERSION_AT_LEAST(major, minor) \ + (__GLIBC__ > major || (__GLIBC__ == major && __GLIBC_MINOR__ >= minor)) + +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) && \ + (GLIBC_VERSION_AT_LEAST(2, 25))) #include #endif @@ -120,12 +125,19 @@ static char *firmwarePath = SAMPLE_CODE_CORPUS_PATH; sample_code_thread_barrier_t barr; -#define UPPER_HALF_OF_REGISTER (32) +extern CpaStatus getCorpusFile(Cpa8U **ppSrcBuff, char *filename, Cpa32U *size); +extern CpaStatus getCompressedFile(Cpa8U **ppSrcBuff, + char *filename, + Cpa32U *size); +extern CpaStatus calcSWDigest(CpaFlatBuffer *msg, + CpaFlatBuffer *digest, + CpaCySymHashAlgorithm hashAlg); -// check GLIBC version used. -#define GLIBC_VERSION_AT_LEAST(major, minor) \ - (__GLIBC__ > major || (__GLIBC__ == major && __GLIBC_MINOR__ >= minor)) +#define UPPER_HALF_OF_REGISTER (32) + +#if ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)) || \ + (!GLIBC_VERSION_AT_LEAST(2, 25))) static __inline__ Cpa64U sampleCoderdtsc(void) { volatile unsigned long a, d; @@ -133,6 +145,7 @@ static __inline__ Cpa64U sampleCoderdtsc(void) asm volatile("rdtsc" : "=a"(a), "=d"(d)); return (((Cpa64U)a) | (((Cpa64U)d) << UPPER_HALF_OF_REGISTER)); } +#endif ChipRec_u64 getCPUTick() { @@ -280,12 +293,14 @@ Cpa32U sampleCodeGetCpuFreq() void generateRandomData(Cpa8U *pWriteRandData, Cpa32U lengthOfRand) { Cpa32U i = 0; -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) +#if ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)) || \ + (!GLIBC_VERSION_AT_LEAST(2, 25))) srand(sampleCoderdtsc()); #endif for (i = 0; i < lengthOfRand; i++) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)) && \ + (GLIBC_VERSION_AT_LEAST(2, 25))) ssize_t status = getrandom(&pWriteRandData[i], sizeof(Cpa8U), GRND_NONBLOCK); if (status == -1) @@ -958,6 +973,7 @@ CpaStatus getCorpusFile(Cpa8U **ppSrcBuff, char *filename, Cpa32U *size) return CPA_STATUS_SUCCESS; } + CpaStatus calcSWDigest(CpaFlatBuffer *msg, CpaFlatBuffer *digest, CpaCySymHashAlgorithm hashAlg) @@ -994,6 +1010,7 @@ CpaStatus calcSWDigest(CpaFlatBuffer *msg, } } + CpaStatus getCompressedFile(Cpa8U **ppSrcBuff, char *filename, Cpa32U *size) { FILE *corpusFilePtr = NULL; diff --git a/quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem.h b/quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem.h index 9dced94c..dc3c2eff 100644 --- a/quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem.h +++ b/quickassist/lookaside/access_layer/src/sample_code/performance/qae/qae_mem.h @@ -385,5 +385,9 @@ void qaeMemFreeNUMA(void **ptr); void qaeMemFree(void **ptr); void printMemAllocations(void); +int register_mem_device_driver(void); +void unregister_mem_device_driver(void); +int qae_mem_init(void); +void qae_mem_exit(void); #endif diff --git a/quickassist/lookaside/access_layer/src/user/sal_user.c b/quickassist/lookaside/access_layer/src/user/sal_user.c index 8b7e56e4..5bfd08b0 100644 --- a/quickassist/lookaside/access_layer/src/user/sal_user.c +++ b/quickassist/lookaside/access_layer/src/user/sal_user.c @@ -285,6 +285,10 @@ CpaStatus icp_sal_userStop() { start_ref_count -= 1; } + if (0 == start_ref_count) + { + start_ref_pid = -1; + } if (osalMutexUnlock(&sync_lock)) { LAC_LOG_ERROR("Mutex unlock failed\n"); @@ -293,7 +297,6 @@ CpaStatus icp_sal_userStop() if (0 == start_ref_count) { osalMutexDestroy(&sync_lock); - start_ref_pid = -1; } return status; diff --git a/quickassist/lookaside/access_layer/src/user/sal_user_congestion_mgmt.c b/quickassist/lookaside/access_layer/src/user/sal_user_congestion_mgmt.c index b99edffb..7cb79c12 100644 --- a/quickassist/lookaside/access_layer/src/user/sal_user_congestion_mgmt.c +++ b/quickassist/lookaside/access_layer/src/user/sal_user_congestion_mgmt.c @@ -84,6 +84,24 @@ #include "lac_sal.h" #include "sal_service_state.h" +/* + ***************************************************************************** + * @ingroup SalCongsMgmt + * Symmetric get in-flight requests + * + * @description + * This function is used to fetch in-flight and max in-flight request + * counts for the given symmetric instance handle. + * + * @param[in] instanceHandle Symmetric instance handle + * @param[out] maxInflightRequests Max in-flight request count + * @param[out] numInflightRequests Current in-flight request count + * + * @retval CPA_STATUS_SUCCESS Function executed successfully + * @retval CPA_STATUS_FAIL Function failed + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter + * + *****************************************************************************/ CpaStatus icp_sal_SymGetInflightRequests(CpaInstanceHandle instanceHandle, Cpa32U *maxInflightRequests, Cpa32U *numInflightRequests) @@ -120,6 +138,24 @@ CpaStatus icp_sal_AsymGetInflightRequests(CpaInstanceHandle instanceHandle, numInflightRequests); } +/* + ***************************************************************************** + * @ingroup SalCongsMgmt + * Symmetric data plane get in-flight requests + * + * @description + * Data plane API to fetch in-flight and max in-flight request counts + * for the given symmetric instance handle. + * + * @param[in] instanceHandle Symmetric instance handle + * @param[out] maxInflightRequests Max in-flight request count + * @param[out] numInflightRequests Current in-flight request count + * + * @retval CPA_STATUS_SUCCESS Function executed successfully + * @retval CPA_STATUS_FAIL Function failed + * @retval CPA_STATUS_INVALID_PARAM Invalid parameter + * + *****************************************************************************/ CpaStatus icp_sal_dp_SymGetInflightRequests(CpaInstanceHandle instanceHandle, Cpa32U *maxInflightRequests, Cpa32U *numInflightRequests) diff --git a/quickassist/lookaside/access_layer/src/user/sal_user_dyn_instance.c b/quickassist/lookaside/access_layer/src/user/sal_user_dyn_instance.c index a3460e66..bbdbccd8 100644 --- a/quickassist/lookaside/access_layer/src/user/sal_user_dyn_instance.c +++ b/quickassist/lookaside/access_layer/src/user/sal_user_dyn_instance.c @@ -69,1025 +69,90 @@ * @description * This file contains implementation of functions * to allocate/free dynamic crypto/compression instances + * These APIs have been deprecated. * *****************************************************************************/ /* QAT-API includes */ #include "cpa.h" -/* Osal includes */ -#include "Osal.h" - -/* ADF includes */ -#include "icp_adf_init.h" -#include "icp_accel_devices.h" -#include "icp_adf_accel_mgr.h" -#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" - -/* SAL includes */ -#include "icp_sal_user.h" -#include "lac_log.h" -#include "lac_mem.h" -#include "lac_mem_pools.h" -#include "lac_list.h" -#include "lac_sal_types_crypto.h" -#include "sal_types_compression.h" -#include "lac_sal.h" -#include "lac_sal_ctrl.h" -#include "sal_string_parse.h" - -#define PENDING_DELAY 1 -#define ALL_DEVPKGS 0xffffffff - -static pthread_mutex_t sync_multi_lock = PTHREAD_MUTEX_INITIALIZER; - -STATIC CpaStatus -do_userGetAvailableNumDynInstances(Cpa32U *pNumInstances, - sal_service_type_t serviceType, - Cpa32U devPkgID) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - Cpa32U x = 0; - - Cpa16U numAccelDev = 0; /* the number of devices (icp_accel_dev_t). */ - icp_accel_dev_t **pAdfInsts = NULL; /* store the address for - all adf device instances' pointers. - here, it's the array - of (icp_accel_dev_t *) */ - icp_accel_dev_t *pDevice = NULL; /* store the address of - one adf device instance */ - - Cpa32U num = 0; - Cpa32U availableInstCnt = 0; /* the available number of sal service - object instances (sal_service_t). */ - Cpa32U capabilitiesMask = 0; - adf_service_type_t stype = ADF_SERVICE_MAX; - char adfGetParam[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - Cpa32U *pDevPkgId = NULL; - - /* Get the number of accel_dev in the system */ - status = icp_adf_getNumInstances(&numAccelDev); - LAC_CHECK_STATUS(status); - - /* Allocate memory to store addr of accel_devs */ - pAdfInsts = osalMemAlloc(numAccelDev * sizeof(icp_accel_dev_t *)); - if (NULL == pAdfInsts) - { - LAC_LOG_ERROR("Failed to allocate dev instance memory\n"); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pAdfInsts, 0, (numAccelDev * sizeof(icp_accel_dev_t *))); - numAccelDev = 0; -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - capabilitiesMask = ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | - ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; - stype = ADF_SERVICE_CRYPTO; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - capabilitiesMask = ICP_ACCEL_CAPABILITIES_COMPRESSION; - stype = ADF_SERVICE_COMPRESS; - } - /* Get devices with crypto or compression service enabled */ - status = icp_adf_getAllAccelDevByCapabilities( - capabilitiesMask, pAdfInsts, &numAccelDev); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR("Can not find device with sufficient capabilities\n"); - osalMemFree(pAdfInsts); - return CPA_STATUS_FAIL; - } - /* Allocate memory to store addr of devPkgId */ - pDevPkgId = osalMemAlloc(numAccelDev * sizeof(Cpa32U)); - if (NULL == pDevPkgId) - { - LAC_LOG_ERROR("Failed to allocate devPkgId memory\n"); - osalMemFree(pAdfInsts); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pDevPkgId, 0xff, (numAccelDev * sizeof(Cpa32U))); - - /* Check if there are enough available dyn cy or dc instances */ - availableInstCnt = 0; - for (x = 0; x < numAccelDev; x++) - { - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - if (NULL == pDevice->pSalHandle) - { - /* Try the next device */ - continue; - } - if (devPkgID != ALL_DEVPKGS) - { - status = icp_adf_cfgGetParamValue( - pDevice, LAC_CFG_SECTION_GENERAL, ADF_DEV_PKG_ID, adfGetParam); - if (CPA_STATUS_SUCCESS != status) - { - /* Try the next device */ - continue; - } - pDevPkgId[x] = Sal_Strtoul(adfGetParam, NULL, SAL_CFG_BASE_DEC); - if (pDevPkgId[x] != devPkgID) - { - /* Try the next device */ - continue; - } - } - status = icp_adf_getNumAvailDynInstance(pDevice, stype, &num); - if (CPA_STATUS_SUCCESS != status) - { - /* Try the next device */ - continue; - } - availableInstCnt += num; - } - *pNumInstances = availableInstCnt; - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - return CPA_STATUS_SUCCESS; -} - #ifndef ICP_DC_ONLY CpaStatus icp_sal_userCyGetAvailableNumDynInstances(Cpa32U *pNumCyInstances) { - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pNumCyInstances); - - return do_userGetAvailableNumDynInstances( - pNumCyInstances, SAL_SERVICE_TYPE_CRYPTO, ALL_DEVPKGS); -} -#endif - -CpaStatus icp_sal_userDcGetAvailableNumDynInstances(Cpa32U *pNumDcInstances) -{ - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pNumDcInstances); - - return do_userGetAvailableNumDynInstances( - pNumDcInstances, SAL_SERVICE_TYPE_COMPRESSION, ALL_DEVPKGS); + return CPA_STATUS_UNSUPPORTED; } -#ifndef ICP_DC_ONLY CpaStatus icp_sal_userCyGetAvailableNumDynInstancesByDevPkg( Cpa32U *pNumCyInstances, Cpa32U devPkgID) { - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pNumCyInstances); - - return do_userGetAvailableNumDynInstances( - pNumCyInstances, SAL_SERVICE_TYPE_CRYPTO, devPkgID); + return CPA_STATUS_UNSUPPORTED; } -#endif - -CpaStatus icp_sal_userDcGetAvailableNumDynInstancesByDevPkg( - Cpa32U *pNumDcInstances, - Cpa32U devPkgID) -{ - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pNumDcInstances); - return do_userGetAvailableNumDynInstances( - pNumDcInstances, SAL_SERVICE_TYPE_COMPRESSION, devPkgID); -} - -#ifndef ICP_DC_ONLY CpaStatus icp_sal_userCyGetAvailableNumDynInstancesByPkgAccel( Cpa32U *pNumCyInstances, Cpa32U devPkgID, Cpa32U accelerator_number) { - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pNumCyInstances); - if (accelerator_number > 0) - { - LAC_LOG_ERROR1("accelerator_number is invalid(%u)\n", - accelerator_number); - return CPA_STATUS_INVALID_PARAM; - } - - return icp_sal_userCyGetAvailableNumDynInstancesByDevPkg(pNumCyInstances, - devPkgID); -} -#endif - -/* allocate sal service instances */ -STATIC CpaStatus do_userInstancesAlloc(Cpa32U numInstances, - sal_service_type_t serviceType, - CpaInstanceHandle *pInstances, - Cpa32U devPkgID) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - - Cpa16U numAccelDev = 0; /* the number of devices (icp_accel_dev_t). */ - icp_accel_dev_t **pAdfInsts = NULL; /* store the address for - all adf device instances' pointers. - here, it's the array - of (icp_accel_dev_t *) */ - icp_accel_dev_t *pDevice = NULL; /* store the address of - one adf device instance */ - Cpa32U num = 0; - Cpa32U availableInstCnt = 0; /* the available number of sal service - object instances (sal_service_t). */ - Cpa32U instanceId = ADF_CFG_NO_INSTANCE; /* the id of - sal service instance */ - sal_list_t **pSalLists = NULL; /* store the address of - sal service list head pointers - of all device. - here, it's the array of (sal_list_t *) */ - sal_list_t *pDynServices = NULL; /* store the address of - one sal service list of one device. - here, sal service list is the list - of (sal_service_t *) */ - sal_service_t *pInst = NULL; /* store the address of - one sal service object */ - - sal_list_t *pTailList = NULL; - sal_list_t *pHeadList = NULL; - sal_list_t *pList = NULL; - sal_list_t **pNewLists = NULL; /* store the address of all new added - sal list head pointers - in pServiceContainer->crypto_services, - or pServiceContainer->compression_services */ - sal_list_t *pNextElement = NULL; - Cpa32U enabledServices = 0; - Cpa32U i = 0; - Cpa32U x = 0; - Cpa32U *pNumSals = 0; - Cpa32U capabilitiesMask = 0; - adf_service_type_t stype = ADF_SERVICE_MAX; - sal_t *pServiceContainer = NULL; - sal_list_t *pServiceList = NULL; - char adfGetParam[ADF_CFG_MAX_VAL_LEN_IN_BYTES] = {0}; - Cpa32U *pDevPkgId = NULL; - - /* Get the number of accel_dev in the system */ - status = icp_adf_getNumInstances(&numAccelDev); - LAC_CHECK_STATUS(status); - - /* Allocate memory to store addr of accel_devs */ - pAdfInsts = osalMemAlloc(numAccelDev * sizeof(icp_accel_dev_t *)); - if (NULL == pAdfInsts) - { - LAC_LOG_ERROR("Failed to allocate dev instance memory\n"); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pAdfInsts, 0, (numAccelDev * sizeof(icp_accel_dev_t *))); - numAccelDev = 0; -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - capabilitiesMask = ICP_ACCEL_CAPABILITIES_CRYPTO_ASYMMETRIC | - ICP_ACCEL_CAPABILITIES_CRYPTO_SYMMETRIC; - stype = ADF_SERVICE_CRYPTO; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - capabilitiesMask = ICP_ACCEL_CAPABILITIES_COMPRESSION; - stype = ADF_SERVICE_COMPRESS; - } - /* Get devices with crypto or compression service enabled */ - status = icp_adf_getAllAccelDevByCapabilities( - capabilitiesMask, pAdfInsts, &numAccelDev); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR("Can not find device with sufficient capabilities\n"); - osalMemFree(pAdfInsts); - return CPA_STATUS_FAIL; - } - /* Allocate memory to store addr of devPkgId */ - pDevPkgId = osalMemAlloc(numAccelDev * sizeof(Cpa32U)); - if (NULL == pDevPkgId) - { - LAC_LOG_ERROR("Failed to allocate devPkgId memory\n"); - osalMemFree(pAdfInsts); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pDevPkgId, 0xff, (numAccelDev * sizeof(Cpa32U))); - - /* Check if there are enough available dyn cy or dc instances */ - availableInstCnt = 0; - for (x = 0; x < numAccelDev; x++) - { - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - if (NULL == pDevice->pSalHandle) - { - /* Try the next device */ - continue; - } - - if (devPkgID != ALL_DEVPKGS) - { - status = icp_adf_cfgGetParamValue( - pDevice, LAC_CFG_SECTION_GENERAL, ADF_DEV_PKG_ID, adfGetParam); - if (CPA_STATUS_SUCCESS != status) - { - /* Try the next device */ - continue; - } - pDevPkgId[x] = Sal_Strtoul(adfGetParam, NULL, SAL_CFG_BASE_DEC); - if (pDevPkgId[x] != devPkgID) - { - /* Try the next device */ - continue; - } - } - status = icp_adf_getNumAvailDynInstance(pDevice, stype, &num); - if (CPA_STATUS_SUCCESS != status) - { - /* Try the next device */ - continue; - } - availableInstCnt += num; - } - if (availableInstCnt < numInstances) - { - LAC_LOG_ERROR("No enough available dyn cy or dc instances\n"); - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - return CPA_STATUS_FAIL; - } - - /* Allocate memory to store addr of sal lists */ - pSalLists = osalMemAlloc(numAccelDev * sizeof(sal_list_t *)); - if (NULL == pSalLists) - { - LAC_LOG_ERROR("Failed to allocate sal list memory\n"); - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pSalLists, 0, (numAccelDev * sizeof(sal_list_t *))); - - pNumSals = osalMemAlloc(numAccelDev * sizeof(Cpa32U)); - if (NULL == pNumSals) - { - LAC_LOG_ERROR("Failed to allocate pNumSals\n"); - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - osalMemFree(pSalLists); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pNumSals, 0, (numAccelDev * sizeof(Cpa32U))); - - /* Allocate memory to store addr of the new added sal lists - * in pServiceContainer->crypto_services - * or pServiceContainer->compression_services */ - pNewLists = osalMemAlloc(numAccelDev * sizeof(sal_list_t *)); - if (NULL == pNewLists) - { - LAC_LOG_ERROR("Failed to allocate sal list memory\n"); - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - osalMemFree(pSalLists); - osalMemFree(pNumSals); - return CPA_STATUS_RESOURCE; - } - osalMemSet(pNewLists, 0, (numAccelDev * sizeof(sal_list_t *))); - - do - { - /* Allocate instances from multiple devices - * with crypto or compression service enabled. - * Allocated instances are saved in - * pAdfInsts[x]->pSalHandle->crypto_services, - * or pAdfInsts[x]->pSalHandle->compression_services */ - for (x = 0, i = 0; x < numAccelDev; x++) - { - pDynServices = NULL; - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - - if (devPkgID != ALL_DEVPKGS) - { - if (pDevPkgId[x] != devPkgID) - { - /* Try the next device */ - continue; - } - } - if (NULL == pDevice->pSalHandle) - { - /* Try the next device */ - continue; - } - - /* Get enabled services from device cfg data */ - status = SalCtrl_GetEnabledServices(pDevice, &enabledServices); - if (CPA_STATUS_SUCCESS != status) - { - /* Try the next device */ - continue; - } - if (CPA_FALSE == - SalCtrl_IsServiceEnabled(enabledServices, serviceType)) - { - /* Try the next device */ - continue; - } - - /* Create sal crypto or compression service instance described - * in DYN section of cfg file */ - for (; i < numInstances; i++) - { - instanceId = ADF_CFG_NO_INSTANCE; - pInst = NULL; - /* Get an available instance from dyn instance pool - * for the device */ - status = icp_adf_getDynInstance(pDevice, stype, &instanceId); - if ((CPA_STATUS_SUCCESS != status) || - (ADF_CFG_NO_INSTANCE == instanceId)) - { /* No available instance in the device */ - break; - } - status = SalCtrl_ServiceCreate(serviceType, instanceId, &pInst); - if ((CPA_STATUS_SUCCESS != status) || (NULL == pInst)) - { - icp_adf_putDynInstance(pDevice, stype, instanceId); - break; - } - /* SalCtrl_ServiceCreate will set pInst->is_dyn - * to be CPA_FALSE by default. - * Set pInst->is_dyn to be CPA_TRUE, so as to get cfg data - * from DYN section. */ - pInst->is_dyn = CPA_TRUE; - pInst->capabilitiesMask = pDevice->accelCapabilitiesMask; - status = SalList_add(&pDynServices, &pTailList, pInst); - if (CPA_STATUS_SUCCESS != status) - { - icp_adf_putDynInstance(pDevice, stype, instanceId); - osalMemFree(pInst); - break; - } - } - pSalLists[x] = pDynServices; - if ((CPA_STATUS_SUCCESS != status) || - (ADF_CFG_NO_INSTANCE == instanceId)) - { - /* Try the next device */ - continue; - } - } - if (i < numInstances) - { - LAC_LOG_ERROR1("Fail to get %d dyn cy or dc instances\n", - numInstances); - status = CPA_STATUS_FAIL; - break; - } - - for (x = 0; x < numAccelDev; x++) - { - if (devPkgID != ALL_DEVPKGS) - { - if (pDevPkgId[x] != devPkgID) - { - /* Try the next device */ - continue; - } - } - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - /* Call init function for each service instance */ - SAL_FOR_EACH(pSalLists[x], sal_service_t, pDevice, init, status); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR1( - "Failed to initialise all instances for icp_dev%d\n", - ((icp_accel_dev_t *)pAdfInsts[x])->accelId); - break; - } - - /* Call Start function for each service instance */ - SAL_FOR_EACH(pSalLists[x], sal_service_t, pDevice, start, status); - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR1("Failed to start all instances for icp_dev%d\n", - ((icp_accel_dev_t *)pAdfInsts[x])->accelId); - break; - } - } - if (CPA_STATUS_SUCCESS != status) - { - break; - } - - pTailList = NULL; - pHeadList = NULL; - - for (x = 0, i = 0; x < numAccelDev; x++) - { /* Add initialized sal crypto or compression service instance - * from pSalLists[x] into - * pServiceContainer->crypto_services - * or pServiceContainer->compression_services of each device - * pAdfInsts[x] */ - if (devPkgID != ALL_DEVPKGS) - { - if (pDevPkgId[x] != devPkgID) - { - /* Try the next device */ - continue; - } - } - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - if (NULL == pDevice->pSalHandle) - { - /* Try the next device */ - continue; - } - pServiceContainer = pDevice->pSalHandle; -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - pServiceList = pServiceContainer->crypto_services; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - pServiceList = pServiceContainer->compression_services; - } - /* Move pTailList point to the end - * of the existing pServiceContainer->crypto_services, - * or pServiceContainer->compression_services */ - pTailList = pServiceList; - if (NULL != pServiceList) - { - pTailList = pServiceList; - while (SalList_next(pTailList)) - { - pTailList = SalList_next(pTailList); - } - } - pHeadList = pTailList; - - /* save the address of the end - * of the existing pServiceContainer->crypto_services, - * or pServiceContainer->compression_services, - * which is the new added list head pointer */ - pNewLists[x] = pHeadList; - - pDynServices = pSalLists[x]; - pNumSals[x] = 0; - while (pDynServices) - { - pInst = (sal_service_t *)SalList_getObject(pDynServices); -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - status = SalList_add( - &pServiceContainer->crypto_services, &pTailList, pInst); - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - status = - SalList_add(&pServiceContainer->compression_services, - &pTailList, - pInst); - } - if (CPA_STATUS_SUCCESS != status) - { - break; - } - pNumSals[x]++; - pInstances[i++] = (CpaInstanceHandle)pInst; - pDynServices = SalList_next(pDynServices); - } - if (CPA_STATUS_SUCCESS != status) - { - LAC_LOG_ERROR1("Failed to add instances for icp_dev%d\n", - ((icp_accel_dev_t *)pAdfInsts[x])->accelId); - break; - } - } - break; - } while (0); - - /* Handle error */ - if (CPA_STATUS_SUCCESS != status) - { - for (x = 0; x < numAccelDev; x++) - { - pList = pSalLists[x]; - pDevice = (icp_accel_dev_t *)pAdfInsts[x]; - while (pList) - { - pInst = (sal_service_t *)SalList_getObject(pList); - if (NULL == pInst) - { - pList = SalList_next(pList); - continue; - } - if (SAL_SERVICE_STATE_RUNNING == pInst->state) - { - status = pInst->stop(pDevice, pInst); - } - if (CPA_STATUS_RETRY == status) - { - osalSleep(PENDING_DELAY); - } - - if ((SAL_SERVICE_STATE_INITIALIZED == pInst->state) || - (SAL_SERVICE_STATE_SHUTTING_DOWN == pInst->state) || - (SAL_SERVICE_STATE_RESTARTING == pInst->state)) - { - pInst->shutdown(pDevice, pInst); - } - icp_adf_putDynInstance(pDevice, stype, pInst->instance); - pList = SalList_next(pList); - } - SalList_free(&pSalLists[x]); - if (NULL != pNewLists[x]) - { - /* Free new added list in pServiceContainer->crypto_services, - * or pServiceContainer->compression_services, - * sal object should have been freed when free pSalLists[x] */ - pList = SalList_next(pNewLists[x]); - while ((NULL != pList) && (pNumSals[x]-- > 0)) - { - pNextElement = SalList_next(pList); - LAC_OS_FREE(pList); - pList = pNextElement; - } - pNewLists[x]->next = pList; - } - } - for (i = 0; i < numInstances; i++) - { - pInstances[i] = NULL; - } - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - osalMemFree(pSalLists); - osalMemFree(pNewLists); - osalMemFree(pNumSals); - return status; - } - - for (x = 0; x < numAccelDev; x++) - { - /* Delete sal object from pSalLists[x] to avoid free it - * when free pSalLists[x] as it has been added into - * pServiceContainer->crypto_services - * or pServiceContainer->compression_services for each device */ - pList = pSalLists[x]; - while (pList) - { - SalList_delObject(&pList); - pList = SalList_next(pList); - } - SalList_free(&pSalLists[x]); - } - osalMemFree(pAdfInsts); - osalMemFree(pDevPkgId); - osalMemFree(pSalLists); - osalMemFree(pNewLists); - osalMemFree(pNumSals); - return status; + return CPA_STATUS_UNSUPPORTED; } -#ifndef ICP_DC_ONLY -/* allocate crypto sal service instances */ CpaStatus icp_sal_userCyInstancesAlloc(Cpa32U numCyInstances, CpaInstanceHandle *pCyInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; - - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pCyInstances); - if (0 == numCyInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userInstancesAlloc( - numCyInstances, SAL_SERVICE_TYPE_CRYPTO, pCyInstances, ALL_DEVPKGS); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; -} -#endif - -/* allocate compression sal service instances */ -CpaStatus icp_sal_userDcInstancesAlloc(Cpa32U numDcInstances, - CpaInstanceHandle *pDcInstances) -{ - CpaStatus status = CPA_STATUS_SUCCESS; - - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pDcInstances); - if (0 == numDcInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userInstancesAlloc(numDcInstances, - SAL_SERVICE_TYPE_COMPRESSION, - pDcInstances, - ALL_DEVPKGS); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; + return CPA_STATUS_UNSUPPORTED; } -#ifndef ICP_DC_ONLY -/* allocate crypto sal service instances - * which are from the specific device package. */ CpaStatus icp_sal_userCyInstancesAllocByDevPkg(Cpa32U numCyInstances, CpaInstanceHandle *pCyInstances, Cpa32U devPkgID) { - CpaStatus status = CPA_STATUS_SUCCESS; - - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pCyInstances); - if (0 == numCyInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userInstancesAlloc( - numCyInstances, SAL_SERVICE_TYPE_CRYPTO, pCyInstances, devPkgID); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; + return CPA_STATUS_UNSUPPORTED; } -#endif -/* allocate compression sal service instances - * which are from the specific device package. */ -CpaStatus icp_sal_userDcInstancesAllocByDevPkg(Cpa32U numDcInstances, - CpaInstanceHandle *pDcInstances, - Cpa32U devPkgID) +CpaStatus icp_sal_userCyFreeInstances(Cpa32U numCyInstances, + CpaInstanceHandle *pCyInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; - - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pDcInstances); - if (0 == numDcInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userInstancesAlloc( - numDcInstances, SAL_SERVICE_TYPE_COMPRESSION, pDcInstances, devPkgID); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; + return CPA_STATUS_UNSUPPORTED; } -#ifndef ICP_DC_ONLY -/** - * Allocate crypto sal service instances - * which are from the specific device package and accelerator. - */ CpaStatus icp_sal_userCyInstancesAllocByPkgAccel( Cpa32U numCyInstances, CpaInstanceHandle *pCyInstances, Cpa32U devPkgID, Cpa32U accelerator_number) { - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pCyInstances); - if (accelerator_number > 0) - { - LAC_LOG_ERROR1("accelerator_number is invalid(%u)\n", - accelerator_number); - return CPA_STATUS_INVALID_PARAM; - } - return icp_sal_userCyInstancesAllocByDevPkg( - numCyInstances, pCyInstances, devPkgID); + return CPA_STATUS_UNSUPPORTED; } #endif -STATIC CpaStatus do_userFreeInstances(Cpa32U numInstances, - sal_service_type_t serviceType, - CpaInstanceHandle *pInstances) +CpaStatus icp_sal_userDcGetAvailableNumDynInstances(Cpa32U *pNumDcInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; -#ifndef ICP_DC_ONLY - sal_crypto_service_t *pCryptoService = NULL; -#endif - sal_compression_service_t *pCompressionService = NULL; - sal_service_t *pInst = NULL; /* store the address of - one sal service object */ - Cpa32U i = 0; - icp_accel_dev_t *pDevice = NULL; - sal_t *pServiceContainer = NULL; - - sal_list_t *pPreList = NULL; - sal_list_t *pList = NULL; - - adf_service_type_t stype = ADF_SERVICE_MAX; - sal_list_t *pServiceList = NULL; - Cpa16U deviceId = 0; - Cpa32U instanceId = 0; -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - stype = ADF_SERVICE_CRYPTO; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - stype = ADF_SERVICE_COMPRESS; - } - - for (i = 0; i < numInstances; i++) - { - if (NULL == pInstances[i]) - { - continue; - } -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - pCryptoService = (sal_crypto_service_t *)pInstances[i]; - deviceId = pCryptoService->pkgID; - instanceId = pCryptoService->generic_service_info.instance; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - pCompressionService = (sal_compression_service_t *)pInstances[i]; - deviceId = pCompressionService->pkgID; - instanceId = pCompressionService->generic_service_info.instance; - } - - pInst = (sal_service_t *)pInstances[i]; - pDevice = icp_adf_getAccelDevByAccelId(deviceId); - if (NULL == pDevice) - { - LAC_LOG_ERROR2("Can not find device%d for the instance%d\n", - deviceId, - instanceId); - continue; - } - /* stop crypto or compressioninstance */ - if (CPA_STATUS_RETRY == pInst->stop(pDevice, pInst)) - { - osalSleep(PENDING_DELAY); - } - /* shutdown crypto or compression instance */ - pInst->shutdown(pDevice, pInst); - - /* put crypto or cmopression instance - * into dyn crypto or compression instances pool */ - icp_adf_putDynInstance(pDevice, stype, pInst->instance); - - /* Remove crypto or compression instance - * from pServiceContainer->crypto_services, - * or pServiceContainer->compression_services, - * free crypto instance */ - pServiceContainer = pDevice->pSalHandle; - if (NULL == pServiceContainer) - { - continue; - } -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - pServiceList = pServiceContainer->crypto_services; - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - pServiceList = pServiceContainer->compression_services; - } - - if (NULL != pServiceList) - { - pList = pServiceList; - pPreList = pList; + return CPA_STATUS_UNSUPPORTED; +} - while (pList) - { - if ((((sal_service_t *)SalList_getObject(pList))->instance == - pInst->instance) && - (CPA_TRUE == - ((sal_service_t *)SalList_getObject(pList))->is_dyn)) - { -#ifndef ICP_DC_ONLY - if (SAL_SERVICE_TYPE_CRYPTO == serviceType) - { - SalList_del(&pServiceContainer->crypto_services, - &pPreList, - pList); - } -#endif - if (SAL_SERVICE_TYPE_COMPRESSION == serviceType) - { - SalList_del(&pServiceContainer->compression_services, - &pPreList, - pList); - } - pInstances[i] = NULL; - break; - } - pPreList = pList; - pList = (sal_list_t *)SalList_next(pList); - } - } - } - return status; +CpaStatus icp_sal_userDcGetAvailableNumDynInstancesByDevPkg( + Cpa32U *pNumDcInstances, + Cpa32U devPkgID) +{ + return CPA_STATUS_UNSUPPORTED; } -#ifndef ICP_DC_ONLY -CpaStatus icp_sal_userCyFreeInstances(Cpa32U numCyInstances, - CpaInstanceHandle *pCyInstances) +CpaStatus icp_sal_userDcInstancesAlloc(Cpa32U numDcInstances, + CpaInstanceHandle *pDcInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; + return CPA_STATUS_UNSUPPORTED; +} - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pCyInstances); - if (0 == numCyInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userFreeInstances( - numCyInstances, SAL_SERVICE_TYPE_CRYPTO, pCyInstances); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; +CpaStatus icp_sal_userDcInstancesAllocByDevPkg(Cpa32U numDcInstances, + CpaInstanceHandle *pDcInstances, + Cpa32U devPkgID) +{ + return CPA_STATUS_UNSUPPORTED; } -#endif CpaStatus icp_sal_userDcFreeInstances(Cpa32U numDcInstances, CpaInstanceHandle *pDcInstances) { - CpaStatus status = CPA_STATUS_SUCCESS; - - /* Input parameters check */ - LAC_CHECK_NULL_PARAM(pDcInstances); - if (0 == numDcInstances) - { - LAC_INVALID_PARAM_LOG("numInstances is 0"); - return CPA_STATUS_INVALID_PARAM; - } - if (pthread_mutex_lock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex lock failed\n"); - return CPA_STATUS_FAIL; - } - status = do_userFreeInstances( - numDcInstances, SAL_SERVICE_TYPE_COMPRESSION, pDcInstances); - if (pthread_mutex_unlock(&sync_multi_lock)) - { - LAC_LOG_ERROR("Mutex unlock failed\n"); - status = CPA_STATUS_FAIL; - } - return status; + return CPA_STATUS_UNSUPPORTED; } diff --git a/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h b/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h index 370d2af5..a063b020 100644 --- a/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h +++ b/quickassist/utilities/libusdm_drv/include/qae_mem_utils.h @@ -175,6 +175,24 @@ typedef struct dev_mem_info_s struct dev_mem_info_s *pNext_user_hash; /* user space only */ uint64_t padding_nextuh; }; +#ifdef ICP_THREAD_SPECIFIC_USDM + /* These pointers are required for adding and deleting slabs + * to/from TMP list. We cannot rely on existing pointers + * because those are actually being filled with relevant + * addresses given the slab was added to another lists. + * Please see ADD_ELEMENT_TO_END_LIST, ADD_ELEMENT_TO_END_LIST + * in usdm/include/qae_mem_utils.h + */ + union { + struct dev_mem_info_s *pPrev_user_vfiotmp; /* user space only */ + uint64_t padding_prevuvfio; + }; + union { + struct dev_mem_info_s *pNext_user_vfiotmp; /* user space only */ + uint64_t padding_nextuvfio; + }; + uint32_t flag_pinned; /* required while using TMP list */ +#endif /* ICP_THREAD_SPECIFIC_USDM */ } dev_mem_info_t; typedef struct user_page_info_s @@ -681,6 +699,7 @@ void printMemAllocations(void); #endif #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); diff --git a/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c b/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c new file mode 100644 index 00000000..9aeb6223 --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_common.c @@ -0,0 +1,677 @@ +/*************************************************************************** + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + ***************************************************************************/ +/** + **************************************************************************** + * @file qae_mem_common.c + * + * This file provides for Linux user space memory allocation. It uses + * a driver that allocates the memory in kernel memory space (to ensure + * physically contiguous memory) and maps it to + * user space for use by the quick assist sample code + * + ***************************************************************************/ + +#include "qae_mem_lib_utils.h" +#include "qae_mem_utils_common.h" + +/* Maximum supported alignment is 4M. */ +#define QAE_MAX_PHYS_ALIGN (0x400000ULL) + +/* Current cached memory size. */ +size_t g_cache_size = 0; +/* Maximum cached memory size, 8 Mb by default */ +size_t g_max_cache = MAX_CACHE_DEPTH_MB; +/* The maximum number we allow to search for available size */ +size_t g_max_lookup_num = 10; + +#ifdef __CLANG_FORMAT__ +/* clang-format off */ +#endif + +/* User space page table for fast virtual to physical address translation */ +page_table_t g_page_table = {{{0}}}; +/* User space hash for fast slab searching */ +slab_list_t g_slab_list[PAGE_SIZE] = {{0}}; + +#ifdef __CLANG_FORMAT__ +/* clang-format on */ +#endif + +#ifndef ICP_WITHOUT_THREAD +pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +#endif + +API_LOCAL dev_mem_info_t *__qae_pUserCacheHead = NULL; +API_LOCAL dev_mem_info_t *__qae_pUserCacheTail = NULL; +API_LOCAL dev_mem_info_t *__qae_pUserMemListHead = NULL; +API_LOCAL dev_mem_info_t *__qae_pUserMemListTail = NULL; +API_LOCAL dev_mem_info_t *__qae_pUserLargeMemListHead = NULL; +API_LOCAL dev_mem_info_t *__qae_pUserLargeMemListTail = NULL; + + +free_page_table_fptr_t free_page_table_fptr = free_page_table; +load_key_fptr_t load_key_fptr = load_key; + +API_LOCAL +dev_mem_info_t *__qae_userMemLookupBySize(size_t size, + int node, + void **block, + const size_t align) +{ + dev_mem_info_t *pCurr = NULL; + size_t link_num = 0; + + for (pCurr = __qae_pUserMemListHead; pCurr != NULL; + pCurr = pCurr->pNext_user) + { + if (g_strict_node && (pCurr->nodeId != node)) + { + continue; + } + *block = __qae_mem_alloc((block_ctrl_t *)pCurr, size, align); + if (NULL != *block) + { + 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 >= g_max_lookup_num) + { + break; + } + } + return NULL; +} + +/* translate a physical address to a virtual address */ +void *qaePhysToVirtNUMA(uint64_t physAddress) +{ + int status; + dev_mem_info_t *slab; + uintptr_t offset; + void *ret = NULL; + + status = mem_mutex_lock(&mutex); + if (status) + { + CMD_ERROR("%s:%d Error on thread mutex lock %s\n", + __func__, + __LINE__, + strerror(status)); + return NULL; + } + + /* find slab from physical address without using hash lookup */ + for (slab = __qae_pUserMemListHead; slab != NULL; slab = slab->pNext_user) + { + offset = (uintptr_t)physAddress - (uintptr_t)slab->phy_addr; + if (offset < slab->size) + { + ret = (void *)((uintptr_t)slab->virt_addr + offset); + break; + } + } + + status = mem_mutex_unlock(&mutex); + if (status) + { + CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", + __func__, + __LINE__, + strerror(status)); + return NULL; + } + + return ret; +} + +static int32_t memoryRemap(dev_mem_info_t *head) +{ + // NOT SUPPORTED + if (NULL != head) + { + CMD_ERROR("%s:%d not supported \n", __func__, __LINE__); + return -EIO; + } + + return 0; +} + +void qaeAtFork() +{ + int ret = 0; + int32_t status0 = 0; + int32_t status1 = 0; + int32_t status2 = 0; + + ret = mem_mutex_lock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR( + "%s:%d Error(%d) on thread mutex lock \n", __func__, __LINE__, ret); + return; + } + + status0 = memoryRemap(__qae_pUserCacheHead); + status1 = memoryRemap(__qae_pUserMemListHead); + status2 = memoryRemap(__qae_pUserLargeMemListHead); + + ret = mem_mutex_unlock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", + __func__, + __LINE__, + strerror(ret)); + goto fork_exit; + } + +fork_exit: + if (unlikely(status0)) + { + CMD_ERROR( + "%s:%d Failed to remap memory allocations \n", __func__, __LINE__); + } + if (unlikely(status1)) + { + CMD_ERROR( + "%s:%d Failed to remap memory allocations \n", __func__, __LINE__); + } + if (unlikely(status2)) + { + CMD_ERROR("%s:%d Failed to remap large memory allocations \n", + __func__, + __LINE__); + } + return; +} + +API_LOCAL +void __qae_free_slab(const int fd, dev_mem_info_t *slab) +{ + dev_mem_info_t memInfo; + int ret = 0; + + del_slab_from_hash(slab); + + memcpy(&memInfo, slab, sizeof(dev_mem_info_t)); + /* Need to disconnect from original chain */ + ret = qae_munmap(memInfo.virt_addr, memInfo.size); + if (ret) + { + CMD_ERROR("%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); + } + if (LARGE == memInfo.type) + { + ret = qae_munmap(slab, getpagesize()); + if (ret) + { + CMD_ERROR( + "%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); + } + } + + __qae_finish_free_slab(fd, &memInfo); +} + +API_LOCAL +dev_mem_info_t *__qae_find_slab(const int fd, + const size_t size, + const int node, + void **addr, + const size_t align) +{ + dev_mem_info_t *slab = __qae_userMemLookupBySize(size, node, addr, align); + + if (NULL == slab) + { + slab = pop_slab(node); + if (NULL != slab) + { + *addr = init_slab_and_alloc((block_ctrl_t *)slab, size, align); + if (NULL == *addr) + { + CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " + " Size: %zu \n", + __func__, + __LINE__, + slab, + size); + __qae_free_slab(fd, slab); + return NULL; + } + } + } + return slab; +} + +API_LOCAL +void __qae_ResetControl(void) +{ + /* Reset all control structures. */ + free_page_table_fptr(&g_page_table); + memset(&g_page_table, 0, sizeof(g_page_table)); + memset(&g_slab_list, 0, sizeof(g_slab_list)); + g_cache_size = 0; + + __qae_pUserCacheHead = NULL; + __qae_pUserCacheTail = NULL; + __qae_pUserMemListHead = NULL; + __qae_pUserMemListTail = NULL; + __qae_pUserLargeMemListHead = NULL; + __qae_pUserLargeMemListTail = NULL; +} + +int32_t qaeMemInit() +{ + int32_t fd_status = 0; + int32_t status = 0; + + status = mem_mutex_lock(&mutex); + if (status) + { + CMD_ERROR("%s:%d Error on thread mutex lock %s\n", + __func__, + __LINE__, + strerror(status)); + return -EIO; + } + + fd_status = __qae_open(); + + status = mem_mutex_unlock(&mutex); + if (status) + { + CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", + __func__, + __LINE__, + strerror(status)); + return -EIO; + } + return fd_status; +} + +API_LOCAL +void __qae_destroyList(const int fd, dev_mem_info_t *pList) +{ + dev_mem_info_t *pCurr = pList; + + while (pCurr) + { + dev_mem_info_t *next = pCurr->pNext_user; + __qae_free_slab(fd, pCurr); + pCurr = next; + } +} + +API_LOCAL +void __qae_reset_cache(const int fd) +{ + dev_mem_info_t *slab = NULL; + do + { + slab = pop_slab(NUMA_ANY_NODE); + if (NULL != slab) + __qae_free_slab(fd, slab); + } while (slab != NULL); +} + +void qaeMemDestroy(void) +{ + int ret = 0; + + /* Free all of the chains */ + ret = mem_mutex_lock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR( + "%s:%d Error(%d) on thread mutex lock \n", __func__, __LINE__, ret); + return; + } + + /* release all control buffers */ + free_page_table_fptr(&g_page_table); + __qae_reset_cache(g_fd); + __qae_destroyList(g_fd, __qae_pUserMemListHead); + __qae_destroyList(g_fd, __qae_pUserLargeMemListHead); + + __qae_pUserCacheHead = NULL; + __qae_pUserCacheTail = NULL; + __qae_pUserMemListHead = NULL; + __qae_pUserMemListTail = NULL; + __qae_pUserLargeMemListHead = NULL; + __qae_pUserLargeMemListTail = NULL; + + __qae_free_special(); + + ret = mem_mutex_unlock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR("%s:%d Error(%d) on thread mutex unlock\n", + __func__, + __LINE__, + ret); + } +} + +API_LOCAL +void *__qae_alloc_addr(size_t size, + const int node, + const size_t phys_alignment_byte) +{ + dev_mem_info_t *p_ctrl_blk = NULL; + void *pVirtAddress = NULL; + size_t allocate_pages = 0; + 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); + /* 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) + { + mem_type = LARGE; + /* Huge page and Large memory are mutually exclusive + * Since Large slabs are NOT 2 MB aligned, but huge + * pages are always 2 MB aligned. + */ + if (__qae_hugepage_enabled()) + return NULL; + size = MAX(size, phys_alignment_byte); + allocate_pages = div_round_up(size, UNIT_SIZE); + } + else + { + allocate_pages = QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE; + if (__qae_hugepage_enabled()) + mem_type = HUGE_PAGE; + + p_ctrl_blk = + __qae_find_slab(g_fd, size, node, &pVirtAddress, phys_align_unit); + + if (p_ctrl_blk) + { + p_ctrl_blk->allocations += 1; + return pVirtAddress; + } + } + + /* Try to allocate memory as much as possible */ + p_ctrl_blk = __qae_alloc_slab( + g_fd, allocate_pages * UNIT_SIZE, phys_alignment_byte, node, mem_type); + 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()); + + if (LARGE == mem_type) + { + p_ctrl_blk->allocations = 1; + + ADD_ELEMENT_TO_HEAD_LIST(p_ctrl_blk, + __qae_pUserLargeMemListHead, + __qae_pUserLargeMemListTail, + _user); + + pVirtAddress = p_ctrl_blk->virt_addr; + } + else + { + p_ctrl_blk->allocations = 1; + + if ((uintptr_t)p_ctrl_blk->virt_addr % QAE_PAGE_SIZE) + { + CMD_ERROR("%s:%d Bad virtual address alignment %lux %x %lux\n", + __func__, + __LINE__, + (uintptr_t)p_ctrl_blk->virt_addr, + QAE_NUM_PAGES_PER_ALLOC, + QAE_PAGE_SIZE); + __qae_free_slab(g_fd, p_ctrl_blk); + + return NULL; + } + pVirtAddress = init_slab_and_alloc( + (block_ctrl_t *)p_ctrl_blk, size, phys_align_unit); + if (NULL == pVirtAddress) + { + CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " + " Size: %zu \n", + __func__, + __LINE__, + p_ctrl_blk, + size); + __qae_free_slab(g_fd, p_ctrl_blk); + + return NULL; + } + } + return pVirtAddress; +} + +void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) +{ + void *pVirtAddress = NULL; + int ret = 0; + + if (!size) + { + CMD_ERROR("%s:%d Size cannot be zero \n", __func__, __LINE__); + 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 || + (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", + __func__, + __LINE__, + phys_alignment_byte, + QAE_MAX_PHYS_ALIGN); + return NULL; + } + + ret = mem_mutex_lock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR("%s:%d Error on thread mutex lock %s\n", + __func__, + __LINE__, + strerror(ret)); + return NULL; + } + + pVirtAddress = __qae_alloc_addr(size, node, phys_alignment_byte); + + ret = mem_mutex_unlock(&mutex); + if (unlikely(ret)) + { + CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", + __func__, + __LINE__, + strerror(ret)); + return NULL; + } + return pVirtAddress; +} + +API_LOCAL +void __qae_free_addr(void **p_va, bool secure_free) +{ + dev_mem_info_t *p_ctrl_blk = NULL; + + if (0 != __qae_open()) + return; + + if ((p_ctrl_blk = find_slab_in_hash(*p_va)) == NULL) + { + CMD_ERROR("%s:%d Unable to free as lookup failed on address (%p) " + "provided \n", + __func__, + __LINE__, + *p_va); + return; + } + if (SMALL == p_ctrl_blk->type || HUGE_PAGE == p_ctrl_blk->type) + { + if (__qae_mem_free((block_ctrl_t *)p_ctrl_blk, *p_va, secure_free)) + { + p_ctrl_blk->allocations -= 1; + } + else + { + /*Skip push_slab(p_ctrl_blk)) and return when mem_free fails */ + CMD_ERROR("%s:%d mem_free returned false (%p) " + "provided \n", + __func__, + __LINE__, + *p_va); + *p_va = NULL; + return; + } + if (p_ctrl_blk->allocations) + { + *p_va = NULL; + return; + } + + REMOVE_ELEMENT_FROM_LIST( + p_ctrl_blk, __qae_pUserMemListHead, __qae_pUserMemListTail, _user); + if (0 != push_slab(p_ctrl_blk)) + __qae_free_slab(g_fd, p_ctrl_blk); + } + else + { + REMOVE_ELEMENT_FROM_LIST(p_ctrl_blk, + __qae_pUserLargeMemListHead, + __qae_pUserLargeMemListTail, + _user); + __qae_free_slab(g_fd, p_ctrl_blk); + } + *p_va = NULL; +} + +/* __qae_memFreeNUMA function + * Frees memory pointed by ptr. + * ptr refers to memory allocated by qaeMemAllocNUMA function. + * secure_free is a boolean to perform memory free secured or not. + */ +API_LOCAL +void __qae_memFreeNUMA(void **ptr, bool secure_free) +{ + int ret = 0; + + if (NULL == ptr) + { + CMD_ERROR( + "%s:%d Input parameter cannot be NULL \n", __func__, __LINE__); + return; + } + if (NULL == *ptr) + { + CMD_ERROR( + "%s:%d Address to be freed cannot be NULL \n", __func__, __LINE__); + return; + } + ret = mem_mutex_lock(&mutex); + if (ret) + { + CMD_ERROR("%s:%d Error on thread mutex lock %s\n", + __func__, + __LINE__, + strerror(ret)); + return; + } + + __qae_free_addr(ptr, secure_free); + + ret = mem_mutex_unlock(&mutex); + if (ret) + { + CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", + __func__, + __LINE__, + strerror(ret)); + } + return; +} 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 new file mode 100644 index 00000000..7e536035 --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_lib_utils.h @@ -0,0 +1,240 @@ +/*************************************************************************** + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + ***************************************************************************/ +/** + **************************************************************************** + * @file qae_mem_lib_utils.h + * + * This file provides for Linux user space memory allocation. It uses + * a driver that allocates the memory in kernel memory space (to ensure + * physically contiguous memory) and maps it to + * user space for use by the quick assist sample code + * + ***************************************************************************/ + +#ifndef QAE_MEM_COMMON_H +#define QAE_MEM_COMMON_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef ICP_WITHOUT_THREAD +#include +#endif +#include +#include +#include +#include +#include "qae_mem.h" +#include "qae_mem_utils.h" +#include "qae_mem_user_utils.h" +#include "qae_page_table_common.h" +#include "qae_mem_hugepage_utils.h" +#include "qae_mem_utils_common.h" + +extern int g_strict_node; +/* Current cached memory size. */ +extern size_t g_cache_size; +/* Maximum cached memory size, 8 Mb by default */ +extern size_t g_max_cache; + +/* User space hash for fast slab searching */ +extern slab_list_t g_slab_list[PAGE_SIZE]; + +extern dev_mem_info_t *__qae_pUserCacheHead; +extern dev_mem_info_t *__qae_pUserCacheTail; +extern dev_mem_info_t *__qae_pUserMemListHead; +extern dev_mem_info_t *__qae_pUserMemListTail; +extern dev_mem_info_t *__qae_pUserLargeMemListHead; +extern dev_mem_info_t *__qae_pUserLargeMemListTail; + +extern uint32_t numaAllocations_g; + +API_LOCAL +void __qae_ResetControl(void); + +API_LOCAL +dev_mem_info_t *__qae_userMemLookupBySize(size_t size, + int node, + void **block, + const size_t align); + +API_LOCAL +void __qae_free_slab(const int fd, dev_mem_info_t *slab); + +API_LOCAL +dev_mem_info_t *__qae_find_slab(const int fd, + const size_t size, + const int node, + void **addr, + const size_t align); +API_LOCAL +int __qae_open(void); + +API_LOCAL +void __qae_destroyList(const int fd, dev_mem_info_t *pList); + +API_LOCAL +void __qae_reset_cache(const int fd); + +API_LOCAL +int __qae_free_special(void); + +API_LOCAL +dev_mem_info_t *__qae_alloc_slab(const int fd, + const size_t size, + const uint32_t alignment, + const int node, + enum slabType type); + +static inline void add_slab_to_hash(dev_mem_info_t *slab) +{ + const size_t key = get_key(slab->phy_addr); + + ADD_ELEMENT_TO_HEAD_LIST( + slab, g_slab_list[key].head, g_slab_list[key].tail, _user_hash); +} +static inline void del_slab_from_hash(dev_mem_info_t *slab) +{ + const size_t key = get_key(slab->phy_addr); + + REMOVE_ELEMENT_FROM_LIST( + slab, g_slab_list[key].head, g_slab_list[key].tail, _user_hash); +} + +static inline dev_mem_info_t *find_slab_in_hash(void *virt_addr) +{ + const size_t key = load_key_fptr(&g_page_table, virt_addr); + dev_mem_info_t *slab = g_slab_list[key].head; + + while (slab) + { + uintptr_t offs = (uintptr_t)virt_addr - (uintptr_t)slab->virt_addr; + if (offs < slab->size) + return slab; + slab = slab->pNext_user_hash; + } + + return NULL; +} + +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; + + virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); + if (NULL != virt_addr) + { + ADD_ELEMENT_TO_HEAD_LIST( + p_ctrl_blk, __qae_pUserMemListHead, __qae_pUserMemListTail, _user); + } + return virt_addr; +} + +static inline int push_slab(dev_mem_info_t *slab) +{ + if (g_cache_size + slab->size <= g_max_cache) + { + g_cache_size += slab->size; + ADD_ELEMENT_TO_HEAD_LIST( + slab, __qae_pUserCacheHead, __qae_pUserCacheTail, _user); + return 0; + } + return -ENOMEM; +} + +static inline dev_mem_info_t *pop_slab(const int node) +{ + dev_mem_info_t *slab = NULL; + + for (slab = __qae_pUserCacheHead; slab != NULL; slab = slab->pNext_user) + { + if (node != NUMA_ANY_NODE) + if (g_strict_node && (node != slab->nodeId)) + continue; + + g_cache_size -= slab->size; + REMOVE_ELEMENT_FROM_LIST( + slab, __qae_pUserCacheHead, __qae_pUserCacheTail, _user); + return slab; + } + return NULL; +} + +#endif /* QAE_MEM_COMMON_H */ 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 new file mode 100644 index 00000000..a52b244e --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread.h @@ -0,0 +1,272 @@ +/*************************************************************************** + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + ***************************************************************************/ +/** + **************************************************************************** + * @file qae_mem_utils_common.h + * + * This file provides for Linux user space memory allocation. It uses + * a driver that allocates the memory in kernel memory space (to ensure + * physically contiguous memory) and maps it to + * user space for use by the quick assist sample code + * + ***************************************************************************/ + +#ifndef QAE_MEM_MULTI_THREAD_H +#define QAE_MEM_MULTI_THREAD_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "qae_mem.h" +#include "qae_mem_utils.h" +#include "qae_mem_user_utils.h" +#include "qae_page_table_common.h" +#include "qae_mem_hugepage_utils.h" +#include "qae_mem_utils_common.h" + +#ifdef ICP_THREAD_SPECIFIC_USDM +typedef struct +{ + dev_mem_info_t *pUserCacheHead; + dev_mem_info_t *pUserCacheTail; + dev_mem_info_t *pUserMemListHead; + dev_mem_info_t *pUserMemListTail; + dev_mem_info_t *pUserLargeMemListHead; + dev_mem_info_t *pUserLargeMemListTail; + size_t g_cache_size; + size_t g_max_cache; + size_t g_max_lookup_num; + slab_list_t g_slab_list[PAGE_SIZE]; + int g_strict_node; + uint32_t numaAllocations_g; + uint32_t thd_process_id; +} qae_mem_info_t; + +extern slab_list_t g_slab_tmp_list; +extern pthread_mutex_t mutex_tmp_list; +extern pthread_key_t qae_key; +extern pthread_once_t qae_key_once; +extern __thread int qae_mem_inited; + +API_LOCAL +dev_mem_info_t *__qae_userMemLookupBySize(size_t size, + int node, + void **block, + const size_t align, + qae_mem_info_t *tls_ptr); + +API_LOCAL +int __qae_free_special(void); + +API_LOCAL +void __qae_free_slab(const int fd, + dev_mem_info_t *slab, + qae_mem_info_t *tls_ptr); + +API_LOCAL +dev_mem_info_t *__qae_find_slab(const int fd, + const size_t size, + const int node, + void **addr, + const size_t align, + qae_mem_info_t *tls_ptr); +API_LOCAL +void __qae_destroyList(const int fd, dev_mem_info_t *pList, void *thread_key); + +API_LOCAL +void __qae_reset_cache(const int fd, void *thread_key); + +API_LOCAL +dev_mem_info_t *__qae_alloc_slab(const int fd, + const size_t size, + const uint32_t alignment, + const int node, + enum slabType type, + qae_mem_info_t *tls_ptr); + +/* These *_tmp_list() functions are for managing the TMP list in thread + * specific implementation. + */ +static inline void save_slab_to_tmp_list(dev_mem_info_t *slab) +{ + mem_mutex_lock(&mutex_tmp_list); + ADD_ELEMENT_TO_HEAD_LIST( + slab, g_slab_tmp_list.head, g_slab_tmp_list.tail, _user_vfiotmp); + mem_mutex_unlock(&mutex_tmp_list); +} + +static inline void remove_slab_from_tmp_list(dev_mem_info_t *slab) +{ + mem_mutex_lock(&mutex_tmp_list); + REMOVE_ELEMENT_FROM_LIST( + slab, g_slab_tmp_list.head, g_slab_tmp_list.tail, _user_vfiotmp); + mem_mutex_unlock(&mutex_tmp_list); +} + +static inline void add_slab_to_hash(dev_mem_info_t *slab, + qae_mem_info_t *tls_ptr) +{ + const size_t key = get_key(slab->phy_addr); + + ADD_ELEMENT_TO_HEAD_LIST(slab, + tls_ptr->g_slab_list[key].head, + tls_ptr->g_slab_list[key].tail, + _user_hash); +} +static inline void del_slab_from_hash(dev_mem_info_t *slab, + qae_mem_info_t *tls_ptr) +{ + const size_t key = get_key(slab->phy_addr); + + REMOVE_ELEMENT_FROM_LIST(slab, + tls_ptr->g_slab_list[key].head, + tls_ptr->g_slab_list[key].tail, + _user_hash); +} + +static inline dev_mem_info_t *find_slab_in_hash(void *virt_addr, + qae_mem_info_t *tls_ptr) +{ + const size_t key = load_key_fptr(&g_page_table, virt_addr); + dev_mem_info_t *slab = tls_ptr->g_slab_list[key].head; + + while (slab) + { + uintptr_t offs = (uintptr_t)virt_addr - (uintptr_t)slab->virt_addr; + if (offs < slab->size) + return slab; + slab = slab->pNext_user_hash; + } + + return NULL; +} + +static inline void *init_slab_and_alloc(block_ctrl_t *slab, + const size_t size, + 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; + + virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); + if (NULL != virt_addr) + { + ADD_ELEMENT_TO_HEAD_LIST(p_ctrl_blk, + tls_ptr->pUserMemListHead, + tls_ptr->pUserMemListTail, + _user); + } + return virt_addr; +} + +static inline int push_slab(dev_mem_info_t *slab, qae_mem_info_t *tls_ptr) +{ + if (tls_ptr->g_cache_size + slab->size <= tls_ptr->g_max_cache) + { + tls_ptr->g_cache_size += slab->size; + ADD_ELEMENT_TO_HEAD_LIST( + slab, tls_ptr->pUserCacheHead, tls_ptr->pUserCacheTail, _user); + return 0; + } + return -ENOMEM; +} + +static inline dev_mem_info_t *pop_slab(const int node, qae_mem_info_t *tls_ptr) +{ + dev_mem_info_t *slab = NULL; + + for (slab = tls_ptr->pUserCacheHead; slab != NULL; slab = slab->pNext_user) + { + if (node != NUMA_ANY_NODE) + if (tls_ptr->g_strict_node && (node != slab->nodeId)) + continue; + + tls_ptr->g_cache_size -= slab->size; + REMOVE_ELEMENT_FROM_LIST( + slab, tls_ptr->pUserCacheHead, tls_ptr->pUserCacheTail, _user); + return slab; + } + return NULL; +} +#endif + +#endif /* QAE_MEM_THREAD_H */ 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 new file mode 100644 index 00000000..56619dd2 --- /dev/null +++ b/quickassist/utilities/libusdm_drv/user_space/qae_mem_multi_thread_utils.c @@ -0,0 +1,610 @@ +/*************************************************************************** + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * The full GNU General Public License is included in this distribution + * in the file called LICENSE.GPL. + * + * Contact Information: + * Intel Corporation + * + * BSD LICENSE + * + * Copyright(c) 2007-2022 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * + * + ***************************************************************************/ +/** + **************************************************************************** + * @file qae_mem_multi_thread_utils.c + * + * This file provides for thread specific Linux user space memory allocation. + * It uses a driver that allocates the memory in kernel memory space (to ensure + * physically contiguous memory) and maps it to + * user space for use by the quick assist sample code + * + * Each thread handles its own memory allocator information. Thread local + * storage is used to hold all slab memory allocator information for each + * thread. + * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifndef ICP_WITHOUT_THREAD +#include +#endif +#include +#include +#include +#include +#include "qae_mem.h" +#include "qae_mem_utils.h" +#include "qae_mem_user_utils.h" +#include "qae_page_table_common.h" +#include "qae_mem_utils_common.h" +#include "qae_mem_multi_thread.h" +#include "qae_mem_hugepage_utils.h" +#include + +/************************************************************************** + macro +**************************************************************************/ + +#ifdef __CLANG_FORMAT__ +/* clang-format off */ +#endif +/* User space page table for fast virtual to physical address translation */ +page_table_t g_page_table = { { { 0 } } }; + +slab_list_t g_slab_tmp_list = { 0 }; +pthread_mutex_t mutex_tmp_list = PTHREAD_MUTEX_INITIALIZER; + +#ifdef __CLANG_FORMAT__ +/* clang-format on */ +#endif + +pthread_key_t qae_key; +pthread_once_t qae_key_once = PTHREAD_ONCE_INIT; +__thread int qae_mem_inited = 0; + +free_page_table_fptr_t free_page_table_fptr = free_page_table; +load_key_fptr_t load_key_fptr = load_key; + +void qae_mem_destroy_t(void *thread_key); + +static void qae_make_key() +{ + pthread_key_create(&qae_key, qae_mem_destroy_t); +} + +API_LOCAL +dev_mem_info_t *__qae_userMemLookupBySize(size_t size, + int node, + void **block, + const size_t align, + qae_mem_info_t *tls_ptr) +{ + dev_mem_info_t *pCurr = NULL; + size_t link_num = 0; + + for (pCurr = tls_ptr->pUserMemListHead; pCurr != NULL; + pCurr = pCurr->pNext_user) + { + if (tls_ptr->g_strict_node && (pCurr->nodeId != node)) + { + continue; + } + *block = __qae_mem_alloc((block_ctrl_t *)pCurr, size, align); + if (NULL != *block) + { + 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 >= tls_ptr->g_max_lookup_num) + { + break; + } + } + return NULL; +} + +/* translate a physical address to a virtual address */ +void *qaePhysToVirtNUMA(uint64_t physAddress) +{ + dev_mem_info_t *slab; + uintptr_t offset; + void *ret = NULL; + qae_mem_info_t *tls_ptr; + tls_ptr = (qae_mem_info_t *)pthread_getspecific(qae_key); + /* find slab from physical address without using hash lookup */ + for (slab = tls_ptr->pUserMemListHead; slab != NULL; + slab = slab->pNext_user) + { + offset = (uintptr_t)physAddress - (uintptr_t)slab->phy_addr; + if (offset < slab->size) + { + ret = (void *)((uintptr_t)slab->virt_addr + offset); + break; + } + } + return ret; +} + +void qaeAtFork() +{ + return; +} + +API_LOCAL +void __qae_free_slab(const int fd, + dev_mem_info_t *slab, + qae_mem_info_t *tls_ptr) +{ + dev_mem_info_t memInfo; + int ret = 0; + + del_slab_from_hash(slab, tls_ptr); + /* Remove the slab from TMP list as well */ + remove_slab_from_tmp_list(slab); + + memcpy(&memInfo, slab, sizeof(dev_mem_info_t)); + /* Need to disconnect from original chain */ + ret = qae_munmap(memInfo.virt_addr, memInfo.size); + if (ret) + { + CMD_ERROR("%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); + } + if (LARGE == memInfo.type) + { + ret = qae_munmap(slab, getpagesize()); + if (ret) + { + CMD_ERROR( + "%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); + } + } + + __qae_finish_free_slab(fd, &memInfo); +} + +API_LOCAL +dev_mem_info_t *__qae_find_slab(const int fd, + const size_t size, + const int node, + void **addr, + const size_t align, + qae_mem_info_t *tls_ptr) +{ + dev_mem_info_t *slab = + __qae_userMemLookupBySize(size, node, addr, align, tls_ptr); + + if (NULL == slab) + { + slab = pop_slab(node, tls_ptr); + if (NULL != slab) + { + *addr = + init_slab_and_alloc((block_ctrl_t *)slab, size, align, tls_ptr); + if (NULL == *addr) + { + CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " + " Size: %zu \n", + __func__, + __LINE__, + slab, + size); + __qae_free_slab(fd, slab, tls_ptr); + return NULL; + } + } + } + return slab; +} + +static void qae_mem_init_t(void) +{ + qae_mem_info_t *tls_ptr; + pthread_once(&qae_key_once, qae_make_key); + + if ((tls_ptr = (qae_mem_info_t *)pthread_getspecific(qae_key)) == NULL) + { + tls_ptr = malloc(sizeof(qae_mem_info_t)); + /* Reset all control structures. */ + memset(tls_ptr, 0, sizeof(qae_mem_info_t)); + pthread_setspecific(qae_key, (void *)tls_ptr); + } + /* Set this to 0, because mmap doesn't provide NUMA aware memory */ + tls_ptr->g_strict_node = 0; + tls_ptr->g_max_lookup_num = 10; + /* MAX cache size per thread */ + tls_ptr->g_max_cache = MAX_CACHE_DEPTH_MB; + tls_ptr->thd_process_id = syscall(__NR_gettid); + + qae_mem_inited = 1; +} + +int32_t qaeMemInit() +{ + int32_t fd_status = 0; + int32_t status = 0; + + if (!is_new_process()) + { + /* Return if it is an existing process. */ + return status; + } + + qae_key = 0; + qae_mem_inited = 0; + qae_key_once = PTHREAD_ONCE_INIT; + + fd_status = __qae_open(); + + return fd_status; +} + +API_LOCAL +void __qae_destroyList(const int fd, dev_mem_info_t *pList, void *thread_key) +{ + dev_mem_info_t *pCurr = pList; + + while (pCurr) + { + dev_mem_info_t *next = pCurr->pNext_user; + __qae_free_slab(fd, pCurr, (qae_mem_info_t *)thread_key); + pCurr = next; + } +} + +API_LOCAL +void __qae_reset_cache(const int fd, void *thread_key) +{ + + dev_mem_info_t *slab = NULL; + do + { + slab = pop_slab(NUMA_ANY_NODE, (qae_mem_info_t *)thread_key); + if (NULL != slab) + __qae_free_slab(fd, slab, (qae_mem_info_t *)thread_key); + } while (slab != NULL); +} + +void qaeMemDestroy(void) +{ + qae_mem_info_t *tls_ptr = NULL; + + free_page_table_fptr(&g_page_table); + + tls_ptr = (qae_mem_info_t *)pthread_getspecific(qae_key); + if (tls_ptr && qae_mem_inited) + { + __qae_reset_cache(g_fd, (void *)tls_ptr); + __qae_destroyList(g_fd, tls_ptr->pUserMemListHead, (void *)tls_ptr); + __qae_destroyList( + g_fd, tls_ptr->pUserLargeMemListHead, (void *)tls_ptr); + free(tls_ptr); + pthread_setspecific(qae_key, NULL); + } + + __qae_free_special(); + + qae_mem_inited = 0; + pthread_key_delete(qae_key); +} + +void qae_mem_destroy_t(void *thread_key) +{ + qae_mem_info_t *tls_ptr; + tls_ptr = (qae_mem_info_t *)thread_key; + /* release all control buffers */ + __qae_reset_cache(g_fd, thread_key); + __qae_destroyList(g_fd, tls_ptr->pUserMemListHead, thread_key); + __qae_destroyList(g_fd, tls_ptr->pUserLargeMemListHead, thread_key); + + free(thread_key); + qae_mem_inited = 0; +} + +API_LOCAL +void *__qae_alloc_addr(size_t size, + const int node, + const size_t phys_alignment_byte) +{ + dev_mem_info_t *p_ctrl_blk = NULL; + void *pVirtAddress = NULL; + size_t allocate_pages = 0; + enum slabType mem_type = SMALL; + qae_mem_info_t *tls_ptr; + 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); + /* calculate units needed */ + const size_t requested_pages = div_round_up(size, UNIT_SIZE) + reserved; + + if (tls_ptr == NULL) + { + CMD_ERROR("error, unable to initialise slab allocator\n"); + 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) + { + mem_type = LARGE; + /* Huge page and Large memory are mutually exclusive + * Since Large slabs are NOT 2 MB aligned, but huge + * pages are always 2 MB aligned. + */ + if (__qae_hugepage_enabled()) + return NULL; + + size = MAX(size, phys_alignment_byte); + allocate_pages = div_round_up(size, UNIT_SIZE); + } + else + { + allocate_pages = QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE; + if (__qae_hugepage_enabled()) + mem_type = HUGE_PAGE; + + p_ctrl_blk = __qae_find_slab( + g_fd, size, node, &pVirtAddress, phys_align_unit, tls_ptr); + + if (p_ctrl_blk) + { + p_ctrl_blk->allocations += 1; + return pVirtAddress; + } + } + + /* Try to allocate memory as much as possible */ + p_ctrl_blk = __qae_alloc_slab(g_fd, + allocate_pages * UNIT_SIZE, + phys_alignment_byte, + node, + mem_type, + tls_ptr); + 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()); + + if (LARGE == mem_type) + { + p_ctrl_blk->allocations = 1; + + ADD_ELEMENT_TO_HEAD_LIST(p_ctrl_blk, + tls_ptr->pUserLargeMemListHead, + tls_ptr->pUserLargeMemListTail, + _user); + + pVirtAddress = p_ctrl_blk->virt_addr; + } + else + { + p_ctrl_blk->allocations = 1; + + if ((uintptr_t)p_ctrl_blk->virt_addr % QAE_PAGE_SIZE) + { + CMD_ERROR("%s:%d Bad virtual address alignment %lux %x %lux\n", + __func__, + __LINE__, + (uintptr_t)p_ctrl_blk->virt_addr, + QAE_NUM_PAGES_PER_ALLOC, + QAE_PAGE_SIZE); + __qae_free_slab(g_fd, p_ctrl_blk, tls_ptr); + + return NULL; + } + pVirtAddress = init_slab_and_alloc( + (block_ctrl_t *)p_ctrl_blk, size, phys_align_unit, tls_ptr); + if (NULL == pVirtAddress) + { + CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " + " Size: %zu \n", + __func__, + __LINE__, + p_ctrl_blk, + size); + __qae_free_slab(g_fd, p_ctrl_blk, tls_ptr); + + return NULL; + } + } + return pVirtAddress; +} + +void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) +{ + void *pVirtAddress = NULL; + + if (!size) + { + CMD_ERROR("%s:%d Size cannot be zero \n", __func__, __LINE__); + 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 || + (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", + __func__, + __LINE__, + phys_alignment_byte, + QAE_MAX_PHYS_ALIGN); + return NULL; + } + + if (0 != qaeMemInit()) + return NULL; + + if (!qae_mem_inited) + { + qae_mem_init_t(); + } + + pVirtAddress = __qae_alloc_addr(size, node, phys_alignment_byte); + return pVirtAddress; +} + +API_LOCAL +void __qae_free_addr(void **p_va, bool secure_free) +{ + dev_mem_info_t *p_ctrl_blk = NULL; + qae_mem_info_t *tls_ptr; + + tls_ptr = (qae_mem_info_t *)pthread_getspecific(qae_key); + if (!tls_ptr) + { + CMD_ERROR("%s:%d No memory alloc info found \n", __func__, __LINE__); + return; + } + + if ((p_ctrl_blk = find_slab_in_hash(*p_va, tls_ptr)) == NULL) + { + CMD_ERROR("%s:%d Unable to free as lookup failed on address (%p) " + "provided \n", + __func__, + __LINE__, + *p_va); + return; + } + if (SMALL == p_ctrl_blk->type || HUGE_PAGE == p_ctrl_blk->type) + { + if (__qae_mem_free((block_ctrl_t *)p_ctrl_blk, *p_va, secure_free)) + { + p_ctrl_blk->allocations -= 1; + } + else + { + /*Skip push_slab(p_ctrl_blk)) and return when mem_free fails */ + CMD_ERROR("%s:%d mem_free returned false (%p) " + "provided \n", + __func__, + __LINE__, + *p_va); + *p_va = NULL; + return; + } + if (p_ctrl_blk->allocations) + { + *p_va = NULL; + return; + } + + REMOVE_ELEMENT_FROM_LIST(p_ctrl_blk, + tls_ptr->pUserMemListHead, + tls_ptr->pUserMemListTail, + _user); + if (0 != push_slab(p_ctrl_blk, tls_ptr)) + __qae_free_slab(g_fd, p_ctrl_blk, tls_ptr); + } + else + { + REMOVE_ELEMENT_FROM_LIST(p_ctrl_blk, + tls_ptr->pUserLargeMemListHead, + tls_ptr->pUserLargeMemListTail, + _user); + __qae_free_slab(g_fd, p_ctrl_blk, tls_ptr); + } + *p_va = NULL; +} + +/* __qae_memFreeNUMA function + * Frees memory pointed by ptr. + * ptr refers to memory allocated by qaeMemAllocNUMA function. + * secure_free is a boolean to perform memory free secured or not. + */ +API_LOCAL +void __qae_memFreeNUMA(void **ptr, bool secure_free) +{ + + if (NULL == ptr) + { + CMD_ERROR( + "%s:%d Input parameter cannot be NULL \n", __func__, __LINE__); + return; + } + if (NULL == *ptr) + { + CMD_ERROR( + "%s:%d Address to be freed cannot be NULL \n", __func__, __LINE__); + return; + } + __qae_free_addr(ptr, secure_free); + + return; +} 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 e0c7182b..78222c2f 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 @@ -81,9 +81,6 @@ #include #include #include -#ifndef ICP_WITHOUT_THREAD -#include -#endif #include #include #include @@ -91,37 +88,10 @@ #include "qae_mem.h" #include "qae_mem_utils.h" #include "qae_mem_user_utils.h" -#include "qae_page_table_common.h" -#include "qae_mem_hugepage_utils.h" #include "qae_mem_utils_common.h" -/* Current cached memory size. */ -size_t g_cache_size = 0; -/* Maximum cached memory size, 8 Mb by default */ -size_t g_max_cache = 0x800000; -/* The maximum number we allow to search for available size */ -size_t g_max_lookup_num = 10; -/* User space page table for fast virtual to physical address translation */ -page_table_t g_page_table = {{{0}}}; - -/* User space hash for fast slab searching */ -slab_list_t g_slab_list[PAGE_SIZE] = {{0}}; - -#ifndef ICP_WITHOUT_THREAD -pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; -#endif - -API_LOCAL dev_mem_info_t *__qae_pUserCacheHead = NULL; -API_LOCAL dev_mem_info_t *__qae_pUserCacheTail = NULL; -API_LOCAL dev_mem_info_t *__qae_pUserMemListHead = NULL; -API_LOCAL dev_mem_info_t *__qae_pUserMemListTail = NULL; -API_LOCAL dev_mem_info_t *__qae_pUserLargeMemListHead = NULL; -API_LOCAL dev_mem_info_t *__qae_pUserLargeMemListTail = NULL; - -free_page_table_fptr_t free_page_table_fptr = free_page_table; load_addr_fptr_t load_addr_fptr = load_addr; -load_key_fptr_t load_key_fptr = load_key; const uint64_t __qae_bitmask[65] = { 0x0000000000000000ULL, 0x0000000000000001ULL, 0x0000000000000003ULL, @@ -384,41 +354,6 @@ bool __qae_mem_free(block_ctrl_t *block_ctrl, void *block, bool secure_free) return true; } -API_LOCAL -dev_mem_info_t *__qae_userMemLookupBySize(size_t size, - int node, - void **block, - const size_t align) -{ - dev_mem_info_t *pCurr = NULL; - size_t link_num = 0; - - for (pCurr = __qae_pUserMemListHead; pCurr != NULL; - pCurr = pCurr->pNext_user) - { - if (g_strict_node && (pCurr->nodeId != node)) - { - continue; - } - *block = __qae_mem_alloc((block_ctrl_t *)pCurr, size, align); - if (NULL != *block) - { - 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 >= g_max_lookup_num) - { - break; - } - } - return NULL; -} - /************************************** * Memory functions *************************************/ @@ -446,544 +381,6 @@ uint64_t qaeVirtToPhysNUMA(void *pVirtAddress) return load_addr_fptr(&g_page_table, pVirtAddress); } -/* translate a physical address to a virtual address */ -void *qaePhysToVirtNUMA(uint64_t physAddress) -{ - int status; - dev_mem_info_t *slab; - uintptr_t offset; - void *ret = NULL; - - status = mem_mutex_lock(&mutex); - if (status) - { - CMD_ERROR("%s:%d Error on thread mutex lock %s\n", - __func__, - __LINE__, - strerror(status)); - return NULL; - } - - /* find slab from physical address without using hash lookup */ - for (slab = __qae_pUserMemListHead; slab != NULL; slab = slab->pNext_user) - { - offset = (uintptr_t)physAddress - (uintptr_t)slab->phy_addr; - if (offset < slab->size) - { - ret = (void *)((uintptr_t)slab->virt_addr + offset); - break; - } - } - - status = mem_mutex_unlock(&mutex); - if (status) - { - CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", - __func__, - __LINE__, - strerror(status)); - return NULL; - } - - return ret; -} - -static int32_t memoryRemap(dev_mem_info_t *head) -{ - // NOT SUPPORTED - if (NULL != head) - { - CMD_ERROR("%s:%d not supported \n", __func__, __LINE__); - return -EIO; - } - - return 0; -} - -void qaeAtFork() -{ - int ret = 0; - int32_t status0 = 0; - int32_t status1 = 0; - int32_t status2 = 0; - - ret = mem_mutex_lock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR( - "%s:%d Error(%d) on thread mutex lock \n", __func__, __LINE__, ret); - return; - } - - status0 = memoryRemap(__qae_pUserCacheHead); - status1 = memoryRemap(__qae_pUserMemListHead); - status2 = memoryRemap(__qae_pUserLargeMemListHead); - - ret = mem_mutex_unlock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", - __func__, - __LINE__, - strerror(ret)); - goto fork_exit; - } - -fork_exit: - if (unlikely(status0)) - { - CMD_ERROR( - "%s:%d Failed to remap memory allocations \n", __func__, __LINE__); - } - if (unlikely(status1)) - { - CMD_ERROR( - "%s:%d Failed to remap memory allocations \n", __func__, __LINE__); - } - if (unlikely(status2)) - { - CMD_ERROR("%s:%d Failed to remap large memory allocations \n", - __func__, - __LINE__); - } - return; -} - -API_LOCAL -void __qae_free_slab(const int fd, dev_mem_info_t *slab) -{ - dev_mem_info_t memInfo; - int ret = 0; - - del_slab_from_hash(slab); - - memcpy(&memInfo, slab, sizeof(dev_mem_info_t)); - /* Need to disconnect from original chain */ - ret = qae_munmap(memInfo.virt_addr, memInfo.size); - if (ret) - { - CMD_ERROR("%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); - } - if (LARGE == memInfo.type) - { - ret = qae_munmap(slab, getpagesize()); - if (ret) - { - CMD_ERROR( - "%s:%d munmap failed, ret = %d\n", __func__, __LINE__, ret); - } - } - - __qae_finish_free_slab(fd, &memInfo); -} - -API_LOCAL -dev_mem_info_t *__qae_find_slab(const int fd, - const size_t size, - const int node, - void **addr, - const size_t align) -{ - dev_mem_info_t *slab = __qae_userMemLookupBySize(size, node, addr, align); - - if (NULL == slab) - { - slab = pop_slab(node); - if (NULL != slab) - { - *addr = init_slab_and_alloc((block_ctrl_t *)slab, size, align); - if (NULL == *addr) - { - CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " - " Size: %zu \n", - __func__, - __LINE__, - slab, - size); - __qae_free_slab(fd, slab); - return NULL; - } - } - } - return slab; -} - -API_LOCAL -void __qae_ResetControl(void) -{ - /* Reset all control structures. */ - free_page_table_fptr(&g_page_table); - memset(&g_page_table, 0, sizeof(g_page_table)); - memset(&g_slab_list, 0, sizeof(g_slab_list)); - g_cache_size = 0; - - __qae_pUserCacheHead = NULL; - __qae_pUserCacheTail = NULL; - __qae_pUserMemListHead = NULL; - __qae_pUserMemListTail = NULL; - __qae_pUserLargeMemListHead = NULL; - __qae_pUserLargeMemListTail = NULL; -} - -int32_t qaeMemInit() -{ - int32_t fd_status = 0; - int32_t status = 0; - - status = mem_mutex_lock(&mutex); - if (status) - { - CMD_ERROR("%s:%d Error on thread mutex lock %s\n", - __func__, - __LINE__, - strerror(status)); - return -EIO; - } - - fd_status = __qae_open(); - - status = mem_mutex_unlock(&mutex); - if (status) - { - CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", - __func__, - __LINE__, - strerror(status)); - return -EIO; - } - return fd_status; -} - -API_LOCAL -void __qae_destroyList(const int fd, dev_mem_info_t *pList) -{ - dev_mem_info_t *pCurr = pList; - - while (pCurr) - { - dev_mem_info_t *next = pCurr->pNext_user; - __qae_free_slab(fd, pCurr); - pCurr = next; - } -} - -API_LOCAL -void __qae_reset_cache(const int fd) -{ - dev_mem_info_t *slab = NULL; - do - { - slab = pop_slab(NUMA_ANY_NODE); - if (NULL != slab) - __qae_free_slab(fd, slab); - } while (slab != NULL); -} - -void qaeMemDestroy(void) -{ - int ret = 0; - - /* Free all of the chains */ - ret = mem_mutex_lock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR( - "%s:%d Error(%d) on thread mutex lock \n", __func__, __LINE__, ret); - return; - } - - /* release all control buffers */ - free_page_table_fptr(&g_page_table); - __qae_reset_cache(g_fd); - __qae_destroyList(g_fd, __qae_pUserMemListHead); - __qae_destroyList(g_fd, __qae_pUserLargeMemListHead); - - __qae_pUserCacheHead = NULL; - __qae_pUserCacheTail = NULL; - __qae_pUserMemListHead = NULL; - __qae_pUserMemListTail = NULL; - __qae_pUserLargeMemListHead = NULL; - __qae_pUserLargeMemListTail = NULL; - - __qae_free_special(); - - ret = mem_mutex_unlock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR("%s:%d Error(%d) on thread mutex unlock\n", - __func__, - __LINE__, - ret); - } -} - -API_LOCAL -void *__qae_alloc_addr(size_t size, - const int node, - const size_t phys_alignment_byte) -{ - dev_mem_info_t *p_ctrl_blk = NULL; - void *pVirtAddress = NULL; - size_t allocate_pages = 0; - 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); - size_t requested_pages; - - if (0 != __qae_open()) - return NULL; - - /* Calculate units needed */ - /* First make sure the requested_pages calculation can’t overflow */ - { - size_t max_size = (size_t)(-1); - if ((max_size - reserved - UNIT_SIZE) < size) - return NULL; - } - requested_pages = div_round_up(size, UNIT_SIZE) + reserved; - - if (requested_pages > QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE || - phys_alignment_byte >= QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE) - { - mem_type = LARGE; - /* Huge page and Large memory are mutually exclusive - * Since Large slabs are NOT 2 MB aligned, but huge - * pages are always 2 MB aligned. - */ - if (__qae_hugepage_enabled()) - return NULL; - size = MAX(size, phys_alignment_byte); - allocate_pages = div_round_up(size, UNIT_SIZE); - } - else - { - allocate_pages = QAE_NUM_PAGES_PER_ALLOC * QAE_PAGE_SIZE / UNIT_SIZE; - if (__qae_hugepage_enabled()) - mem_type = HUGE_PAGE; - - p_ctrl_blk = - __qae_find_slab(g_fd, size, node, &pVirtAddress, phys_align_unit); - - if (p_ctrl_blk) - { - p_ctrl_blk->allocations += 1; - return pVirtAddress; - } - } - - /* Try to allocate memory as much as possible */ - p_ctrl_blk = __qae_alloc_slab( - g_fd, allocate_pages * UNIT_SIZE, phys_alignment_byte, node, mem_type); - 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()); - - if (LARGE == mem_type) - { - p_ctrl_blk->allocations = 1; - - ADD_ELEMENT_TO_HEAD_LIST(p_ctrl_blk, - __qae_pUserLargeMemListHead, - __qae_pUserLargeMemListTail, - _user); - - pVirtAddress = p_ctrl_blk->virt_addr; - } - else - { - p_ctrl_blk->allocations = 1; - - if ((uintptr_t)p_ctrl_blk->virt_addr % QAE_PAGE_SIZE) - { - CMD_ERROR("%s:%d Bad virtual address alignment %lux %x %lux\n", - __func__, - __LINE__, - (uintptr_t)p_ctrl_blk->virt_addr, - QAE_NUM_PAGES_PER_ALLOC, - QAE_PAGE_SIZE); - __qae_free_slab(g_fd, p_ctrl_blk); - - return NULL; - } - pVirtAddress = init_slab_and_alloc( - (block_ctrl_t *)p_ctrl_blk, size, phys_align_unit); - if (NULL == pVirtAddress) - { - CMD_ERROR("%s:%d Memory allocation failed Virtual address: %p " - " Size: %zu \n", - __func__, - __LINE__, - p_ctrl_blk, - size); - __qae_free_slab(g_fd, p_ctrl_blk); - - return NULL; - } - } - return pVirtAddress; -} - -void *qaeMemAllocNUMA(size_t size, int node, size_t phys_alignment_byte) -{ - void *pVirtAddress = NULL; - int ret = 0; - - if (!size) - { - CMD_ERROR("%s:%d Size cannot be zero \n", __func__, __LINE__); - 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 || - (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", - __func__, - __LINE__, - phys_alignment_byte, - QAE_MAX_PHYS_ALIGN); - return NULL; - } - - ret = mem_mutex_lock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR("%s:%d Error on thread mutex lock %s\n", - __func__, - __LINE__, - strerror(ret)); - return NULL; - } - - pVirtAddress = __qae_alloc_addr(size, node, phys_alignment_byte); - - ret = mem_mutex_unlock(&mutex); - if (unlikely(ret)) - { - CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", - __func__, - __LINE__, - strerror(ret)); - return NULL; - } - return pVirtAddress; -} - -API_LOCAL -void __qae_free_addr(void **p_va, bool secure_free) -{ - dev_mem_info_t *p_ctrl_blk = NULL; - - if (0 != __qae_open()) - return; - - if ((p_ctrl_blk = find_slab_in_hash(*p_va)) == NULL) - { - CMD_ERROR("%s:%d Unable to free as lookup failed on address (%p) " - "provided \n", - __func__, - __LINE__, - *p_va); - return; - } - if (SMALL == p_ctrl_blk->type || HUGE_PAGE == p_ctrl_blk->type) - { - if (__qae_mem_free((block_ctrl_t *)p_ctrl_blk, *p_va, secure_free)) - { - p_ctrl_blk->allocations -= 1; - } - else - { - /*Skip push_slab(p_ctrl_blk)) and return when mem_free fails */ - CMD_ERROR("%s:%d mem_free returned false (%p) " - "provided \n", - __func__, - __LINE__, - *p_va); - *p_va = NULL; - return; - } - if (p_ctrl_blk->allocations) - { - *p_va = NULL; - return; - } - - REMOVE_ELEMENT_FROM_LIST( - p_ctrl_blk, __qae_pUserMemListHead, __qae_pUserMemListTail, _user); - if (0 != push_slab(p_ctrl_blk)) - __qae_free_slab(g_fd, p_ctrl_blk); - } - else - { - REMOVE_ELEMENT_FROM_LIST(p_ctrl_blk, - __qae_pUserLargeMemListHead, - __qae_pUserLargeMemListTail, - _user); - __qae_free_slab(g_fd, p_ctrl_blk); - } - *p_va = NULL; -} - -/* __qae_memFreeNUMA function - * Frees memory pointed by ptr. - * ptr refers to memory allocated by qaeMemAllocNUMA function. - * secure_free is a boolean to perform memory free secured or not. - */ -API_LOCAL -void __qae_memFreeNUMA(void **ptr, bool secure_free) -{ - int ret = 0; - - if (NULL == ptr) - { - CMD_ERROR( - "%s:%d Input parameter cannot be NULL \n", __func__, __LINE__); - return; - } - if (NULL == *ptr) - { - CMD_ERROR( - "%s:%d Address to be freed cannot be NULL \n", __func__, __LINE__); - return; - } - ret = mem_mutex_lock(&mutex); - if (ret) - { - CMD_ERROR("%s:%d Error on thread mutex lock %s\n", - __func__, - __LINE__, - strerror(ret)); - return; - } - - __qae_free_addr(ptr, secure_free); - - ret = mem_mutex_unlock(&mutex); - if (ret) - { - CMD_ERROR("%s:%d Error on thread mutex unlock %s\n", - __func__, - __LINE__, - strerror(ret)); - } - return; -} - void qaeMemFreeNUMA(void **ptr) { __qae_memFreeNUMA(ptr, true); 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 8fa61fe8..df3ecf4d 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 @@ -97,12 +97,24 @@ #include "qae_page_table_common.h" #include "qae_mem_hugepage_utils.h" +/* Maximum cached memory size, 8 Mb by default */ +#define MAX_CACHE_DEPTH_MB (0x800000) + /* Maximum supported alignment is 4M. */ #define QAE_MAX_PHYS_ALIGN (0x400000ULL) /* Maximum supported allocation is 64M for vfio. */ #define QAE_MAX_ALLOC_SIZE (0x4000000ULL) +#ifdef MADV_WIPEONFORK +#define CACHE_PID +#endif + + +#ifdef CACHE_PID +extern void *cache_pid; +#endif + typedef struct { dev_mem_info_t *head; @@ -113,56 +125,15 @@ typedef struct extern page_table_t g_page_table; extern const uint64_t __qae_bitmask[65]; extern int g_fd; - -#ifndef ICP_THREAD_SPECIFIC_USDM -extern int g_strict_node; -/* Current cached memory size. */ -extern size_t g_cache_size; -/* Maximum cached memory size, 8 Mb by default */ -extern size_t g_max_cache; -/* The maximum number we allow to search for available size */ -extern size_t g_max_lookup_num; - -/* User space hash for fast slab searching */ -extern slab_list_t g_slab_list[PAGE_SIZE]; - -#ifndef ICP_WITHOUT_THREAD -extern pthread_mutex_t mutex; -#endif - -extern dev_mem_info_t *__qae_pUserCacheHead; -extern dev_mem_info_t *__qae_pUserCacheTail; -extern dev_mem_info_t *__qae_pUserMemListHead; -extern dev_mem_info_t *__qae_pUserMemListTail; -extern dev_mem_info_t *__qae_pUserLargeMemListHead; -extern dev_mem_info_t *__qae_pUserLargeMemListTail; - -extern uint32_t numaAllocations_g; -#else -typedef struct -{ - dev_mem_info_t *pUserCacheHead; - dev_mem_info_t *pUserCacheTail; - dev_mem_info_t *pUserMemListHead; - dev_mem_info_t *pUserMemListTail; - dev_mem_info_t *pUserLargeMemListHead; - dev_mem_info_t *pUserLargeMemListTail; - size_t g_cache_size; - size_t g_max_cache; - size_t g_max_lookup_num; - slab_list_t g_slab_list[PAGE_SIZE]; - int g_strict_node; - uint32_t numaAllocations_g; - uint32_t thd_process_id; -} qae_mem_info_t; -#endif - 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; +API_LOCAL +int __qae_open(void); + API_LOCAL void *__qae_mem_alloc(block_ctrl_t *block_ctrl, size_t size, size_t align); @@ -176,78 +147,6 @@ API_LOCAL void *__qae_alloc_addr(size_t size, const int node, const size_t phys_alignment_byte); -#ifndef ICP_THREAD_SPECIFIC_USDM -API_LOCAL -void __qae_ResetControl(void); - -API_LOCAL -dev_mem_info_t *__qae_userMemLookupBySize(size_t size, - int node, - void **block, - const size_t align); - -API_LOCAL -void __qae_free_slab(const int fd, dev_mem_info_t *slab); - -API_LOCAL -dev_mem_info_t *__qae_find_slab(const int fd, - const size_t size, - const int node, - void **addr, - const size_t align); -API_LOCAL -int __qae_open(void); - -API_LOCAL -void __qae_destroyList(const int fd, dev_mem_info_t *pList); - -API_LOCAL -void __qae_reset_cache(const int fd); - -API_LOCAL -int __qae_free_special(void); - -API_LOCAL -dev_mem_info_t *__qae_alloc_slab(const int fd, - const size_t size, - const uint32_t alignment, - const int node, - enum slabType type); -#else -API_LOCAL -dev_mem_info_t *__qae_userMemLookupBySize(size_t size, - int node, - void **block, - const size_t align, - qae_mem_info_t *tls_ptr); - -API_LOCAL -void __qae_free_slab(const int fd, - dev_mem_info_t *slab, - qae_mem_info_t *tls_ptr); - -API_LOCAL -dev_mem_info_t *__qae_find_slab(const int fd, - const size_t size, - const int node, - void **addr, - const size_t align, - qae_mem_info_t *tls_ptr); -API_LOCAL -void __qae_destroyList(const int fd, dev_mem_info_t *pList, void *thread_key); - -API_LOCAL -void __qae_reset_cache(const int fd, void *thread_key); - -API_LOCAL -dev_mem_info_t *__qae_alloc_slab(const int fd, - const size_t size, - const uint32_t alignment, - const int node, - enum slabType type, - qae_mem_info_t *tls_ptr); -#endif - API_LOCAL void __qae_free_addr(void **p_va, bool secure_free); @@ -263,76 +162,7 @@ static inline size_t round_up(const size_t n, const size_t s) { return ((n + s - 1) / s) * s; } -#ifndef ICP_THREAD_SPECIFIC_USDM -static inline void add_slab_to_hash(dev_mem_info_t *slab) -{ - const size_t key = get_key(slab->phy_addr); - - ADD_ELEMENT_TO_HEAD_LIST( - slab, g_slab_list[key].head, g_slab_list[key].tail, _user_hash); -} -static inline void del_slab_from_hash(dev_mem_info_t *slab) -{ - const size_t key = get_key(slab->phy_addr); - - REMOVE_ELEMENT_FROM_LIST( - slab, g_slab_list[key].head, g_slab_list[key].tail, _user_hash); -} - -static inline dev_mem_info_t *find_slab_in_hash(void *virt_addr) -{ - const size_t key = load_key_fptr(&g_page_table, virt_addr); - dev_mem_info_t *slab = g_slab_list[key].head; - - while (slab) - { - uintptr_t offs = (uintptr_t)virt_addr - (uintptr_t)slab->virt_addr; - if (offs < slab->size) - return slab; - slab = slab->pNext_user_hash; - } - - return NULL; -} -#else -static inline void add_slab_to_hash(dev_mem_info_t *slab, - qae_mem_info_t *tls_ptr) -{ - const size_t key = get_key(slab->phy_addr); - ADD_ELEMENT_TO_HEAD_LIST(slab, - tls_ptr->g_slab_list[key].head, - tls_ptr->g_slab_list[key].tail, - _user_hash); -} -static inline void del_slab_from_hash(dev_mem_info_t *slab, - qae_mem_info_t *tls_ptr) -{ - const size_t key = get_key(slab->phy_addr); - - REMOVE_ELEMENT_FROM_LIST(slab, - tls_ptr->g_slab_list[key].head, - tls_ptr->g_slab_list[key].tail, - _user_hash); -} - -static inline dev_mem_info_t *find_slab_in_hash(void *virt_addr, - qae_mem_info_t *tls_ptr) -{ - const size_t key = load_key_fptr(&g_page_table, virt_addr); - dev_mem_info_t *slab = tls_ptr->g_slab_list[key].head; - - while (slab) - { - uintptr_t offs = (uintptr_t)virt_addr - (uintptr_t)slab->virt_addr; - if (offs < slab->size) - return slab; - slab = slab->pNext_user_hash; - } - - return NULL; -} -#endif /* mem_ctzll function * input: a 64-bit bitmap window * output: number of contiguous 0s from least significant bit position @@ -427,116 +257,59 @@ static inline void set_bitmap(uint64_t *bitmap, const size_t index, size_t len) bitmap[qword] |= __qae_bitmask[len]; } -#ifndef ICP_THREAD_SPECIFIC_USDM -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; - - virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); - if (NULL != virt_addr) - { - ADD_ELEMENT_TO_HEAD_LIST( - p_ctrl_blk, __qae_pUserMemListHead, __qae_pUserMemListTail, _user); - } - return virt_addr; -} - -static inline int push_slab(dev_mem_info_t *slab) -{ - if (g_cache_size + slab->size <= g_max_cache) - { - g_cache_size += slab->size; - ADD_ELEMENT_TO_HEAD_LIST( - slab, __qae_pUserCacheHead, __qae_pUserCacheTail, _user); - return 0; - } - return -ENOMEM; -} - -static inline dev_mem_info_t *pop_slab(const int node) +#ifdef CACHE_PID +static inline void uncache_process_id(void) { - dev_mem_info_t *slab = NULL; - - for (slab = __qae_pUserCacheHead; slab != NULL; slab = slab->pNext_user) + int ret = 0; + if (cache_pid != NULL) { - if (node != NUMA_ANY_NODE) - if (g_strict_node && (node != slab->nodeId)) - continue; - - g_cache_size -= slab->size; - REMOVE_ELEMENT_FROM_LIST( - slab, __qae_pUserCacheHead, __qae_pUserCacheTail, _user); - return slab; + ret = qae_munmap(cache_pid, getpagesize()); + if (ret) + { + CMD_ERROR("%s:%d munmap call for cache failed, ret = %d\n", + __func__, + __LINE__, + ret); + } + cache_pid = NULL; } - return NULL; } -#else -static inline void *init_slab_and_alloc(block_ctrl_t *slab, - const size_t size, - const size_t phys_align_unit, - qae_mem_info_t *tls_ptr) +static inline int cache_process_id(void) { - 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; - - virt_addr = __qae_mem_alloc(slab, size, phys_align_unit); - if (NULL != virt_addr) + if (!cache_pid) { - ADD_ELEMENT_TO_HEAD_LIST(p_ctrl_blk, - tls_ptr->pUserMemListHead, - tls_ptr->pUserMemListTail, - _user); + int page_size = getpagesize(); + + cache_pid = qae_mmap(NULL, + page_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, + -1, + 0); + if (cache_pid == NULL) + { + CMD_ERROR( + "%s:%d Unable to mmap aligned memory \n", __func__, __LINE__); + return -ENOMEM; + } + + if (qae_madvise(cache_pid, page_size, MADV_WIPEONFORK)) + { + + CMD_ERROR( + "%s:%d Unable to update page properties\n", __func__, __LINE__); + qae_munmap(cache_pid, page_size); + close(g_fd); + g_fd = -1; + cache_pid = NULL; + return -ENOMEM; + } } - return virt_addr; -} -static inline int push_slab(dev_mem_info_t *slab, qae_mem_info_t *tls_ptr) -{ - if (tls_ptr->g_cache_size + slab->size <= tls_ptr->g_max_cache) - { - tls_ptr->g_cache_size += slab->size; - ADD_ELEMENT_TO_HEAD_LIST( - slab, tls_ptr->pUserCacheHead, tls_ptr->pUserCacheTail, _user); - return 0; - } - return -ENOMEM; -} - -static inline dev_mem_info_t *pop_slab(const int node, qae_mem_info_t *tls_ptr) -{ - dev_mem_info_t *slab = NULL; - - for (slab = tls_ptr->pUserCacheHead; slab != NULL; slab = slab->pNext_user) - { - if (node != NUMA_ANY_NODE) - if (tls_ptr->g_strict_node && (node != slab->nodeId)) - continue; - - tls_ptr->g_cache_size -= slab->size; - REMOVE_ELEMENT_FROM_LIST( - slab, tls_ptr->pUserCacheHead, tls_ptr->pUserCacheTail, _user); - return slab; - } - return NULL; + *((pid_t *)cache_pid) = getpid(); + return 0; } -#endif +#endif /* CACHE_PID */ #ifndef CACHE_PID static inline int check_pid(void) @@ -550,6 +323,18 @@ static inline int check_pid(void) } return 0; } +#endif /* !CACHE_PID */ + +static inline int is_new_process() +{ + /* Check if it is a new process or child. */ +#ifdef CACHE_PID + const int is_new_pid = + cache_pid == NULL || (cache_pid != NULL && *((pid_t *)cache_pid) == 0); +#else + const int is_new_pid = check_pid(); #endif + return is_new_pid; +} #endif /* QAE_MEM_UTILS_COMMON_H */ 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 1fa4f7c4..9c3a30b5 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 @@ -71,20 +71,18 @@ ***************************************************************************/ #include #include "qae_mem_utils_common.h" - -/* Check for process pid caching availability */ -#ifdef MADV_WIPEONFORK -#define CACHE_PID +#ifdef ICP_THREAD_SPECIFIC_USDM +#include "qae_mem_multi_thread.h" +#else +#include "qae_mem_lib_utils.h" #endif #ifdef CACHE_PID -STATIC void *cache_pid = NULL; +void *cache_pid = NULL; #endif - /************************************************************************** macro **************************************************************************/ - #ifdef __x86_64__ #define IOVA_BITS 39 #else @@ -100,6 +98,16 @@ STATIC void *cache_pid = NULL; #define NUM_IOVA_SLABS (1 << (IOVA_BITS - SLAB_BITS)) #define MAX_IOVA ((1ll << IOVA_BITS) - IOVA_SLAB_SIZE) +#ifdef ICP_THREAD_SPECIFIC_USDM +/* Needed to protect iova allocation for GEN2 devices */ +pthread_mutex_t iova_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif /* ICP_THREAD_SPECIFIC_USDM */ + +#ifdef ICP_THREAD_SPECIFIC_USDM +#define PINNED 1 +#define NOT_PINNED 0 +#endif + /************************************************************************** static variable **************************************************************************/ @@ -171,12 +179,32 @@ static int iova_reserve(uint64_t iova, uint32_t size) static void iova_release(uint64_t iova, uint32_t size) { - unsigned slab = IOVA_IDX(iova); + unsigned slab = 0; int count; - int num_slabs = (size + (1 << SLAB_BITS) - 1) >> SLAB_BITS; + int num_slabs = 0; + +#ifdef ICP_THREAD_SPECIFIC_USDM + if (unlikely(mem_mutex_lock(&iova_mutex))) + { + CMD_ERROR( + "%s:%d Error on thread iova_mutex lock\n", __func__, __LINE__); + return; + } +#endif + + slab = IOVA_IDX(iova); + num_slabs = (size + (1 << SLAB_BITS) - 1) >> SLAB_BITS; for (count = 0; count < num_slabs; count++, slab++) clear_bit(iova_used, slab); + +#ifdef ICP_THREAD_SPECIFIC_USDM + if (unlikely(mem_mutex_unlock(&iova_mutex))) + { + CMD_ERROR( + "%s:%d Error on thread iova_mutex unlock\n", __func__, __LINE__); + } +#endif } static inline int dma_map_slab(const void *virt, @@ -217,7 +245,7 @@ static inline int dma_unmap_slab(const uint64_t iova, const size_t size) ret = mem_ioctl(vfio_container_fd, VFIO_IOMMU_UNMAP_DMA, &dma_umap); if (ret) CMD_ERROR( - "%s:%d VFIO_IOMMU_UMAP_DMA failed iova=%llx size%lx -- errno=%d\n", + "%s:%d VFIO_IOMMU_UNMAP_DMA failed iova=%llx size%lx -- errno=%d\n", __func__, __LINE__, dma_umap.iova, @@ -237,6 +265,9 @@ static inline void ioctl_free_slab(const int fd, dev_mem_info_t *memInfo) return; dma_unmap_slab(memInfo->phy_addr, memInfo->size); +#ifdef ICP_THREAD_SPECIFIC_USDM + memInfo->flag_pinned = NOT_PINNED; +#endif } API_LOCAL @@ -251,12 +282,26 @@ void __qae_finish_free_slab(const int fd, dev_mem_info_t *slab) static inline int qaeInitProcess(void) { - if (check_pid()) + if (is_new_process()) { +#ifndef ICP_THREAD_SPECIFIC_USDM __qae_ResetControl(); +#else + free_page_table_fptr(&g_page_table); + memset(&g_page_table, 0, sizeof(g_page_table)); + qae_key = 0; + qae_mem_inited = 0; + qae_key_once = PTHREAD_ONCE_INIT; + g_slab_tmp_list.head = NULL; + g_slab_tmp_list.tail = NULL; +#endif memset(&iova_used, 0, sizeof(iova_used)); next_iova = FIRST_IOVA; +#ifdef CACHE_PID + cache_process_id(); +#endif /* CACHE_PID */ } + return 0; } @@ -270,19 +315,7 @@ API_LOCAL int __qae_free_special(void) { #ifdef CACHE_PID - int ret = 0; - if (cache_pid != NULL) - { - ret = qae_munmap(cache_pid, getpagesize()); - if (ret) - { - CMD_ERROR("%s:%d munmap call for cache failed, ret = %d\n", - __func__, - __LINE__, - ret); - } - cache_pid = NULL; - } + uncache_process_id(); #endif return 0; } @@ -292,6 +325,15 @@ uint64_t allocate_iova(const uint32_t size, uint32_t alignment) uint64_t iova; unsigned tryCount; +#ifdef ICP_THREAD_SPECIFIC_USDM + if (unlikely(mem_mutex_lock(&iova_mutex))) + { + CMD_ERROR( + "%s:%d Error on thread iova_mutex lock %s\n", __func__, __LINE__); + return 0; + } +#endif + /* IOVA alignment must be minimum of IOVA_SLAB_SIZE but may be greater */ alignment = round_up(alignment, IOVA_SLAB_SIZE); iova = round_up(next_iova, alignment); @@ -309,10 +351,28 @@ uint64_t allocate_iova(const uint32_t size, uint32_t alignment) next_iova = iova + round_up(size, IOVA_SLAB_SIZE); if (next_iova > MAX_IOVA) next_iova = FIRST_IOVA; + +#ifdef ICP_THREAD_SPECIFIC_USDM + if (unlikely(mem_mutex_unlock(&iova_mutex))) + { + CMD_ERROR("%s:%d Error on thread iova_mutex unlock %s\n", + __func__, + __LINE__); + return 0; + } +#endif return iova; } } +#ifdef ICP_THREAD_SPECIFIC_USDM + if (unlikely(mem_mutex_unlock(&iova_mutex))) + { + CMD_ERROR( + "%s:%d Error on thread iova_mutex unlock %s\n", __func__, __LINE__); + } +#endif + return 0; } @@ -323,10 +383,13 @@ static inline void *mmap_alloc(const size_t size) ptr = qae_mmap(NULL, size, PROT_READ | PROT_WRITE, flags, -1, 0); - if (qae_madvise(ptr, size, MADV_DONTFORK)) + if (ptr != MAP_FAILED) { - munmap(ptr, size); - ptr = MAP_FAILED; + if (qae_madvise(ptr, size, MADV_DONTFORK)) + { + munmap(ptr, size); + ptr = MAP_FAILED; + } } return (ptr == MAP_FAILED) ? NULL : ptr; @@ -383,13 +446,48 @@ static inline dev_mem_info_t *ioctl_alloc_slab(const int fd, slab->type = type; - /* Defer IOMMU map until container is registered. */ + /* Defer IOMMU map until container is registered. + * This is a use-case where qaeMemAllocNUMA() is invoked before + * process start up. + * NOTE: Regardless of when it is invoked, the + * qaeRegisterDevice()/qaeUnregsiterDevice() would get invoked + * as many number of times as the number of devices found in the + * QAT hardware. However, the pinning and un-pinning occur only + * once based on the value of vfio_container_fd. + */ if (vfio_container_fd < 0) + { +#ifdef ICP_THREAD_SPECIFIC_USDM + /* Save the slab in a TMP list for the deferred pinning. */ + slab->flag_pinned = NOT_PINNED; + save_slab_to_tmp_list(slab); +#endif + /* This is required for adding into hash table.*/ return slab; + } +#ifdef ICP_THREAD_SPECIFIC_USDM + /* In the case of thread specific implementation, the slabs that are + * allocated from different threads should be kept in a global array + * for getting the slab information at the time of pinning and + * un-pinning which is done in qaeRegisterDevice()/qaeUnregisterDevice() + * functions. + * NOTE: A new variable 'flag_pinned' is introduced. As the TMP list is + * being employed to keep all the slabs, we need a marker to later + * identify among the slabs in the TMP list that are already pinned! + * The pinning will take place for the slab in this ioctl_alloc_slab() + * itself if there is a vfio_container_fd active). This flag is required + * to skip those slabs while doing deferred pinning at the + * qaeRegisterDevice() time. + */ + save_slab_to_tmp_list(slab); +#endif if (dma_map_slab(slab->virt_addr, slab->phy_addr, slab->size)) goto error; +#ifdef ICP_THREAD_SPECIFIC_USDM + slab->flag_pinned = PINNED; +#endif return slab; error: @@ -406,6 +504,7 @@ static inline dev_mem_info_t *ioctl_alloc_slab(const int fd, return NULL; } +#ifndef ICP_THREAD_SPECIFIC_USDM API_LOCAL dev_mem_info_t *__qae_alloc_slab(const int fd, const size_t size, @@ -417,21 +516,68 @@ dev_mem_info_t *__qae_alloc_slab(const int fd, slab = ioctl_alloc_slab(fd, size, alignment, node, type); - /* Store a slab into the hash table for a fast lookup. */ + /* Store a slab into the hash table for a fast lookup. + * NOTE: this is not the free list. This hash table is used + * for finding the slab info from virt address quickly + * at the time of qaeMemFreeNUMA code flow. The free list + * is accessed by push_slab()/pop_slab() functions (uses + * tls_ptr->pUserCacheHead/Tail). + */ if (slab) add_slab_to_hash(slab); return slab; } +#else /* ICP_THREAD_SPECIFIC_USDM */ +API_LOCAL +dev_mem_info_t *__qae_alloc_slab(const int fd, + const size_t size, + const uint32_t alignment, + const int node, + enum slabType type, + qae_mem_info_t *tls_ptr) +{ + dev_mem_info_t *slab = NULL; + + slab = ioctl_alloc_slab(fd, size, alignment, node, type); + + /* Store a slab into the hash table for a fast lookup. + * NOTE: this is not the free list. This hash table is used + * for finding the slab info from virt address quickly + * at the time of qaeMemFreeNUMA code flow. The free list + * is accessed by push_slab()/pop_slab() functions (uses + * tls_ptr->pUserCacheHead/Tail). + */ + if (slab) + add_slab_to_hash(slab, tls_ptr); + + return slab; +} +#endif /* ICP_THREAD_SPECIFIC_USDM */ static int dma_map_slabs(dev_mem_info_t *pList) { dev_mem_info_t *slab; - for (slab = pList; slab != NULL; slab = slab->pNext_user) + for (slab = pList; slab != NULL;) { +#ifdef ICP_THREAD_SPECIFIC_USDM + /* Do the deferred pinning only on slabs in the TMP list that + * are NOT pinned at ioctl_alloc_slab() + */ + if (slab->flag_pinned == NOT_PINNED) + { + if (dma_map_slab(slab->virt_addr, slab->phy_addr, slab->size)) + return 1; + /* now that slab has been PINNED, mark it */ + slab->flag_pinned = PINNED; + } + slab = slab->pNext_user_vfiotmp; +#else if (dma_map_slab(slab->virt_addr, slab->phy_addr, slab->size)) return 1; + slab = slab->pNext_user; +#endif } return 0; } @@ -440,10 +586,22 @@ static int dma_unmap_slabs(dev_mem_info_t *pList) { dev_mem_info_t *slab; - for (slab = pList; slab != NULL; slab = slab->pNext_user) + for (slab = pList; slab != NULL;) { +#ifdef ICP_THREAD_SPECIFIC_USDM + if (slab->flag_pinned == PINNED) + { + if (dma_unmap_slab(slab->phy_addr, slab->size)) + return 1; + + slab->flag_pinned = NOT_PINNED; + } + slab = slab->pNext_user_vfiotmp; +#else if (dma_unmap_slab(slab->phy_addr, slab->size)) return 1; + slab = slab->pNext_user; +#endif } return 0; } @@ -551,6 +709,7 @@ static int filter_dma_ranges(int fd) } #endif +#ifndef ICP_THREAD_SPECIFIC_USDM int qaeRegisterDevice(int fd) { int ret = 0; @@ -561,10 +720,15 @@ int qaeRegisterDevice(int fd) if (qaeInitProcess()) { - CMD_ERROR("Failed to init qae process \n"); + CMD_ERROR("Failed to init qae process\n"); return -1; } + /* When a new process is spawned then that means that + * a new container is brought up, so we need to do + * necessary actions, like, pinning memory of that process + * to IOMMU (associate memory to the new container). + */ if (pid != vfio_pid) { vfio_pid = pid; @@ -630,3 +794,125 @@ int qaeUnregisterDevice(int fd) } return ret; } +#else /* ICP_THREAD_SPECIFIC_USDM */ +/* The memory pinning operation is usually performed at the memory allocation + * time itself but there are use cases where the application may allocate + * memory before it has registered with USDM. In such cases, the pinning + * will be deferred until a container_fd is active (the fd argument + * to the qaeRegisterDevice() is exactly that). The expectation is that the + * allocated memory is then pinned within qaeRegisterDevice() so that it + * can be used for DMA. + */ +int qaeRegisterDevice(int fd) +{ + int ret = 0; + dev_mem_info_t *slab; + + pid_t pid = getpid(); + + if (filter_dma_ranges(fd)) + return -1; + + if (qaeInitProcess()) + { + CMD_ERROR("Failed to init qae process\n"); + return -1; + } + + /* When a new process is spawned then that means that + * a new container is brought up, so we need to do + * necessary actions, like, pinning memory of that process + * to IOMMU (associate memory to the new container). + */ + if (pid != vfio_pid) + { + vfio_pid = pid; + vfio_container_fd = -1; + vfio_container_ref = 0; + } + + if (vfio_container_fd < 0) + { + vfio_container_fd = fd; + + /* Do the memory pinning by referring to the TMP list */ + if (unlikely(mem_mutex_lock(&mutex_tmp_list))) + { + CMD_ERROR("%s:%d Error on temp mutex lock\n", __func__, __LINE__); + return -EIO; + } + slab = g_slab_tmp_list.head; + if (slab != NULL) + { + if (dma_map_slabs(slab)) + { + vfio_container_fd = -1; + ret = 1; + } + } + if (unlikely(mem_mutex_unlock(&mutex_tmp_list))) + { + CMD_ERROR( + "%s:%d Error on temp mutex unlock %s\n", __func__, __LINE__); + return -EIO; + } + if (ret) + return 1; + } + + if (fd == vfio_container_fd) + { + vfio_container_ref++; + } + else + { + CMD_ERROR("%s:%d Invalid container fd %d != %d\n", + __func__, + __LINE__, + fd, + vfio_container_fd); + ret = 1; + } + + return ret; +} + +int qaeUnregisterDevice(int fd) +{ + int ret = 0; + dev_mem_info_t *slab; + + pid_t pid = getpid(); + + if (vfio_container_ref <= 0 || vfio_container_fd != fd) + return 1; + + if (pid != vfio_pid) + return 0; + + if (--vfio_container_ref == 0) + { + /* Do the memory un-pinning by referring to the TMP list */ + if (unlikely(mem_mutex_lock(&mutex_tmp_list))) + { + CMD_ERROR("%s:%d Error on temp mutex lock\n", __func__, __LINE__); + return -EIO; + } + slab = g_slab_tmp_list.head; + if (slab != NULL) + { + if (dma_unmap_slabs(slab)) + ret = 1; + } + if (unlikely(mem_mutex_unlock(&mutex_tmp_list))) + { + CMD_ERROR( + "%s:%d Error on temp mutex unlock %s\n", __func__, __LINE__); + return -EIO; + } + vfio_container_fd = -1; + } + + return ret; +} +#endif /* ICP_THREAD_SPECIFIC_USDM */ diff --git a/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c b/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c index 03f46180..6086fa79 100644 --- a/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c +++ b/quickassist/utilities/osal/src/linux/user_space/OsalUsrKrnProxy.c @@ -741,8 +741,19 @@ OSAL_PUBLIC void *osalMemAllocContiguousNUMA(UINT32 size, alloc_size = allocate_pages * PAGE_SIZE; } - pMemInfo = calloc(USER_MEM_128BYTE_OFFSET + BITMAP_LEN * sizeof(UINT64), - sizeof(UINT8)); + /* 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, @@ -828,7 +839,13 @@ OSAL_PUBLIC void *osalMemAllocContiguousNUMA(UINT32 size, pMemInfo->available_size = alloc_size - size - USER_MEM_128BYTE_OFFSET; pMemInfo->virt_addr = pMemInfo->fvirt_addr; pMemInfo->fvirt_addr = 0; - userLargeMemListAdd(pMemInfo); + 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); } @@ -942,7 +959,30 @@ OSAL_PUBLIC void *osalMemAllocPage(UINT32 node, UINT64 *physAddr) return NULL; } - userMemListAddPage(pMemInfo); + 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; } diff --git a/quickassist/utilities/qat_mgr/qat_mgr.c b/quickassist/utilities/qat_mgr/qat_mgr.c index 1fc20625..0ddfa58d 100644 --- a/quickassist/utilities/qat_mgr/qat_mgr.c +++ b/quickassist/utilities/qat_mgr/qat_mgr.c @@ -121,11 +121,12 @@ void *handle_client(void *arg) int index = -1; pid_t tid; int conn_fd; - struct qatmgr_msg_req msgreq; - struct qatmgr_msg_rsp msgrsp; + struct qatmgr_msg_req msgreq = { 0 }; + struct qatmgr_msg_rsp msgrsp = { 0 }; char *section_name = NULL; struct pollfd fd; int ret = -1; + int write_errno = 0; conn_fd = (intptr_t)arg; tid = pthread_self(); @@ -155,7 +156,9 @@ void *handle_client(void *arg) handle_message(&msgreq, &msgrsp, §ion_name, tid, &index); /* Send response */ + errno = 0; bytes_w = write(conn_fd, (const void *)&msgrsp, msgrsp.hdr.len); + write_errno = errno; if (bytes_w < 0) break; @@ -178,7 +181,8 @@ void *handle_client(void *arg) if (bytes_r < 0 || bytes_w < 0) { - qat_log(LOG_LEVEL_ERROR, "Socket read/write error %d\n", errno); + qat_log( + LOG_LEVEL_ERROR, "Socket read/write error %d\n", write_errno); } else if (bytes_r == 0) { @@ -386,6 +390,7 @@ static int parse_and_validate_arg(char *arg, int *val, int min, int max) return -EINVAL; char *end_ptr; + errno = 0; long long temp = strtoll(arg, &end_ptr, 10); if (errno == ERANGE || *arg == 0 || *end_ptr != 0 || temp < min || @@ -417,12 +422,11 @@ int main(int argc, char **argv) unsigned list_size = ARRAY_SIZE(dev_list); int i; const char *mgr_opts = "hvd:p:f"; - const struct option mgr_optl[] = {{"help", 0, NULL, 'h'}, - {"version", 0, NULL, 'v'}, - {"debug", 1, NULL, 'd'}, - {"policy", 1, NULL, 'p'}, - {"foreground", 0, NULL, 'f'}, - {NULL, 0, NULL, 0}}; + const struct option mgr_optl[] = { + { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'v' }, + { "debug", 1, NULL, 'd' }, { "policy", 1, NULL, 'p' }, + { "foreground", 0, NULL, 'f' }, { NULL, 0, NULL, 0 } + }; int opt; int policy = 0; int foreground = 0; @@ -520,7 +524,7 @@ int main(int argc, char **argv) "Device %d, %X, %04x:%02x:%02x.%01x\n", i, dev_list[i].bdf, - BDF_NODE(dev_list[i].bdf), + BDF_DOMAIN(dev_list[i].bdf), BDF_BUS(dev_list[i].bdf), BDF_DEV(dev_list[i].bdf), BDF_FUN(dev_list[i].bdf)); diff --git a/versionfile b/versionfile index 508c0547..a35052a6 100644 --- a/versionfile +++ b/versionfile @@ -1,11 +1,11 @@ -PACKAGE_TYPE=QAT_UPSTREAM_24.02.0 +PACKAGE_TYPE=QAT_UPSTREAM PACKAGE_OS=L PACKAGE_VERSION_MAJOR_NUMBER=24 -PACKAGE_VERSION_MINOR_NUMBER=02 +PACKAGE_VERSION_MINOR_NUMBER=09 PACKAGE_VERSION_PATCH_NUMBER=0 -PACKAGE_VERSION_BUILD_NUMBER=00004 +PACKAGE_VERSION_BUILD_NUMBER=00002