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(GET_TIMESTAMP, "Get Timestamp"), \
50 ___C(MAX, "invalid / last command")
52 #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
53 #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
58 #define ___C(a, b) { b }
59 #define ___DEPRECATED(a, b) { "Deprecated " b }
62 } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
65 * Here's how this actually breaks out:
66 * cxl_command_names[] = {
67 * [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
68 * [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" },
70 * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
76 #define ___C(a, b) (0)
77 #define ___DEPRECATED(a, b) (1)
79 static const __u8 cxl_deprecated_commands[]
80 __attribute__((__unused__)) = { CXL_CMDS };
83 * Here's how this actually breaks out:
84 * cxl_deprecated_commands[] = {
85 * [CXL_MEM_COMMAND_ID_INVALID] = 0,
86 * [CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
88 * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
89 * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
90 * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
99 * struct cxl_command_info - Command information returned from a query.
100 * @id: ID number for the command.
101 * @flags: Flags that specify command behavior.
103 * CXL_MEM_COMMAND_FLAG_USER_ENABLED
105 * The given command id is supported by the driver and is supported by
106 * a related opcode on the device.
108 * CXL_MEM_COMMAND_FLAG_EXCLUSIVE
110 * Requests with the given command id will terminate with EBUSY as the
111 * kernel actively owns management of the given resource. For example,
112 * the label-storage-area can not be written while the kernel is
113 * actively managing that space.
115 * @size_in: Expected input size, or ~0 if variable length.
116 * @size_out: Expected output size, or ~0 if variable length.
118 * Represents a single command that is supported by both the driver and the
119 * hardware. This is returned as part of an array from the query ioctl. The
120 * following would be a command that takes a variable length input and returns 0
124 * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED
128 * See struct cxl_mem_query_commands.
130 struct cxl_command_info {
134 #define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0)
135 #define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0)
136 #define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1)
143 * struct cxl_mem_query_commands - Query supported commands.
144 * @n_commands: In/out parameter. When @n_commands is > 0, the driver will
145 * return min(num_support_commands, n_commands). When @n_commands
146 * is 0, driver will return the number of total supported commands.
147 * @rsvd: Reserved for future use.
148 * @commands: Output array of supported commands. This array must be allocated
149 * by userspace to be at least min(num_support_commands, @n_commands)
151 * Allow userspace to query the available commands supported by both the driver,
152 * and the hardware. Commands that aren't supported by either the driver, or the
153 * hardware are not returned in the query.
157 * - { .n_commands = 0 } // Get number of supported commands
158 * - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
161 * See struct cxl_command_info.
163 struct cxl_mem_query_commands {
165 * Input: Number of commands to return (space allocated by user)
166 * Output: Number of commands supported by the driver/hardware
168 * If n_commands is 0, kernel will only return number of commands and
169 * not try to populate commands[], thus allowing userspace to know how
170 * much space to allocate
175 struct cxl_command_info __user commands[]; /* out: supported commands */
179 * struct cxl_send_command - Send a command to a memory device.
180 * @id: The command to send to the memory device. This must be one of the
181 * commands returned by the query command.
182 * @flags: Flags for the command (input).
183 * @raw: Special fields for raw commands
184 * @raw.opcode: Opcode passed to hardware when using the RAW command.
185 * @raw.rsvd: Must be zero.
186 * @rsvd: Must be zero.
187 * @retval: Return value from the memory device (output).
188 * @in: Parameters associated with input payload.
189 * @in.size: Size of the payload to provide to the device (input).
190 * @in.rsvd: Must be zero.
191 * @in.payload: Pointer to memory for payload input, payload is little endian.
192 * @out: Parameters associated with output payload.
193 * @out.size: Size of the payload received from the device (input/output). This
194 * field is filled in by userspace to let the driver know how much
195 * space was allocated for output. It is populated by the driver to
196 * let userspace know how large the output payload actually was.
197 * @out.rsvd: Must be zero.
198 * @out.payload: Pointer to memory for payload output, payload is little endian.
200 * Mechanism for userspace to send a command to the hardware for processing. The
201 * driver will do basic validation on the command sizes. In some cases even the
202 * payload may be introspected. Userspace is required to allocate large enough
203 * buffers for size_out which can be variable length in certain situations.
205 struct cxl_send_command {