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(GET_TIMESTAMP, "Get Timestamp"), \ 50 ___C(GET_LOG_CAPS, "Get Log Capabilities"), \ 51 ___C(CLEAR_LOG, "Clear Log"), \ 52 ___C(GET_SUP_LOG_SUBLIST, "Get Supported Logs Sub-List"), \ 53 ___C(MAX, "invalid / last command") 54 55 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a 56 #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a 57 enum { CXL_CMDS }; 58 59 #undef ___C 60 #undef ___DEPRECATED 61 #define ___C(a, b) { b } 62 #define ___DEPRECATED(a, b) { "Deprecated " b } 63 static const struct { 64 const char *name; 65 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS }; 66 67 /* 68 * Here's how this actually breaks out: 69 * cxl_command_names[] = { 70 * [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" }, 71 * [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" }, 72 * ... 73 * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" }, 74 * }; 75 */ 76 77 #undef ___C 78 #undef ___DEPRECATED 79 #define ___C(a, b) (0) 80 #define ___DEPRECATED(a, b) (1) 81 82 static const __u8 cxl_deprecated_commands[] 83 __attribute__((__unused__)) = { CXL_CMDS }; 84 85 /* 86 * Here's how this actually breaks out: 87 * cxl_deprecated_commands[] = { 88 * [CXL_MEM_COMMAND_ID_INVALID] = 0, 89 * [CXL_MEM_COMMAND_ID_IDENTIFY] = 0, 90 * ... 91 * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1, 92 * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1, 93 * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1, 94 * ... 95 * }; 96 */ 97 98 #undef ___C 99 #undef ___DEPRECATED 100 101 /** 102 * struct cxl_command_info - Command information returned from a query. 103 * @id: ID number for the command. 104 * @flags: Flags that specify command behavior. 105 * 106 * CXL_MEM_COMMAND_FLAG_USER_ENABLED 107 * 108 * The given command id is supported by the driver and is supported by 109 * a related opcode on the device. 110 * 111 * CXL_MEM_COMMAND_FLAG_EXCLUSIVE 112 * 113 * Requests with the given command id will terminate with EBUSY as the 114 * kernel actively owns management of the given resource. For example, 115 * the label-storage-area can not be written while the kernel is 116 * actively managing that space. 117 * 118 * @size_in: Expected input size, or ~0 if variable length. 119 * @size_out: Expected output size, or ~0 if variable length. 120 * 121 * Represents a single command that is supported by both the driver and the 122 * hardware. This is returned as part of an array from the query ioctl. The 123 * following would be a command that takes a variable length input and returns 0 124 * bytes of output. 125 * 126 * - @id = 10 127 * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED 128 * - @size_in = ~0 129 * - @size_out = 0 130 * 131 * See struct cxl_mem_query_commands. 132 */ 133 struct cxl_command_info { 134 __u32 id; 135 136 __u32 flags; 137 #define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0) 138 #define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0) 139 #define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1) 140 141 __u32 size_in; 142 __u32 size_out; 143 }; 144 145 /** 146 * struct cxl_mem_query_commands - Query supported commands. 147 * @n_commands: In/out parameter. When @n_commands is > 0, the driver will 148 * return min(num_support_commands, n_commands). When @n_commands 149 * is 0, driver will return the number of total supported commands. 150 * @rsvd: Reserved for future use. 151 * @commands: Output array of supported commands. This array must be allocated 152 * by userspace to be at least min(num_support_commands, @n_commands) 153 * 154 * Allow userspace to query the available commands supported by both the driver, 155 * and the hardware. Commands that aren't supported by either the driver, or the 156 * hardware are not returned in the query. 157 * 158 * Examples: 159 * 160 * - { .n_commands = 0 } // Get number of supported commands 161 * - { .n_commands = 15, .commands = buf } // Return first 15 (or less) 162 * supported commands 163 * 164 * See struct cxl_command_info. 165 */ 166 struct cxl_mem_query_commands { 167 /* 168 * Input: Number of commands to return (space allocated by user) 169 * Output: Number of commands supported by the driver/hardware 170 * 171 * If n_commands is 0, kernel will only return number of commands and 172 * not try to populate commands[], thus allowing userspace to know how 173 * much space to allocate 174 */ 175 __u32 n_commands; 176 __u32 rsvd; 177 178 struct cxl_command_info __user commands[]; /* out: supported commands */ 179 }; 180 181 /** 182 * struct cxl_send_command - Send a command to a memory device. 183 * @id: The command to send to the memory device. This must be one of the 184 * commands returned by the query command. 185 * @flags: Flags for the command (input). 186 * @raw: Special fields for raw commands 187 * @raw.opcode: Opcode passed to hardware when using the RAW command. 188 * @raw.rsvd: Must be zero. 189 * @rsvd: Must be zero. 190 * @retval: Return value from the memory device (output). 191 * @in: Parameters associated with input payload. 192 * @in.size: Size of the payload to provide to the device (input). 193 * @in.rsvd: Must be zero. 194 * @in.payload: Pointer to memory for payload input, payload is little endian. 195 * @out: Parameters associated with output payload. 196 * @out.size: Size of the payload received from the device (input/output). This 197 * field is filled in by userspace to let the driver know how much 198 * space was allocated for output. It is populated by the driver to 199 * let userspace know how large the output payload actually was. 200 * @out.rsvd: Must be zero. 201 * @out.payload: Pointer to memory for payload output, payload is little endian. 202 * 203 * Mechanism for userspace to send a command to the hardware for processing. The 204 * driver will do basic validation on the command sizes. In some cases even the 205 * payload may be introspected. Userspace is required to allocate large enough 206 * buffers for size_out which can be variable length in certain situations. 207 */ 208 struct cxl_send_command { 209 __u32 id; 210 __u32 flags; 211 union { 212 struct { 213 __u16 opcode; 214 __u16 rsvd; 215 } raw; 216 __u32 rsvd; 217 }; 218 __u32 retval; 219 220 struct { 221 __u32 size; 222 __u32 rsvd; 223 __u64 payload; 224 } in; 225 226 struct { 227 __u32 size; 228 __u32 rsvd; 229 __u64 payload; 230 } out; 231 }; 232 233 #endif 234
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.