sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget(/translations/zh_CN/arch/powerpc/vas-apimodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/zh_TW/arch/powerpc/vas-apimodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/it_IT/arch/powerpc/vas-apimodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ja_JP/arch/powerpc/vas-apimodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/ko_KR/arch/powerpc/vas-apimodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget(/translations/sp_SP/arch/powerpc/vas-apimodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhB/var/lib/git/docbuild/linux/Documentation/arch/powerpc/vas-api.rsthKubhtarget)}(h .. _VAS-API:h]h}(h]h ]h"]h$]h&]refidvas-apiuh1hhKhhhhhhubhsection)}(hhh](htitle)}(h3Virtual Accelerator Switchboard (VAS) userspace APIh]h3Virtual Accelerator Switchboard (VAS) userspace API}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Introductionh]h Introduction}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh paragraph)}(hXPower9 processor introduced Virtual Accelerator Switchboard (VAS) which allows both userspace and kernel communicate to co-processor (hardware accelerator) referred to as the Nest Accelerator (NX). The NX unit comprises of one or more hardware engines or co-processor types such as 842 compression, GZIP compression and encryption. On power9, userspace applications will have access to only GZIP Compression engine which supports ZLIB and GZIP compression algorithms in the hardware.h]hXPower9 processor introduced Virtual Accelerator Switchboard (VAS) which allows both userspace and kernel communicate to co-processor (hardware accelerator) referred to as the Nest Accelerator (NX). The NX unit comprises of one or more hardware engines or co-processor types such as 842 compression, GZIP compression and encryption. On power9, userspace applications will have access to only GZIP Compression engine which supports ZLIB and GZIP compression algorithms in the hardware.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hXTo communicate with NX, kernel has to establish a channel or window and then requests can be submitted directly without kernel involvement. Requests to the GZIP engine must be formatted as a co-processor Request Block (CRB) and these CRBs must be submitted to the NX using COPY/PASTE instructions to paste the CRB to hardware address that is associated with the engine's request queue.h]hXTo communicate with NX, kernel has to establish a channel or window and then requests can be submitted directly without kernel involvement. Requests to the GZIP engine must be formatted as a co-processor Request Block (CRB) and these CRBs must be submitted to the NX using COPY/PASTE instructions to paste the CRB to hardware address that is associated with the engine’s request queue.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hThe GZIP engine provides two priority levels of requests: Normal and High. Only Normal requests are supported from userspace right now.h]hThe GZIP engine provides two priority levels of requests: Normal and High. Only Normal requests are supported from userspace right now.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hThis document explains userspace API that is used to interact with kernel to setup channel / window which can be used to send compression requests directly to NX accelerator.h]hThis document explains userspace API that is used to interact with kernel to setup channel / window which can be used to send compression requests directly to NX accelerator.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h] introductionah ]h"] introductionah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(hOverviewh]hOverview}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj*hhhhhK#ubh)}(hX0Application access to the GZIP engine is provided through /dev/crypto/nx-gzip device node implemented by the VAS/NX device driver. An application must open the /dev/crypto/nx-gzip device to obtain a file descriptor (fd). Then should issue VAS_TX_WIN_OPEN ioctl with this fd to establish connection to the engine. It means send window is opened on GZIP engine for this process. Once a connection is established, the application should use the mmap() system call to map the hardware address of engine's request queue into the application's virtual address space.h]hX4Application access to the GZIP engine is provided through /dev/crypto/nx-gzip device node implemented by the VAS/NX device driver. An application must open the /dev/crypto/nx-gzip device to obtain a file descriptor (fd). Then should issue VAS_TX_WIN_OPEN ioctl with this fd to establish connection to the engine. It means send window is opened on GZIP engine for this process. Once a connection is established, the application should use the mmap() system call to map the hardware address of engine’s request queue into the application’s virtual address space.}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hj*hhubh)}(hX;The application can then submit one or more requests to the engine by using copy/paste instructions and pasting the CRBs to the virtual address (aka paste_address) returned by mmap(). User space can close the established connection or send window by closing the file descriptor (close(fd)) or upon the process exit.h]hX;The application can then submit one or more requests to the engine by using copy/paste instructions and pasting the CRBs to the virtual address (aka paste_address) returned by mmap(). User space can close the established connection or send window by closing the file descriptor (close(fd)) or upon the process exit.}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hj*hhubh)}(hNote that applications can send several requests with the same window or can establish multiple windows, but one window for each file descriptor.h]hNote that applications can send several requests with the same window or can establish multiple windows, but one window for each file descriptor.}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK4hj*hhubh)}(hXFollowing sections provide additional details and references about the individual steps.h]hXFollowing sections provide additional details and references about the individual steps.}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hj*hhubeh}(h]overviewah ]h"]overviewah$]h&]uh1hhhhhhhhK#ubh)}(hhh](h)}(hNX-GZIP Device Nodeh]hNX-GZIP Device Node}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj{hhhhhK;ubh)}(hThere is one /dev/crypto/nx-gzip node in the system and it provides access to all GZIP engines in the system. The only valid operations on /dev/crypto/nx-gzip are:h]hThere is one /dev/crypto/nx-gzip node in the system and it provides access to all GZIP engines in the system. The only valid operations on /dev/crypto/nx-gzip are:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hj{hhubh block_quote)}(h* open() the device for read and write. * issue VAS_TX_WIN_OPEN ioctl * mmap() the engine's request queue into application's virtual address space (i.e. get a paste_address for the co-processor engine). * close the device node. h]h bullet_list)}(hhh](h list_item)}(h%open() the device for read and write.h]h)}(hjh]h%open() the device for read and write.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKAhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hissue VAS_TX_WIN_OPEN ioctlh]h)}(hjh]hissue VAS_TX_WIN_OPEN ioctl}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKBhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hmmap() the engine's request queue into application's virtual address space (i.e. get a paste_address for the co-processor engine).h]h)}(hmmap() the engine's request queue into application's virtual address space (i.e. get a paste_address for the co-processor engine).h]hmmap() the engine’s request queue into application’s virtual address space (i.e. get a paste_address for the co-processor engine).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hclose the device node. h]h)}(hclose the device node.h]hclose the device node.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKFhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]bullet*uh1jhhhKAhjubah}(h]h ]h"]h$]h&]uh1jhhhKAhj{hhubh)}(h8Other file operations on this device node are undefined.h]h8Other file operations on this device node are undefined.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhj{hhubh)}(hNote that the copy and paste operations go directly to the hardware and do not go through this device. Refer COPY/PASTE document for more details.h]hNote that the copy and paste operations go directly to the hardware and do not go through this device. Refer COPY/PASTE document for more details.}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKJhj{hhubh)}(hXAlthough a system may have several instances of the NX co-processor engines (typically, one per P9 chip) there is just one /dev/crypto/nx-gzip device node in the system. When the nx-gzip device node is opened, Kernel opens send window on a suitable instance of NX accelerator. It finds CPU on which the user process is executing and determine the NX instance for the corresponding chip on which this CPU belongs.h]hXAlthough a system may have several instances of the NX co-processor engines (typically, one per P9 chip) there is just one /dev/crypto/nx-gzip device node in the system. When the nx-gzip device node is opened, Kernel opens send window on a suitable instance of NX accelerator. It finds CPU on which the user process is executing and determine the NX instance for the corresponding chip on which this CPU belongs.}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKNhj{hhubh)}(hApplications may chose a specific instance of the NX co-processor using the vas_id field in the VAS_TX_WIN_OPEN ioctl as detailed below.h]hApplications may chose a specific instance of the NX co-processor using the vas_id field in the VAS_TX_WIN_OPEN ioctl as detailed below.}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhj{hhubh)}(hFA userspace library libnxz is available here but still in development:h]hFA userspace library libnxz is available here but still in development:}(hjKhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKYhj{hhubj)}(h%https://github.com/abalib/power-gzip h]h)}(h$https://github.com/abalib/power-gziph]h reference)}(hj_h]h$https://github.com/abalib/power-gzip}(hjchhhNhNubah}(h]h ]h"]h$]h&]refurij_uh1jahj]ubah}(h]h ]h"]h$]h&]uh1hhhhK[hjYubah}(h]h ]h"]h$]h&]uh1jhhhK[hj{hhubh)}(hApplications that use inflate / deflate calls can link with libnxz instead of libz and use NX GZIP compression without any modification.h]hApplications that use inflate / deflate calls can link with libnxz instead of libz and use NX GZIP compression without any modification.}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK]hj{hhubeh}(h]nx-gzip-device-nodeah ]h"]nx-gzip device nodeah$]h&]uh1hhhhhhhhK;ubh)}(hhh](h)}(hOpen /dev/crypto/nx-gziph]hOpen /dev/crypto/nx-gzip}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKaubh)}(hThe nx-gzip device should be opened for read and write. No special privileges are needed to open the device. Each window corresponds to one file descriptor. So if the userspace process needs multiple windows, several open calls have to be issued.h]hThe nx-gzip device should be opened for read and write. No special privileges are needed to open the device. Each window corresponds to one file descriptor. So if the userspace process needs multiple windows, several open calls have to be issued.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKchjhhubh)}(hhSee open(2) system call man pages for other details such as return values, error codes and restrictions.h]hhSee open(2) system call man pages for other details such as return values, error codes and restrictions.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhjhhubeh}(h]open-dev-crypto-nx-gzipah ]h"]open /dev/crypto/nx-gzipah$]h&]uh1hhhhhhhhKaubh)}(hhh](h)}(hVAS_TX_WIN_OPEN ioctlh]hVAS_TX_WIN_OPEN ioctl}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKlubh)}(hsApplications should use the VAS_TX_WIN_OPEN ioctl as follows to establish a connection with NX co-processor engine:h]hsApplications should use the VAS_TX_WIN_OPEN ioctl as follows to establish a connection with NX co-processor engine:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjhhubj)}(hX:: struct vas_tx_win_open_attr { __u32 version; __s16 vas_id; /* specific instance of vas or -1 for default */ __u16 reserved1; __u64 flags; /* For future use */ __u64 reserved2[6]; }; version: The version field must be currently set to 1. vas_id: If '-1' is passed, kernel will make a best-effort attempt to assign an optimal instance of NX for the process. To select the specific VAS instance, refer "Discovery of available VAS engines" section below. flags, reserved1 and reserved2[6] fields are for future extension and must be set to 0. The attributes attr for the VAS_TX_WIN_OPEN ioctl are defined as follows:: #define VAS_MAGIC 'v' #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 1, struct vas_tx_win_open_attr) struct vas_tx_win_open_attr attr; rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr); The VAS_TX_WIN_OPEN ioctl returns 0 on success. On errors, it returns -1 and sets the errno variable to indicate the error. Error conditions: ====== ================================================ EINVAL fd does not refer to a valid VAS device. EINVAL Invalid vas ID EINVAL version is not set with proper value EEXIST Window is already opened for the given fd ENOMEM Memory is not available to allocate window ENOSPC System has too many active windows (connections) opened EINVAL reserved fields are not set to 0. ====== ================================================ See the ioctl(2) man page for more details, error codes and restrictions. h](h literal_block)}(hXstruct vas_tx_win_open_attr { __u32 version; __s16 vas_id; /* specific instance of vas or -1 for default */ __u16 reserved1; __u64 flags; /* For future use */ __u64 reserved2[6]; };h]hXstruct vas_tx_win_open_attr { __u32 version; __s16 vas_id; /* specific instance of vas or -1 for default */ __u16 reserved1; __u64 flags; /* For future use */ __u64 reserved2[6]; };}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKshjubhdefinition_list)}(hhh](hdefinition_list_item)}(h6version: The version field must be currently set to 1.h](hterm)}(hversion:h]hversion:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhK|hjubh definition)}(hhh]h)}(h-The version field must be currently set to 1.h]h-The version field must be currently set to 1.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK}hjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhhhK|hjubj)}(hvas_id: If '-1' is passed, kernel will make a best-effort attempt to assign an optimal instance of NX for the process. To select the specific VAS instance, refer "Discovery of available VAS engines" section below. h](j)}(hvas_id:h]hvas_id:}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhKhj5ubj)}(hhh]h)}(hIf '-1' is passed, kernel will make a best-effort attempt to assign an optimal instance of NX for the process. To select the specific VAS instance, refer "Discovery of available VAS engines" section below.h]hIf ‘-1’ is passed, kernel will make a best-effort attempt to assign an optimal instance of NX for the process. To select the specific VAS instance, refer “Discovery of available VAS engines” section below.}(hjJhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjGubah}(h]h ]h"]h$]h&]uh1jhj5ubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjubh)}(hWflags, reserved1 and reserved2[6] fields are for future extension and must be set to 0.h]hWflags, reserved1 and reserved2[6] fields are for future extension and must be set to 0.}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hJThe attributes attr for the VAS_TX_WIN_OPEN ioctl are defined as follows::h]hIThe attributes attr for the VAS_TX_WIN_OPEN ioctl are defined as follows:}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(h#define VAS_MAGIC 'v' #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 1, struct vas_tx_win_open_attr) struct vas_tx_win_open_attr attr; rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr);h]h#define VAS_MAGIC 'v' #define VAS_TX_WIN_OPEN _IOW(VAS_MAGIC, 1, struct vas_tx_win_open_attr) struct vas_tx_win_open_attr attr; rc = ioctl(fd, VAS_TX_WIN_OPEN, &attr);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjubh)}(h{The VAS_TX_WIN_OPEN ioctl returns 0 on success. On errors, it returns -1 and sets the errno variable to indicate the error.h]h{The VAS_TX_WIN_OPEN ioctl returns 0 on success. On errors, it returns -1 and sets the errno variable to indicate the error.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hError conditions:h]hError conditions:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hX====== ================================================ EINVAL fd does not refer to a valid VAS device. EINVAL Invalid vas ID EINVAL version is not set with proper value EEXIST Window is already opened for the given fd ENOMEM Memory is not available to allocate window ENOSPC System has too many active windows (connections) opened EINVAL reserved fields are not set to 0. ====== ================================================ h]htable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK0uh1jhjubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(hEINVALh]hEINVAL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h(fd does not refer to a valid VAS device.h]h(fd does not refer to a valid VAS device.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hEINVALh]hEINVAL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hInvalid vas IDh]hInvalid vas ID}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj.ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hEINVALh]hEINVAL}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjNubah}(h]h ]h"]h$]h&]uh1jhjKubj)}(hhh]h)}(h$version is not set with proper valueh]h$version is not set with proper value}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjeubah}(h]h ]h"]h$]h&]uh1jhjKubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hEEXISTh]hEEXIST}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h)Window is already opened for the given fdh]h)Window is already opened for the given fd}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hENOMEMh]hENOMEM}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h*Memory is not available to allocate windowh]h*Memory is not available to allocate window}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hENOSPCh]hENOSPC}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h7System has too many active windows (connections) openedh]h7System has too many active windows (connections) opened}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hEINVALh]hEINVAL}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj*ubah}(h]h ]h"]h$]h&]uh1jhj'ubj)}(hhh]h)}(h!reserved fields are not set to 0.h]h!reserved fields are not set to 0.}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjAubah}(h]h ]h"]h$]h&]uh1jhj'ubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hISee the ioctl(2) man page for more details, error codes and restrictions.h]hISee the ioctl(2) man page for more details, error codes and restrictions.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKqhjhhubeh}(h]vas-tx-win-open-ioctlah ]h"]vas_tx_win_open ioctlah$]h&]uh1hhhhhhhhKlubh)}(hhh](h)}(hmmap() NX-GZIP deviceh]hmmap() NX-GZIP device}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hThe mmap() system call for a NX-GZIP device fd returns a paste_address that the application can use to copy/paste its CRB to the hardware engines.h]hThe mmap() system call for a NX-GZIP device fd returns a paste_address that the application can use to copy/paste its CRB to the hardware engines.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX:: paste_addr = mmap(addr, size, prot, flags, fd, offset); Only restrictions on mmap for a NX-GZIP device fd are: * size should be PAGE_SIZE * offset parameter should be 0ULL Refer to mmap(2) man page for additional details/restrictions. In addition to the error conditions listed on the mmap(2) man page, can also fail with one of the following error codes: ====== ============================================= EINVAL fd is not associated with an open window (i.e mmap() does not follow a successful call to the VAS_TX_WIN_OPEN ioctl). EINVAL offset field is not 0ULL. ====== ============================================= h](j)}(h7paste_addr = mmap(addr, size, prot, flags, fd, offset);h]h7paste_addr = mmap(addr, size, prot, flags, fd, offset);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjubh)}(h6Only restrictions on mmap for a NX-GZIP device fd are:h]h6Only restrictions on mmap for a NX-GZIP device fd are:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(h=* size should be PAGE_SIZE * offset parameter should be 0ULL h]j)}(hhh](j)}(hsize should be PAGE_SIZEh]h)}(hjh]hsize should be PAGE_SIZE}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h offset parameter should be 0ULL h]h)}(hoffset parameter should be 0ULLh]hoffset parameter should be 0ULL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]j j uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1jhhhKhjubh)}(hRefer to mmap(2) man page for additional details/restrictions. In addition to the error conditions listed on the mmap(2) man page, can also fail with one of the following error codes:h]hRefer to mmap(2) man page for additional details/restrictions. In addition to the error conditions listed on the mmap(2) man page, can also fail with one of the following error codes:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubj)}(hX====== ============================================= EINVAL fd is not associated with an open window (i.e mmap() does not follow a successful call to the VAS_TX_WIN_OPEN ioctl). EINVAL offset field is not 0ULL. ====== ============================================= h]j)}(hhh]j)}(hhh](j)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhj)ubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK-uh1jhj)ubj)}(hhh](j)}(hhh](j)}(hhh]h)}(hEINVALh]hEINVAL}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjFubah}(h]h ]h"]h$]h&]uh1jhjCubj)}(hhh]h)}(hufd is not associated with an open window (i.e mmap() does not follow a successful call to the VAS_TX_WIN_OPEN ioctl).h]hufd is not associated with an open window (i.e mmap() does not follow a successful call to the VAS_TX_WIN_OPEN ioctl).}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj]ubah}(h]h ]h"]h$]h&]uh1jhjCubeh}(h]h ]h"]h$]h&]uh1jhj@ubj)}(hhh](j)}(hhh]h)}(hEINVALh]hEINVAL}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj}ubah}(h]h ]h"]h$]h&]uh1jhjzubj)}(hhh]h)}(hoffset field is not 0ULL.h]hoffset field is not 0ULL.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjzubeh}(h]h ]h"]h$]h&]uh1jhj@ubeh}(h]h ]h"]h$]h&]uh1jhj)ubeh}(h]h ]h"]h$]h&]colsKuh1jhj&ubah}(h]h ]h"]h$]h&]uh1jhj"ubah}(h]h ]h"]h$]h&]uh1jhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhhhKhjhhubeh}(h]mmap-nx-gzip-deviceah ]h"]mmap() nx-gzip deviceah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h"Discovery of available VAS enginesh]h"Discovery of available VAS engines}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hX Each available VAS instance in the system will have a device tree node like /proc/device-tree/vas@* or /proc/device-tree/xscom@*/vas@*. Determine the chip or VAS instance and use the corresponding ibm,vas-id property value in this node to select specific VAS instance.h]hX Each available VAS instance in the system will have a device tree node like /proc/device-tree/vas@* or /proc/device-tree/xscom@*/vas@*. Determine the chip or VAS instance and use the corresponding ibm,vas-id property value in this node to select specific VAS instance.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]"discovery-of-available-vas-enginesah ]h"]"discovery of available vas enginesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hCopy/Paste operationsh]hCopy/Paste operations}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hApplications should use the copy and paste instructions to send CRB to NX. Refer section 4.4 in PowerISA for Copy/Paste instructions: https://openpowerfoundation.org/?resource_lib=power-isa-version-3-0h](hApplications should use the copy and paste instructions to send CRB to NX. Refer section 4.4 in PowerISA for Copy/Paste instructions: }(hjhhhNhNubjb)}(hChttps://openpowerfoundation.org/?resource_lib=power-isa-version-3-0h]hChttps://openpowerfoundation.org/?resource_lib=power-isa-version-3-0}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jahjubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]copy-paste-operationsah ]h"]copy/paste operationsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hCRB Specification and use NXh]hCRB Specification and use NX}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj5hhhhhKubh)}(hApplications should format requests to the co-processor using the co-processor Request Block (CRBs). Refer NX-GZIP user's manual for the format of CRB and use NX from userspace such as sending requests and checking request status.h]hApplications should format requests to the co-processor using the co-processor Request Block (CRBs). Refer NX-GZIP user’s manual for the format of CRB and use NX from userspace such as sending requests and checking request status.}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj5hhubeh}(h]crb-specification-and-use-nxah ]h"]crb specification and use nxah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hNX Fault handlingh]hNX Fault handling}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj\hhhhhKubh)}(hApplications send requests to NX and wait for the status by polling on co-processor Status Block (CSB) flags. NX updates status in CSB after each request is processed. Refer NX-GZIP user's manual for the format of CSB and status flags.h]hApplications send requests to NX and wait for the status by polling on co-processor Status Block (CSB) flags. NX updates status in CSB after each request is processed. Refer NX-GZIP user’s manual for the format of CSB and status flags.}(hjmhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\hhubh)}(hXSIn case if NX encounters translation error (called NX page fault) on CSB address or any request buffer, raises an interrupt on the CPU to handle the fault. Page fault can happen if an application passes invalid addresses or request buffers are not in memory. The operating system handles the fault by updating CSB with the following data::h]hXRIn case if NX encounters translation error (called NX page fault) on CSB address or any request buffer, raises an interrupt on the CPU to handle the fault. Page fault can happen if an application passes invalid addresses or request buffers are not in memory. The operating system handles the fault by updating CSB with the following data:}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\hhubj)}(hkcsb.flags = CSB_V; csb.cc = CSB_CC_FAULT_ADDRESS; csb.ce = CSB_CE_TERMINATION; csb.address = fault_address;h]hkcsb.flags = CSB_V; csb.cc = CSB_CC_FAULT_ADDRESS; csb.ce = CSB_CE_TERMINATION; csb.address = fault_address;}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhj\hhubh)}(hWhen an application receives translation error, it can touch or access the page that has a fault address so that this page will be in memory. Then the application can resend this request to NX.h]hWhen an application receives translation error, it can touch or access the page that has a fault address so that this page will be in memory. Then the application can resend this request to NX.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\hhubh)}(hIf the OS can not update CSB due to invalid CSB address, sends SEGV signal to the process who opened the send window on which the original request was issued. This signal returns with the following siginfo struct::h]hIf the OS can not update CSB due to invalid CSB address, sends SEGV signal to the process who opened the send window on which the original request was issued. This signal returns with the following siginfo struct:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\hhubj)}(htsiginfo.si_signo = SIGSEGV; siginfo.si_errno = EFAULT; siginfo.si_code = SEGV_MAPERR; siginfo.si_addr = CSB address;h]htsiginfo.si_signo = SIGSEGV; siginfo.si_errno = EFAULT; siginfo.si_code = SEGV_MAPERR; siginfo.si_addr = CSB address;}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhj\hhubh)}(hXIn the case of multi-thread applications, NX send windows can be shared across all threads. For example, a child thread can open a send window, but other threads can send requests to NX using this window. These requests will be successful even in the case of OS handling faults as long as CSB address is valid. If the NX request contains an invalid CSB address, the signal will be sent to the child thread that opened the window. But if the thread is exited without closing the window and the request is issued using this window. the signal will be issued to the thread group leader (tgid). It is up to the application whether to ignore or handle these signals.h]hXIn the case of multi-thread applications, NX send windows can be shared across all threads. For example, a child thread can open a send window, but other threads can send requests to NX using this window. These requests will be successful even in the case of OS handling faults as long as CSB address is valid. If the NX request contains an invalid CSB address, the signal will be sent to the child thread that opened the window. But if the thread is exited without closing the window and the request is issued using this window. the signal will be issued to the thread group leader (tgid). It is up to the application whether to ignore or handle these signals.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj\hhubh)}(h`NX-GZIP User's Manual: https://github.com/libnxz/power-gzip/blob/master/doc/power_nx_gzip_um.pdfh](hNX-GZIP User’s Manual: }(hjhhhNhNubjb)}(hIhttps://github.com/libnxz/power-gzip/blob/master/doc/power_nx_gzip_um.pdfh]hIhttps://github.com/libnxz/power-gzip/blob/master/doc/power_nx_gzip_um.pdf}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurijuh1jahjubeh}(h]h ]h"]h$]h&]uh1hhhhMhj\hhubeh}(h]nx-fault-handlingah ]h"]nx fault handlingah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hSimple exampleh]hSimple example}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMubj)}(hX:: int use_nx_gzip() { int rc, fd; void *addr; struct vas_setup_attr txattr; fd = open("/dev/crypto/nx-gzip", O_RDWR); if (fd < 0) { fprintf(stderr, "open nx-gzip failed\n"); return -1; } memset(&txattr, 0, sizeof(txattr)); txattr.version = 1; txattr.vas_id = -1 rc = ioctl(fd, VAS_TX_WIN_OPEN, (unsigned long)&txattr); if (rc < 0) { fprintf(stderr, "ioctl() n %d, error %d\n", rc, errno); return rc; } addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0ULL); if (addr == MAP_FAILED) { fprintf(stderr, "mmap() failed, errno %d\n", errno); return -errno; } do { //Format CRB request with compression or //uncompression // Refer tests for vas_copy/vas_paste vas_copy((&crb, 0, 1); vas_paste(addr, 0, 1); // Poll on csb.flags with timeout // csb address is listed in CRB } while (true) close(fd) or window can be closed upon process exit } Refer https://github.com/libnxz/power-gzip for tests or more use cases.h](j)}(hXint use_nx_gzip() { int rc, fd; void *addr; struct vas_setup_attr txattr; fd = open("/dev/crypto/nx-gzip", O_RDWR); if (fd < 0) { fprintf(stderr, "open nx-gzip failed\n"); return -1; } memset(&txattr, 0, sizeof(txattr)); txattr.version = 1; txattr.vas_id = -1 rc = ioctl(fd, VAS_TX_WIN_OPEN, (unsigned long)&txattr); if (rc < 0) { fprintf(stderr, "ioctl() n %d, error %d\n", rc, errno); return rc; } addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0ULL); if (addr == MAP_FAILED) { fprintf(stderr, "mmap() failed, errno %d\n", errno); return -errno; } do { //Format CRB request with compression or //uncompression // Refer tests for vas_copy/vas_paste vas_copy((&crb, 0, 1); vas_paste(addr, 0, 1); // Poll on csb.flags with timeout // csb address is listed in CRB } while (true) close(fd) or window can be closed upon process exit }h]hXint use_nx_gzip() { int rc, fd; void *addr; struct vas_setup_attr txattr; fd = open("/dev/crypto/nx-gzip", O_RDWR); if (fd < 0) { fprintf(stderr, "open nx-gzip failed\n"); return -1; } memset(&txattr, 0, sizeof(txattr)); txattr.version = 1; txattr.vas_id = -1 rc = ioctl(fd, VAS_TX_WIN_OPEN, (unsigned long)&txattr); if (rc < 0) { fprintf(stderr, "ioctl() n %d, error %d\n", rc, errno); return rc; } addr = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0ULL); if (addr == MAP_FAILED) { fprintf(stderr, "mmap() failed, errno %d\n", errno); return -errno; } do { //Format CRB request with compression or //uncompression // Refer tests for vas_copy/vas_paste vas_copy((&crb, 0, 1); vas_paste(addr, 0, 1); // Poll on csb.flags with timeout // csb address is listed in CRB } while (true) close(fd) or window can be closed upon process exit }}hj sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhjubh)}(hGRefer https://github.com/libnxz/power-gzip for tests or more use cases.h](hRefer }(hjhhhNhNubjb)}(h$https://github.com/libnxz/power-gziph]h$https://github.com/libnxz/power-gzip}(hjhhhNhNubah}(h]h ]h"]h$]h&]refurij!uh1jahjubh for tests or more use cases.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM0hjubeh}(h]h ]h"]h$]h&]uh1jhhhMhjhhubeh}(h]simple-exampleah ]h"]simple exampleah$]h&]uh1hhhhhhhhMubeh}(h](1virtual-accelerator-switchboard-vas-userspace-apiheh ]h"](3virtual accelerator switchboard (vas) userspace apivas-apieh$]h&]uh1hhhhhhhhKexpect_referenced_by_name}jLhsexpect_referenced_by_id}hhsubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjuerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}h]hasnameids}(jLhjKjHj'j$jxjujjjjjjjjjjj2j/jYjVjjjCj@u nametypes}(jLjKj'jxjjjjjj2jYjjCuh}(hhjHhj$hjuj*jj{jjjjjjjjj/jjVj5jj\j@ju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages]hsystem_message)}(hhh]h)}(hhh]h-Hyperlink target "vas-api" is not referenced.}hjsbah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]levelKtypeINFOsourcehlineKuh1juba transformerN include_log] decorationNhhub.