1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * CXL IOCTLs for Memory Devices 4 */ 5 6 #ifndef _UAPI_CXL_MEM_H_ 7 #define _UAPI_CXL_MEM_H_ 8 9 #include <linux/types.h> 10 11 /** 12 * DOC: UAPI 13 * 14 * Not all of the commands that the driver supports are available for use by 15 * userspace at all times. Userspace can check the result of the QUERY command 16 * to determine the live set of commands. Alternatively, it can issue the 17 * command and check for failure. 18 */ 19 20 #define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands) 21 #define CXL_MEM_SEND_COMMAND _IOWR(0xCE, 2, struct cxl_send_command) 22 23 /* 24 * NOTE: New defines must be added to the end of the list to preserve 25 * compatibility because this enum is exported to user space. 26 */ 27 #define CXL_CMDS \ 28 ___C(INVALID, "Invalid Command"), \ 29 ___C(IDENTIFY, "Identify Command"), \ 30 ___C(RAW, "Raw device command"), \ 31 ___C(GET_SUPPORTED_LOGS, "Get Supported Logs"), \ 32 ___C(GET_FW_INFO, "Get FW Info"), \ 33 ___C(GET_PARTITION_INFO, "Get Partition Information"), \ 34 ___C(GET_LSA, "Get Label Storage Area"), \ 35 ___C(GET_HEALTH_INFO, "Get Health Info"), \ 36 ___C(GET_LOG, "Get Log"), \ 37 ___C(SET_PARTITION_INFO, "Set Partition Information"), \ 38 ___C(SET_LSA, "Set Label Storage Area"), \ 39 ___C(GET_ALERT_CONFIG, "Get Alert Configuration"), \ 40 ___C(SET_ALERT_CONFIG, "Set Alert Configuration"), \ 41 ___C(GET_SHUTDOWN_STATE, "Get Shutdown State"), \ 42 ___C(SET_SHUTDOWN_STATE, "Set Shutdown State"), \ 43 ___DEPRECATED(GET_POISON, "Get Poison List"), \ 44 ___DEPRECATED(INJECT_POISON, "Inject Poison"), \ 45 ___DEPRECATED(CLEAR_POISON, "Clear Poison"), \ 46 ___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"), \ 47 ___DEPRECATED(SCAN_MEDIA, "Scan Media"), \ 48 ___DEPRECATED(GET_SCAN_MEDIA, "Get Scan Media Results"), \ 49 ___C(MAX, "invalid / last command") 50 51 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a 52 #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a 53 enum { CXL_CMDS }; 54 55 #undef ___C 56 #undef ___DEPRECATED 57 #define ___C(a, b) { b } 58 #define ___DEPRECATED(a, b) { "Deprecated " b } 59 static const struct { 60 const char *name; 61 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS }; 62 63 /* 64 * Here's how this actually breaks out: 65 * cxl_command_names[] = { 66 * [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" }, 67 * [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" }, 68 * ... 69 * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" }, 70 * }; 71 */ 72 73 #undef ___C 74 #undef ___DEPRECATED 75 #define ___C(a, b) (0) 76 #define ___DEPRECATED(a, b) (1) 77 78 static const __u8 cxl_deprecated_commands[] 79 __attribute__((__unused__)) = { CXL_CMDS }; 80 81 /* 82 * Here's how this actually breaks out: 83 * cxl_deprecated_commands[] = { 84 * [CXL_MEM_COMMAND_ID_INVALID] = 0, 85 * [CXL_MEM_COMMAND_ID_IDENTIFY] = 0, 86 * ... 87 * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1, 88 * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1, 89 * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1, 90 * ... 91 * }; 92 */ 93 94 #undef ___C 95 #undef ___DEPRECATED 96 97 /** 98 * struct cxl_command_info - Command information returned from a query. 99 * @id: ID number for the command. 100 * @flags: Flags that specify command behavior. 101 * 102 * CXL_MEM_COMMAND_FLAG_USER_ENABLED 103 * 104 * The given command id is supported by the driver and is supported by 105 * a related opcode on the device. 106 * 107 * CXL_MEM_COMMAND_FLAG_EXCLUSIVE 108 * 109 * Requests with the given command id will terminate with EBUSY as the 110 * kernel actively owns management of the given resource. For example, 111 * the label-storage-area can not be written while the kernel is 112 * actively managing that space. 113 * 114 * @size_in: Expected input size, or ~0 if variable length. 115 * @size_out: Expected output size, or ~0 if variable length. 116 * 117 * Represents a single command that is supported by both the driver and the 118 * hardware. This is returned as part of an array from the query ioctl. The 119 * following would be a command that takes a variable length input and returns 0 120 * bytes of output. 121 * 122 * - @id = 10 123 * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED 124 * - @size_in = ~0 125 * - @size_out = 0 126 * 127 * See struct cxl_mem_query_commands. 128 */ 129 struct cxl_command_info { 130 __u32 id; 131 132 __u32 flags; 133 #define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0) 134 #define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0) 135 #define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1) 136 137 __u32 size_in; 138 __u32 size_out; 139 }; 140 141 /** 142 * struct cxl_mem_query_commands - Query supported commands. 143 * @n_commands: In/out parameter. When @n_commands is > 0, the driver will 144 * return min(num_support_commands, n_commands). When @n_commands 145 * is 0, driver will return the number of total supported commands. 146 * @rsvd: Reserved for future use. 147 * @commands: Output array of supported commands. This array must be allocated 148 * by userspace to be at least min(num_support_commands, @n_commands) 149 * 150 * Allow userspace to query the available commands supported by both the driver, 151 * and the hardware. Commands that aren't supported by either the driver, or the 152 * hardware are not returned in the query. 153 * 154 * Examples: 155 * 156 * - { .n_commands = 0 } // Get number of supported commands 157 * - { .n_commands = 15, .commands = buf } // Return first 15 (or less) 158 * supported commands 159 * 160 * See struct cxl_command_info. 161 */ 162 struct cxl_mem_query_commands { 163 /* 164 * Input: Number of commands to return (space allocated by user) 165 * Output: Number of commands supported by the driver/hardware 166 * 167 * If n_commands is 0, kernel will only return number of commands and 168 * not try to populate commands[], thus allowing userspace to know how 169 * much space to allocate 170 */ 171 __u32 n_commands; 172 __u32 rsvd; 173 174 struct cxl_command_info __user commands[]; /* out: supported commands */ 175 }; 176 177 /** 178 * struct cxl_send_command - Send a command to a memory device. 179 * @id: The command to send to the memory device. This must be one of the 180 * commands returned by the query command. 181 * @flags: Flags for the command (input). 182 * @raw: Special fields for raw commands 183 * @raw.opcode: Opcode passed to hardware when using the RAW command. 184 * @raw.rsvd: Must be zero. 185 * @rsvd: Must be zero. 186 * @retval: Return value from the memory device (output). 187 * @in: Parameters associated with input payload. 188 * @in.size: Size of the payload to provide to the device (input). 189 * @in.rsvd: Must be zero. 190 * @in.payload: Pointer to memory for payload input, payload is little endian. 191 * @out: Parameters associated with output payload. 192 * @out.size: Size of the payload received from the device (input/output). This 193 * field is filled in by userspace to let the driver know how much 194 * space was allocated for output. It is populated by the driver to 195 * let userspace know how large the output payload actually was. 196 * @out.rsvd: Must be zero. 197 * @out.payload: Pointer to memory for payload output, payload is little endian. 198 * 199 * Mechanism for userspace to send a command to the hardware for processing. The 200 * driver will do basic validation on the command sizes. In some cases even the 201 * payload may be introspected. Userspace is required to allocate large enough 202 * buffers for size_out which can be variable length in certain situations. 203 */ 204 struct cxl_send_command { 205 __u32 id; 206 __u32 flags; 207 union { 208 struct { 209 __u16 opcode; 210 __u16 rsvd; 211 } raw; 212 __u32 rsvd; 213 }; 214 __u32 retval; 215 216 struct { 217 __u32 size; 218 __u32 rsvd; 219 __u64 payload; 220 } in; 221 222 struct { 223 __u32 size; 224 __u32 rsvd; 225 __u64 payload; 226 } out; 227 }; 228 229 #endif 230