1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * CXL IOCTLs for Memory Devices
6 #ifndef _UAPI_CXL_MEM_H_
7 #define _UAPI_CXL_MEM_H_
9 #include <linux/types.h>
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.
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)
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.
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")
51 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
52 #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
57 #define ___C(a, b) { b }
58 #define ___DEPRECATED(a, b) { "Deprecated " b }
61 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
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" },
69 * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
75 #define ___C(a, b) (0)
76 #define ___DEPRECATED(a, b) (1)
78 static const __u8 cxl_deprecated_commands[]
79 __attribute__((__unused__)) = { CXL_CMDS };
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,
87 * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
88 * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
89 * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
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.
102 * CXL_MEM_COMMAND_FLAG_USER_ENABLED
104 * The given command id is supported by the driver and is supported by
105 * a related opcode on the device.
107 * CXL_MEM_COMMAND_FLAG_EXCLUSIVE
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.
114 * @size_in: Expected input size, or ~0 if variable length.
115 * @size_out: Expected output size, or ~0 if variable length.
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
123 * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED
127 * See struct cxl_mem_query_commands.
129 struct cxl_command_info {
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)
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)
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.
156 * - { .n_commands = 0 } // Get number of supported commands
157 * - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
160 * See struct cxl_command_info.
162 struct cxl_mem_query_commands {
164 * Input: Number of commands to return (space allocated by user)
165 * Output: Number of commands supported by the driver/hardware
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
174 struct cxl_command_info __user commands[]; /* out: supported commands */
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.
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.
204 struct cxl_send_command {