10e79a47fSJason Gunthorpe /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 20e79a47fSJason Gunthorpe /* Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. 30e79a47fSJason Gunthorpe */ 40e79a47fSJason Gunthorpe #ifndef _UAPI_FWCTL_H 50e79a47fSJason Gunthorpe #define _UAPI_FWCTL_H 60e79a47fSJason Gunthorpe 7fb39e909SJason Gunthorpe #include <linux/types.h> 8fb39e909SJason Gunthorpe #include <linux/ioctl.h> 9fb39e909SJason Gunthorpe 100e79a47fSJason Gunthorpe #define FWCTL_TYPE 0x9A 110e79a47fSJason Gunthorpe 120e79a47fSJason Gunthorpe /** 130e79a47fSJason Gunthorpe * DOC: General ioctl format 140e79a47fSJason Gunthorpe * 150e79a47fSJason Gunthorpe * The ioctl interface follows a general format to allow for extensibility. Each 160e79a47fSJason Gunthorpe * ioctl is passed a structure pointer as the argument providing the size of 170e79a47fSJason Gunthorpe * the structure in the first u32. The kernel checks that any structure space 180e79a47fSJason Gunthorpe * beyond what it understands is 0. This allows userspace to use the backward 190e79a47fSJason Gunthorpe * compatible portion while consistently using the newer, larger, structures. 200e79a47fSJason Gunthorpe * 210e79a47fSJason Gunthorpe * ioctls use a standard meaning for common errnos: 220e79a47fSJason Gunthorpe * 230e79a47fSJason Gunthorpe * - ENOTTY: The IOCTL number itself is not supported at all 240e79a47fSJason Gunthorpe * - E2BIG: The IOCTL number is supported, but the provided structure has 250e79a47fSJason Gunthorpe * non-zero in a part the kernel does not understand. 260e79a47fSJason Gunthorpe * - EOPNOTSUPP: The IOCTL number is supported, and the structure is 270e79a47fSJason Gunthorpe * understood, however a known field has a value the kernel does not 280e79a47fSJason Gunthorpe * understand or support. 290e79a47fSJason Gunthorpe * - EINVAL: Everything about the IOCTL was understood, but a field is not 300e79a47fSJason Gunthorpe * correct. 310e79a47fSJason Gunthorpe * - ENOMEM: Out of memory. 320e79a47fSJason Gunthorpe * - ENODEV: The underlying device has been hot-unplugged and the FD is 330e79a47fSJason Gunthorpe * orphaned. 340e79a47fSJason Gunthorpe * 350e79a47fSJason Gunthorpe * As well as additional errnos, within specific ioctls. 360e79a47fSJason Gunthorpe */ 370e79a47fSJason Gunthorpe enum { 380e79a47fSJason Gunthorpe FWCTL_CMD_BASE = 0, 39fb39e909SJason Gunthorpe FWCTL_CMD_INFO = 0, 40840cfb7cSJason Gunthorpe FWCTL_CMD_RPC = 1, 410e79a47fSJason Gunthorpe }; 420e79a47fSJason Gunthorpe 43fb39e909SJason Gunthorpe enum fwctl_device_type { 44fb39e909SJason Gunthorpe FWCTL_DEVICE_TYPE_ERROR = 0, 4552929c21SSaeed Mahameed FWCTL_DEVICE_TYPE_MLX5 = 1, 46858ce2f5SDave Jiang FWCTL_DEVICE_TYPE_CXL = 2, 47*4d09dd11SShannon Nelson FWCTL_DEVICE_TYPE_PDS = 4, 48fb39e909SJason Gunthorpe }; 49fb39e909SJason Gunthorpe 50fb39e909SJason Gunthorpe /** 51fb39e909SJason Gunthorpe * struct fwctl_info - ioctl(FWCTL_INFO) 52fb39e909SJason Gunthorpe * @size: sizeof(struct fwctl_info) 53fb39e909SJason Gunthorpe * @flags: Must be 0 54fb39e909SJason Gunthorpe * @out_device_type: Returns the type of the device from enum fwctl_device_type 55fb39e909SJason Gunthorpe * @device_data_len: On input the length of the out_device_data memory. On 56fb39e909SJason Gunthorpe * output the size of the kernel's device_data which may be larger or 57fb39e909SJason Gunthorpe * smaller than the input. Maybe 0 on input. 58fb39e909SJason Gunthorpe * @out_device_data: Pointer to a memory of device_data_len bytes. Kernel will 59fb39e909SJason Gunthorpe * fill the entire memory, zeroing as required. 60fb39e909SJason Gunthorpe * 61fb39e909SJason Gunthorpe * Returns basic information about this fwctl instance, particularly what driver 62fb39e909SJason Gunthorpe * is being used to define the device_data format. 63fb39e909SJason Gunthorpe */ 64fb39e909SJason Gunthorpe struct fwctl_info { 65fb39e909SJason Gunthorpe __u32 size; 66fb39e909SJason Gunthorpe __u32 flags; 67fb39e909SJason Gunthorpe __u32 out_device_type; 68fb39e909SJason Gunthorpe __u32 device_data_len; 69fb39e909SJason Gunthorpe __aligned_u64 out_device_data; 70fb39e909SJason Gunthorpe }; 71fb39e909SJason Gunthorpe #define FWCTL_INFO _IO(FWCTL_TYPE, FWCTL_CMD_INFO) 72fb39e909SJason Gunthorpe 73840cfb7cSJason Gunthorpe /** 74840cfb7cSJason Gunthorpe * enum fwctl_rpc_scope - Scope of access for the RPC 75840cfb7cSJason Gunthorpe * 76840cfb7cSJason Gunthorpe * Refer to fwctl.rst for a more detailed discussion of these scopes. 77840cfb7cSJason Gunthorpe */ 78840cfb7cSJason Gunthorpe enum fwctl_rpc_scope { 79840cfb7cSJason Gunthorpe /** 80840cfb7cSJason Gunthorpe * @FWCTL_RPC_CONFIGURATION: Device configuration access scope 81840cfb7cSJason Gunthorpe * 82840cfb7cSJason Gunthorpe * Read/write access to device configuration. When configuration 83840cfb7cSJason Gunthorpe * is written to the device it remains in a fully supported state. 84840cfb7cSJason Gunthorpe */ 85840cfb7cSJason Gunthorpe FWCTL_RPC_CONFIGURATION = 0, 86840cfb7cSJason Gunthorpe /** 87840cfb7cSJason Gunthorpe * @FWCTL_RPC_DEBUG_READ_ONLY: Read only access to debug information 88840cfb7cSJason Gunthorpe * 89840cfb7cSJason Gunthorpe * Readable debug information. Debug information is compatible with 90840cfb7cSJason Gunthorpe * kernel lockdown, and does not disclose any sensitive information. For 91840cfb7cSJason Gunthorpe * instance exposing any encryption secrets from this information is 92840cfb7cSJason Gunthorpe * forbidden. 93840cfb7cSJason Gunthorpe */ 94840cfb7cSJason Gunthorpe FWCTL_RPC_DEBUG_READ_ONLY = 1, 95840cfb7cSJason Gunthorpe /** 96840cfb7cSJason Gunthorpe * @FWCTL_RPC_DEBUG_WRITE: Writable access to lockdown compatible debug information 97840cfb7cSJason Gunthorpe * 98840cfb7cSJason Gunthorpe * Allows write access to data in the device which may leave a fully 99840cfb7cSJason Gunthorpe * supported state. This is intended to permit intensive and possibly 100840cfb7cSJason Gunthorpe * invasive debugging. This scope will taint the kernel. 101840cfb7cSJason Gunthorpe */ 102840cfb7cSJason Gunthorpe FWCTL_RPC_DEBUG_WRITE = 2, 103840cfb7cSJason Gunthorpe /** 104840cfb7cSJason Gunthorpe * @FWCTL_RPC_DEBUG_WRITE_FULL: Write access to all debug information 105840cfb7cSJason Gunthorpe * 106840cfb7cSJason Gunthorpe * Allows read/write access to everything. Requires CAP_SYS_RAW_IO, so 107840cfb7cSJason Gunthorpe * it is not required to follow lockdown principals. If in doubt 108840cfb7cSJason Gunthorpe * debugging should be placed in this scope. This scope will taint the 109840cfb7cSJason Gunthorpe * kernel. 110840cfb7cSJason Gunthorpe */ 111840cfb7cSJason Gunthorpe FWCTL_RPC_DEBUG_WRITE_FULL = 3, 112840cfb7cSJason Gunthorpe }; 113840cfb7cSJason Gunthorpe 114840cfb7cSJason Gunthorpe /** 115840cfb7cSJason Gunthorpe * struct fwctl_rpc - ioctl(FWCTL_RPC) 116840cfb7cSJason Gunthorpe * @size: sizeof(struct fwctl_rpc) 117840cfb7cSJason Gunthorpe * @scope: One of enum fwctl_rpc_scope, required scope for the RPC 118840cfb7cSJason Gunthorpe * @in_len: Length of the in memory 119840cfb7cSJason Gunthorpe * @out_len: Length of the out memory 120840cfb7cSJason Gunthorpe * @in: Request message in device specific format 121840cfb7cSJason Gunthorpe * @out: Response message in device specific format 122840cfb7cSJason Gunthorpe * 123840cfb7cSJason Gunthorpe * Deliver a Remote Procedure Call to the device FW and return the response. The 124840cfb7cSJason Gunthorpe * call's parameters and return are marshaled into linear buffers of memory. Any 125840cfb7cSJason Gunthorpe * errno indicates that delivery of the RPC to the device failed. Return status 126840cfb7cSJason Gunthorpe * originating in the device during a successful delivery must be encoded into 127840cfb7cSJason Gunthorpe * out. 128840cfb7cSJason Gunthorpe * 129840cfb7cSJason Gunthorpe * The format of the buffers matches the out_device_type from FWCTL_INFO. 130840cfb7cSJason Gunthorpe */ 131840cfb7cSJason Gunthorpe struct fwctl_rpc { 132840cfb7cSJason Gunthorpe __u32 size; 133840cfb7cSJason Gunthorpe __u32 scope; 134840cfb7cSJason Gunthorpe __u32 in_len; 135840cfb7cSJason Gunthorpe __u32 out_len; 136840cfb7cSJason Gunthorpe __aligned_u64 in; 137840cfb7cSJason Gunthorpe __aligned_u64 out; 138840cfb7cSJason Gunthorpe }; 139840cfb7cSJason Gunthorpe #define FWCTL_RPC _IO(FWCTL_TYPE, FWCTL_CMD_RPC) 140840cfb7cSJason Gunthorpe 1410e79a47fSJason Gunthorpe #endif 142