diff --git a/include/linux/nvscierror.h b/include/linux/nvscierror.h new file mode 100644 index 00000000..10340a2c --- /dev/null +++ b/include/linux/nvscierror.h @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2019-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +/* + * @file + * + * NVIDIA Software Communications Interface (SCI): Error Handling + * + * @b Description: This file declares error codes for NvSci APIs. + */ + +#ifndef INCLUDED_NVSCI_ERROR_H +#define INCLUDED_NVSCI_ERROR_H + +/** + * @defgroup NvSciError SCI Error Handling + * + * Contains error code enumeration and helper macros. + * + * @ingroup nvsci_top + * @{ + */ + +/** + * @brief Return/error codes for all NvSci functions. + * + * This enumeration contains unique return/error codes to identify the + * source of a failure. Some errors have direct correspondence to standard + * errno.h codes, indicated [IN BRACKETS], and may result from failures in + * lower level system calls. Others indicate failures specific to misuse + * of NvSci library function. + */ +typedef enum NvSciErrorRec { + /* Range 0x00000000 - 0x00FFFFFF : Common errors + * This range is used for errors common to all NvSci libraries. + */ + + /** [EOK] No error */ + NvSciError_Success = 0x00000000, + + /** Unidentified error with no additional info */ + NvSciError_Unknown = 0x00000001, + + /* Generic errors */ + /** [ENOSYS] Feature is not implemented */ + NvSciError_NotImplemented = 0x00000010, + /** [ENOTSUP] Feature is not supported */ + NvSciError_NotSupported = 0x00000011, + /** [EACCES] Access to resource denied */ + NvSciError_AccessDenied = 0x00000020, + /** [EPERM] No permission to perform operation */ + NvSciError_NotPermitted = 0x00000021, + /** Resource is in wrong state to perform operation */ + NvSciError_InvalidState = 0x00000022, + /** Requested operation is not legal */ + NvSciError_InvalidOperation = 0x00000023, + /** Required resource is not initialized */ + NvSciError_NotInitialized = 0x00000024, + /** [ENOMEM] Not enough memory */ + NvSciError_InsufficientMemory = 0x00000030, + /** Not enough (non-memory) resources */ + NvSciError_InsufficientResource = 0x00000031, + /** Resource failed */ + NvSciError_ResourceError = 0x00000032, + + /* Function parameter errors */ + /** [EINVAL] Invalid parameter value */ + NvSciError_BadParameter = 0x00000100, + /** [EFAULT] Invalid address */ + NvSciError_BadAddress = 0x00000101, + /** [E2BIG] Parameter list too long */ + NvSciError_TooBig = 0x00000102, + /** [EOVERFLOW] Value too large for data type */ + NvSciError_Overflow = 0x00000103, + + /* Timing/temporary errors */ + /** [ETIMEDOUT] Operation timed out*/ + NvSciError_Timeout = 0x00000200, + /** [EAGAIN] Resource unavailable. Try again. */ + NvSciError_TryItAgain = 0x00000201, + /** [EBUSY] Resource is busy */ + NvSciError_Busy = 0x00000202, + /** [EINTR] An interrupt ocurred */ + NvSciError_InterruptedCall = 0x00000203, + + /* Device errors */ + /** [ENODEV] No such device */ + NvSciError_NoSuchDevice = 0x00001000, + /** [ENOSPC] No space left on device */ + NvSciError_NoSpace = 0x00001001, + /** [ENXIO] No such device or address */ + NvSciError_NoSuchDevAddr = 0x00001002, + /** [EIO] Input/output error */ + NvSciError_IO = 0x00001003, + /** [ENOTTY] Inappropriate I/O control operation */ + NvSciError_InvalidIoctlNum = 0x00001004, + + /* File system errors */ + /** [ENOENT] No such file or directory*/ + NvSciError_NoSuchEntry = 0x00001100, + /** [EBADF] Bad file descriptor */ + NvSciError_BadFileDesc = 0x00001101, + /** [EBADFSYS] Corrupted file system detected */ + NvSciError_CorruptedFileSys = 0x00001102, + /** [EEXIST] File already exists */ + NvSciError_FileExists = 0x00001103, + /** [EISDIR] File is a directory */ + NvSciError_IsDirectory = 0x00001104, + /** [EROFS] Read-only file system */ + NvSciError_ReadOnlyFileSys = 0x00001105, + /** [ETXTBSY] Text file is busy */ + NvSciError_TextFileBusy = 0x00001106, + /** [ENAMETOOLONG] File name is too long */ + NvSciError_FileNameTooLong = 0x00001107, + /** [EFBIG] File is too large */ + NvSciError_FileTooBig = 0x00001108, + /** [ELOOP] Too many levels of symbolic links */ + NvSciError_TooManySymbolLinks = 0x00001109, + /** [EMFILE] Too many open files in process*/ + NvSciError_TooManyOpenFiles = 0x0000110A, + /** [ENFILE] Too many open files in system */ + NvSciError_FileTableOverflow = 0x0000110B, + /** End of file reached */ + NvSciError_EndOfFile = 0x0000110C, + + + /* Communication errors */ + /** [ECONNRESET] Connection was closed or lost */ + NvSciError_ConnectionReset = 0x00001200, + /** [EALREADY] Pending connection is already in progress */ + NvSciError_AlreadyInProgress = 0x00001201, + /** [ENODATA] No message data available */ + NvSciError_NoData = 0x00001202, + /** [ENOMSG] No message of the desired type available*/ + NvSciError_NoDesiredMessage = 0x00001203, + /** [EMSGSIZE] Message is too large */ + NvSciError_MessageSize = 0x00001204, + /** [ENOREMOTE] Remote node doesn't exist */ + NvSciError_NoRemote = 0x00001205, + + /* Process/thread errors */ + /** [ESRCH] No such process */ + NvSciError_NoSuchProcess = 0x00002000, + + /* Mutex errors */ + /** [ENOTRECOVERABLE] Mutex damaged by previous owner's death */ + NvSciError_MutexNotRecoverable = 0x00002100, + /** [EOWNERDEAD] Previous owner died while holding mutex */ + NvSciError_LockOwnerDead = 0x00002101, + /** [EDEADLK] Taking ownership would cause deadlock */ + NvSciError_ResourceDeadlock = 0x00002102, + + /* NvSci attribute list errors */ + /** Could not reconcile attributes */ + NvSciError_ReconciliationFailed = 0x00010100, + /** Could not validate attributes */ + NvSciError_AttrListValidationFailed = 0x00010101, + + /** End of range for common error codes */ + NvSciError_CommonEnd = 0x00FFFFFF, + + + /* Range 0x01000000 - 0x01FFFFFF : NvSciBuf errors */ + /** Unidentified NvSciBuf error with no additional info */ + NvSciError_NvSciBufUnknown = 0x01000000, + /** End of range for NvSciBuf errors */ + NvSciError_NvSciBufEnd = 0x01FFFFFF, + + + /* Range 0x02000000 - 0x02FFFFFF : NvSciSync errors */ + /** Unidentified NvSciSync error with no additional info */ + NvSciError_NvSciSyncUnknown = 0x02000000, + /** Unsupported configuration */ + NvSciError_UnsupportedConfig = 0x02000001, + /** Provided fence is cleared */ + NvSciError_ClearedFence = 0x02000002, + /* End of range for NvScSync errors */ + NvSciError_NvSciSyncEnd = 0x02FFFFFF, + + + /* Range 0x03000000 - 0x03FFFFFF : NvSciStream errors */ + /** Unidentified NvSciStream error with no additional info */ + NvSciError_NvSciStreamUnknown = 0x03000000, + /** Internal stream resource failure occurred */ + NvSciError_StreamInternalError = 0x30000001, + /** Operation requires stream be fully connected */ + NvSciError_StreamNotConnected = 0x30000200, + /** No stream packet available */ + NvSciError_NoStreamPacket = 0x30001000, + /** End of range for NvSciStream errors */ + NvSciError_NvSciStreamEnd = 0x03FFFFFF, + + + /* Range 0x04000000 - 0x04FFFFFF : NvSciIpc errors */ + /** Unidentified NvSciIpc error with no additional info */ + NvSciError_NvSciIpcUnknown = 0x04000000, + /** End of range for NvSciIpc errors */ + NvSciError_NvSciIpcEnd = 0x04FFFFFF, + + + /* Range 0x05000000 - 0x05FFFFFF : NvSciEvent errors */ + /** Unidentified NvSciEvent error with no additional info */ + NvSciError_NvSciEventUnknown = 0x05000000, + /** End of range for NvSciEvent errors */ + NvSciError_NvSciEventEnd = 0x05FFFFFF, + +} NvSciError; + +/* + * @} + */ + +#endif /* INCLUDED_NVSCI_ERROR_H */ diff --git a/include/linux/nvsciipc_interface.h b/include/linux/nvsciipc_interface.h new file mode 100644 index 00000000..2a968d0a --- /dev/null +++ b/include/linux/nvsciipc_interface.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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. + */ + +#ifndef __NVSCIIPC_INTERFACE_H__ +#define __NVSCIIPC_INTERFACE_H__ + +/** Invalid VUID definition */ +#define NVSCIIPC_ENDPOINT_VUID_INVALID 0U +/** Invalid authentication token definition */ +#define NVSCIIPC_ENDPOINT_AUTHTOKEN_INVALID 0U +/** current self SOC ID */ +#define NVSCIIPC_SELF_SOCID 0xFFFFFFFFU +/** current self VM ID */ +#define NVSCIIPC_SELF_VMID 0xFFFFFFFFU + +/** + * @brief Handle to the IPC endpoint. + */ +typedef uint64_t NvSciIpcEndpoint; + + +/** + * @brief VUID(VM unique ID) of the IPC endpoint. + */ +typedef uint64_t NvSciIpcEndpointVuid; + +/** + * @brief authentication token of the IPC endpoint. + */ +typedef uint64_t NvSciIpcEndpointAuthToken; + +/** + * @brief Defines topology ID of the IPC endpoint. + */ +typedef struct { + /*! Holds SOC ID */ + uint32_t SocId; + /*! Holds VMID */ + uint32_t VmId; +} NvSciIpcTopoId; + +/**********************************************************************/ +/*********************** Function Definitions *************************/ +/**********************************************************************/ +NvSciError NvSciIpcEndpointGetAuthToken(NvSciIpcEndpoint handle, + NvSciIpcEndpointAuthToken *authToken); + +NvSciError NvSciIpcEndpointValidateAuthTokenLinuxCurrent( + NvSciIpcEndpointAuthToken authToken, + NvSciIpcEndpointVuid *localUserVuid); + +NvSciError NvSciIpcEndpointMapVuid(NvSciIpcEndpointVuid localUserVuid, + NvSciIpcTopoId *peerTopoId, NvSciIpcEndpointVuid *peerUserVuid); + +NvSciError NvSciIpcEndpointGetVuid(NvSciIpcEndpoint handle, + NvSciIpcEndpointVuid *vuid); + +#endif /* __NVSCIIPC_INTERFACE_H__ */ diff --git a/include/uapi/linux/nvsciipc_ioctl.h b/include/uapi/linux/nvsciipc_ioctl.h new file mode 100644 index 00000000..4e57aa02 --- /dev/null +++ b/include/uapi/linux/nvsciipc_ioctl.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved. + * + * This header is BSD licensed so anyone can use the definitions to implement + * compatible drivers/servers. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of NVIDIA 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 NVIDIA CORPORATION 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. + */ + +#ifndef __NVSCIIPC_IOCTL_H__ +#define __NVSCIIPC_IOCTL_H__ + +#include + +#define NVSCIIPC_MAX_EP_NAME 64U +#define NVSCIIPC_MAX_RDMA_NAME 64U +#define NVSCIIPC_MAX_IP_NAME 16U + +struct nvsciipc_config_entry { + /* endpoint name */ + char ep_name[NVSCIIPC_MAX_EP_NAME]; + /* node name for shm/sem */ + char dev_name[NVSCIIPC_MAX_EP_NAME]; + uint32_t backend; /* backend type */ + uint32_t nframes; /* frame count */ + uint32_t frame_size; /* frame size */ + /* ep id for inter-Proc/Thread + * queue id for inter-VM + * dev id for inter-Chip + */ + uint32_t id; + uint64_t vuid; /* VM-wide unique id */ + char rdma_dev_name[NVSCIIPC_MAX_RDMA_NAME]; + char remote_ip[NVSCIIPC_MAX_IP_NAME]; + uint32_t remote_port; + uint32_t local_port; + uint32_t peer_vmid; +}; + +struct nvsciipc_db { + int num_eps; + struct nvsciipc_config_entry **entry; +}; + +struct nvsciipc_get_vuid { + char ep_name[NVSCIIPC_MAX_EP_NAME]; + uint64_t vuid; +}; + +struct nvsciipc_get_db_by_name { + char ep_name[NVSCIIPC_MAX_EP_NAME]; + struct nvsciipc_config_entry entry; + uint32_t idx; +}; + +struct nvsciipc_get_db_by_vuid { + uint64_t vuid; + struct nvsciipc_config_entry entry; + uint32_t idx; +}; + +/* for userspace level test, debugging purpose only */ +struct nvsciipc_validate_auth_token { + uint32_t auth_token; + uint64_t local_vuid; +}; + +/* NvSciIpcTopoId type */ +struct nvsciipc_topoid { + uint32_t socid; + uint32_t vmid; +}; + +/* for userspace level test, debugging purpose only */ +struct nvsciipc_map_vuid { + uint64_t vuid; + struct nvsciipc_topoid peer_topoid; + uint64_t peer_vuid; +}; + +/* IOCTL magic number - seen available in ioctl-number.txt*/ +#define NVSCIIPC_IOCTL_MAGIC 0xC3 + +#define NVSCIIPC_IOCTL_SET_DB \ + _IOW(NVSCIIPC_IOCTL_MAGIC, 1, struct nvsciipc_db) + +#define NVSCIIPC_IOCTL_GET_VUID \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 2, struct nvsciipc_get_vuid) + +#define NVSCIIPC_IOCTL_GET_DB_BY_NAME \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 3, struct nvsciipc_get_db_by_name) + +#define NVSCIIPC_IOCTL_GET_DB_BY_VUID \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 4, struct nvsciipc_get_db_by_vuid) + +#define NVSCIIPC_IOCTL_GET_DB_SIZE \ + _IOR(NVSCIIPC_IOCTL_MAGIC, 5, uint32_t) + +/* debugging purpose only */ +#define NVSCIIPC_IOCTL_VALIDATE_AUTH_TOKEN \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 6, struct nvsciipc_validate_auth_token) + +/* debugging purpose only */ +#define NVSCIIPC_IOCTL_MAP_VUID \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 7, struct nvsciipc_map_vuid) + +#define NVSCIIPC_IOCTL_GET_VMID \ + _IOWR(NVSCIIPC_IOCTL_MAGIC, 8, uint32_t) + +#define NVSCIIPC_IOCTL_NUMBER_MAX 8 + +#endif /* __NVSCIIPC_IOCTL_H__ */