Deploying UADK

UADK is a framekwork for user application to access hardware, and it depends
UACCE in kernel.


1. Kernel Requirement

User needs to make sure that UACCE is already supported in Linux kernel. The
kernel version should be at least v5.9 with SVA (Shared Virtual Addressing)
enabled.


2. Kernel Configuration

UACCE could be built as module or built-in.

Here's an example to enable UACCE with hardware accelerator in Hisilicon
platform.

    CONFIG_IOMMU_SVA_LIB=y
    CONFIG_ARM_SMMU=y
    CONFIG_ARM_SMMU_V3=y
    CONFIG_ARM_SMMU_V3_SVA=y
    CONFIG_PCI_PASID=y
    CONFIG_UACCE=y
    CONFIG_CRYPTO_DEV_HISI_SEC2=y
    CONFIG_CRYPTO_DEV_HISI_QM=y
    CONFIG_CRYPTO_DEV_HISI_ZIP=y
    CONFIG_CRYPTO_DEV_HISI_HPRE=y

Make sure all these above kernel configurations are selected.

Build kernel and install the kernel image on Hisilicon platform.


3. Build UADK in native environment

Configure UADK

    $ ./cleanup.sh

    Make sure that all generated files could be removed.

    $ ./autogen.sh
    $ ./conf.sh

    UADK could be configured as either static or dynamic library by conf.sh.
    By default, it's configured as dynamic library.

    $ make
    $ sudo make install

    Both dynamic and static libraries would be installed in /usr/local/lib
    directory. And all head files would be installed in /usr/local/include/uadk
    directory.


4. Set proper permission on device nodes

Harware accelerators register in UADK. So char devices are created in dev
directory. In order to make user access resources on hardware accelerators,
write permission should be opened to user.

    $ sudo chmod 777 /dev/hisi_hpre-*
    $ sudo chmod 777 /dev/hisi_sec-*
    $ sudo chmod 777 /dev/hisi_zip-*


5. Run test applications

Test on zip hardware accelerator

    Synchronous mode
    $ zip_sva_perf -b 8192000 -l 1000 -v -m 0
    Asynchronous mode
    $ zip_sva_perf -b 8192000 -l 1000 -v -m 1

Test on sec hardware accelerator

    Synchronous mode
    $ test_hisi_sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 --times 1 --sync --multi 1
    $ test_hisi_sec --digest 0 --optype 0 --pktlen 16 --keylen 16 --times 1 --sync --multi 1
    Asynchronous mode
    $ test_hisi_sec --cipher 0 --optype 0 --pktlen 16 --keylen 16 --times 1 --async --multi 1
    $ test_hisi_sec --digest 0 --optype 0 --pktlen 16 --keylen 16 --times 1 --async --multi 1

Test on hpre hardware accelerator

    Synchronous mode
    $ test_hisi_hpre --trd_mode=sync
    Asynchronous mode
    $ test_hisi_hpre --trd_mode=async


6. (Optional) Build UADK by cross compiler

  Since some libraries are used in UADK library and test cases, these
  libraries should be built first and installed into the path of cross
  compiler.

  ${LIBROOT} and ${CROSSTOOLCHAIN} is a directory that should be defined
  by user. linaro-gcc-7.2.1 is used for reference at here.

  a) Build NUMA library

    $git clone https://github.com/numactl/numactl.git
    $cd numactl
    $./autogen.sh
    $autoconf -i
    $CC=aarch64-linux-gnu-gcc ./configure --host=i386-linux-gnu --target=aarch64-linux-gnu --prefix=${LIBROOT}/usr/local
    $make
    $make install

    Install head files and libraries into the path of cross compiler by manual.
    $sudo cp ${LIBROOT}/usr/local/include/numa*.h  ${CROSSTOOLCHAIN}/aarch64-linux-gnu/libc/usr/include/
    $sudo cp ${LIBROOT}/usr/local/lib/libnuma.a ${CROSSTOOLCHAIN}/lib/gcc/aarch64-linux-gnu/7.2.1/
    $sudo cp ${LIBROOT}/usr/local/lib/libnuma.so.1.0.0 ${CROSSTOOLCHAIN}/lib/gcc/aarch64-linux-gnu/7.2.1/
    $cd ${CROSSTOOLCHAIN}/lib/gcc/aarch64-linux-gnu/7.2.1
    $sudo ln -sf libnuma.so.1.0.0 libnuma.so.1
    $sudo ln -sf libnuma.so.1 libnuma.so

  b) Build OpenSSL library

    $git clone https://github.com/openssl/openssl.git
    $cd openssl
    $git checkout OpenSSL_1_1_1a
    $./Configure linux-aarch64 --cross-compile-prefix=aarch64-linux-gnu- -D__ARCH_MAX_ARCH__=8 --prefix=${LIBROOT}/usr/local --shared
    $make
    $make install

    $sudo cp -a ${LIBROOT}/usr/local/include/openssl ${CROSSTOOLCHAIN}/aarch64-linux-gnu/libc/usr/include/
    $cd ${CROSSTOOLCHAIN}/lib/gcc/aarch64-linux-gnu/7.2.1
    $sudo cp ${LIBROOT}/usr/local/lib/libcrypto.a .
    $sudo cp ${LIBROOT}/usr/local/lib/libcrypto.so.3 .
    $sudo cp ${LIBROOT}/usr/local/lib/libssl.a .
    $sudo cp ${LIBROOT}/usr/local/lib/libssl.so.3 .
    $sudo ln -sf libcrypto.so.3 libcrypto.so
    $sudo ln -sf libssl.so.3 libssl.so

  c) Build zlib library

    $git clone https://github.com/madler/zlib
    $cd zlib
    $CC=aarch64-linux-gnu-gcc \
       AR=aarch64-linux-gnu-ar \
       RANLIB=aarch64-linux-gnu-ranlib \
       ./configure --prefix=${LIBROOT}/usr/local
    $CC=aarch64-linux-gnu-gcc \
       AR=aarch64-linux-gnu-ar \
       RANLIB=aarch64-linux-gnu-ranlib \
       make
    $make install

    $sudo cp ${LIBROOT}/usr/local/include/zconf.h ${CROSSTOOLCHAIN}/aarch64-linux-gnu/libc/usr/include/
    $sudo cp ${LIBROOT}/usr/local/include/zlib.h ${CROSSTOOLCHAIN}/aarch64-linux-gnu/libc/usr/include/
    $cd ${CROSSTOOLCHAIN}/lib/gcc/aarch64-linux-gnu/7.2.1
    $sudo cp ${LIBROOT}/usr/local/lib/libz.a .
    $sudo cp ${LIBROOT}/usr/local/lib/libz.so.1.2.11 .
    $sudo ln -sf libz.so.1.2.11 libz.so.1
    $sudo ln -sf libz.so.1 libz.so


  d) Build UADK and install it into user specified directory

    $cd ${UADK}
    $./cleanup.sh
    $./autogen.sh
    $CC=aarch64-linux-gnu-gcc \
       ac_cv_func_malloc_0_nonnull=yes \
       ac_cv_func_realloc_0_nonnull=yes \
       ./configure \
         --host=i386-linux-gnu \
         --target=aarch64-linux-gnu \
         --prefix=${LIB_ROOT}/usr/local \
         --includedir=${LIB_ROOT}/usr/local/include/uadk \
         --disable-static --enable-shared
    $make
    $make install
