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(MAX, "invalid / last command")
51
52#define ___C(a, b) CXL_MEM_COMMAND_ID_##a
53#define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
54enum { CXL_CMDS };
55
56#undef ___C
57#undef ___DEPRECATED
58#define ___C(a, b) { b }
59#define ___DEPRECATED(a, b) { "Deprecated " b }
60static const struct {
61 const char *name;
62} cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
63
64/*
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" },
69 * ...
70 * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
71 * };
72 */
73
74#undef ___C
75#undef ___DEPRECATED
76#define ___C(a, b) (0)
77#define ___DEPRECATED(a, b) (1)
78
79static const __u8 cxl_deprecated_commands[]
80 __attribute__((__unused__)) = { CXL_CMDS };
81
82/*
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,
87 * ...
88 * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
89 * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
90 * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
91 * ...
92 * };
93 */
94
95#undef ___C
96#undef ___DEPRECATED
97
98/**
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.
102 *
103 * CXL_MEM_COMMAND_FLAG_USER_ENABLED
104 *
105 * The given command id is supported by the driver and is supported by
106 * a related opcode on the device.
107 *
108 * CXL_MEM_COMMAND_FLAG_EXCLUSIVE
109 *
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.
114 *
115 * @size_in: Expected input size, or ~0 if variable length.
116 * @size_out: Expected output size, or ~0 if variable length.
117 *
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
121 * bytes of output.
122 *
123 * - @id = 10
124 * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED
125 * - @size_in = ~0
126 * - @size_out = 0
127 *
128 * See struct cxl_mem_query_commands.
129 */
130struct cxl_command_info {
131 __u32 id;
132
133 __u32 flags;
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)
137
138 __u32 size_in;
139 __u32 size_out;
140};
141
142/**
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)
150 *
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.
154 *
155 * Examples:
156 *
157 * - { .n_commands = 0 } // Get number of supported commands
158 * - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
159 * supported commands
160 *
161 * See struct cxl_command_info.
162 */
163struct cxl_mem_query_commands {
164 /*
165 * Input: Number of commands to return (space allocated by user)
166 * Output: Number of commands supported by the driver/hardware
167 *
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
171 */
172 __u32 n_commands;
173 __u32 rsvd;
174
175 struct cxl_command_info __user commands[]; /* out: supported commands */
176};
177
178/**
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.
199 *
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.
204 */
205struct cxl_send_command {
206 __u32 id;
207 __u32 flags;
208 union {
209 struct {
210 __u16 opcode;
211 __u16 rsvd;
212 } raw;
213 __u32 rsvd;
214 };
215 __u32 retval;
216
217 struct {
218 __u32 size;
219 __u32 rsvd;
220 __u64 payload;
221 } in;
222
223 struct {
224 __u32 size;
225 __u32 rsvd;
226 __u64 payload;
227 } out;
228};
229
230#endif
231

source code of linux/include/uapi/linux/cxl_mem.h