| 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
| 2 | /* Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES. |
| 3 | */ |
| 4 | #ifndef _UAPI_FWCTL_H |
| 5 | #define _UAPI_FWCTL_H |
| 6 | |
| 7 | #include <linux/types.h> |
| 8 | #include <linux/ioctl.h> |
| 9 | |
| 10 | #define FWCTL_TYPE 0x9A |
| 11 | |
| 12 | /** |
| 13 | * DOC: General ioctl format |
| 14 | * |
| 15 | * The ioctl interface follows a general format to allow for extensibility. Each |
| 16 | * ioctl is passed a structure pointer as the argument providing the size of |
| 17 | * the structure in the first u32. The kernel checks that any structure space |
| 18 | * beyond what it understands is 0. This allows userspace to use the backward |
| 19 | * compatible portion while consistently using the newer, larger, structures. |
| 20 | * |
| 21 | * ioctls use a standard meaning for common errnos: |
| 22 | * |
| 23 | * - ENOTTY: The IOCTL number itself is not supported at all |
| 24 | * - E2BIG: The IOCTL number is supported, but the provided structure has |
| 25 | * non-zero in a part the kernel does not understand. |
| 26 | * - EOPNOTSUPP: The IOCTL number is supported, and the structure is |
| 27 | * understood, however a known field has a value the kernel does not |
| 28 | * understand or support. |
| 29 | * - EINVAL: Everything about the IOCTL was understood, but a field is not |
| 30 | * correct. |
| 31 | * - ENOMEM: Out of memory. |
| 32 | * - ENODEV: The underlying device has been hot-unplugged and the FD is |
| 33 | * orphaned. |
| 34 | * |
| 35 | * As well as additional errnos, within specific ioctls. |
| 36 | */ |
| 37 | enum { |
| 38 | FWCTL_CMD_BASE = 0, |
| 39 | FWCTL_CMD_INFO = 0, |
| 40 | FWCTL_CMD_RPC = 1, |
| 41 | }; |
| 42 | |
| 43 | enum fwctl_device_type { |
| 44 | FWCTL_DEVICE_TYPE_ERROR = 0, |
| 45 | FWCTL_DEVICE_TYPE_MLX5 = 1, |
| 46 | FWCTL_DEVICE_TYPE_CXL = 2, |
| 47 | FWCTL_DEVICE_TYPE_PDS = 4, |
| 48 | }; |
| 49 | |
| 50 | /** |
| 51 | * struct fwctl_info - ioctl(FWCTL_INFO) |
| 52 | * @size: sizeof(struct fwctl_info) |
| 53 | * @flags: Must be 0 |
| 54 | * @out_device_type: Returns the type of the device from enum fwctl_device_type |
| 55 | * @device_data_len: On input the length of the out_device_data memory. On |
| 56 | * output the size of the kernel's device_data which may be larger or |
| 57 | * smaller than the input. Maybe 0 on input. |
| 58 | * @out_device_data: Pointer to a memory of device_data_len bytes. Kernel will |
| 59 | * fill the entire memory, zeroing as required. |
| 60 | * |
| 61 | * Returns basic information about this fwctl instance, particularly what driver |
| 62 | * is being used to define the device_data format. |
| 63 | */ |
| 64 | struct fwctl_info { |
| 65 | __u32 size; |
| 66 | __u32 flags; |
| 67 | __u32 out_device_type; |
| 68 | __u32 device_data_len; |
| 69 | __aligned_u64 out_device_data; |
| 70 | }; |
| 71 | #define FWCTL_INFO _IO(FWCTL_TYPE, FWCTL_CMD_INFO) |
| 72 | |
| 73 | /** |
| 74 | * enum fwctl_rpc_scope - Scope of access for the RPC |
| 75 | * |
| 76 | * Refer to fwctl.rst for a more detailed discussion of these scopes. |
| 77 | */ |
| 78 | enum fwctl_rpc_scope { |
| 79 | /** |
| 80 | * @FWCTL_RPC_CONFIGURATION: Device configuration access scope |
| 81 | * |
| 82 | * Read/write access to device configuration. When configuration |
| 83 | * is written to the device it remains in a fully supported state. |
| 84 | */ |
| 85 | FWCTL_RPC_CONFIGURATION = 0, |
| 86 | /** |
| 87 | * @FWCTL_RPC_DEBUG_READ_ONLY: Read only access to debug information |
| 88 | * |
| 89 | * Readable debug information. Debug information is compatible with |
| 90 | * kernel lockdown, and does not disclose any sensitive information. For |
| 91 | * instance exposing any encryption secrets from this information is |
| 92 | * forbidden. |
| 93 | */ |
| 94 | FWCTL_RPC_DEBUG_READ_ONLY = 1, |
| 95 | /** |
| 96 | * @FWCTL_RPC_DEBUG_WRITE: Writable access to lockdown compatible debug information |
| 97 | * |
| 98 | * Allows write access to data in the device which may leave a fully |
| 99 | * supported state. This is intended to permit intensive and possibly |
| 100 | * invasive debugging. This scope will taint the kernel. |
| 101 | */ |
| 102 | FWCTL_RPC_DEBUG_WRITE = 2, |
| 103 | /** |
| 104 | * @FWCTL_RPC_DEBUG_WRITE_FULL: Write access to all debug information |
| 105 | * |
| 106 | * Allows read/write access to everything. Requires CAP_SYS_RAW_IO, so |
| 107 | * it is not required to follow lockdown principals. If in doubt |
| 108 | * debugging should be placed in this scope. This scope will taint the |
| 109 | * kernel. |
| 110 | */ |
| 111 | FWCTL_RPC_DEBUG_WRITE_FULL = 3, |
| 112 | }; |
| 113 | |
| 114 | /** |
| 115 | * struct fwctl_rpc - ioctl(FWCTL_RPC) |
| 116 | * @size: sizeof(struct fwctl_rpc) |
| 117 | * @scope: One of enum fwctl_rpc_scope, required scope for the RPC |
| 118 | * @in_len: Length of the in memory |
| 119 | * @out_len: Length of the out memory |
| 120 | * @in: Request message in device specific format |
| 121 | * @out: Response message in device specific format |
| 122 | * |
| 123 | * Deliver a Remote Procedure Call to the device FW and return the response. The |
| 124 | * call's parameters and return are marshaled into linear buffers of memory. Any |
| 125 | * errno indicates that delivery of the RPC to the device failed. Return status |
| 126 | * originating in the device during a successful delivery must be encoded into |
| 127 | * out. |
| 128 | * |
| 129 | * The format of the buffers matches the out_device_type from FWCTL_INFO. |
| 130 | */ |
| 131 | struct fwctl_rpc { |
| 132 | __u32 size; |
| 133 | __u32 scope; |
| 134 | __u32 in_len; |
| 135 | __u32 out_len; |
| 136 | __aligned_u64 in; |
| 137 | __aligned_u64 out; |
| 138 | }; |
| 139 | #define FWCTL_RPC _IO(FWCTL_TYPE, FWCTL_CMD_RPC) |
| 140 | |
| 141 | #endif |
| 142 | |