1583fa5e7SBen Widawsky /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2583fa5e7SBen Widawsky /* 3583fa5e7SBen Widawsky * CXL IOCTLs for Memory Devices 4583fa5e7SBen Widawsky */ 5583fa5e7SBen Widawsky 6583fa5e7SBen Widawsky #ifndef _UAPI_CXL_MEM_H_ 7583fa5e7SBen Widawsky #define _UAPI_CXL_MEM_H_ 8583fa5e7SBen Widawsky 9583fa5e7SBen Widawsky #include <linux/types.h> 10583fa5e7SBen Widawsky 11583fa5e7SBen Widawsky /** 12583fa5e7SBen Widawsky * DOC: UAPI 13583fa5e7SBen Widawsky * 14af73370dSIra Weiny * Not all of the commands that the driver supports are available for use by 15af73370dSIra Weiny * userspace at all times. Userspace can check the result of the QUERY command 16af73370dSIra Weiny * to determine the live set of commands. Alternatively, it can issue the 17af73370dSIra Weiny * command and check for failure. 18583fa5e7SBen Widawsky */ 19583fa5e7SBen Widawsky 20583fa5e7SBen Widawsky #define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands) 21583fa5e7SBen Widawsky #define CXL_MEM_SEND_COMMAND _IOWR(0xCE, 2, struct cxl_send_command) 22583fa5e7SBen Widawsky 2311ef026eSIra Weiny /* 2411ef026eSIra Weiny * NOTE: New defines must be added to the end of the list to preserve 2511ef026eSIra Weiny * compatibility because this enum is exported to user space. 2611ef026eSIra Weiny */ 27583fa5e7SBen Widawsky #define CXL_CMDS \ 28583fa5e7SBen Widawsky ___C(INVALID, "Invalid Command"), \ 29583fa5e7SBen Widawsky ___C(IDENTIFY, "Identify Command"), \ 3013237183SBen Widawsky ___C(RAW, "Raw device command"), \ 31472b1ce6SBen Widawsky ___C(GET_SUPPORTED_LOGS, "Get Supported Logs"), \ 3257ee605bSBen Widawsky ___C(GET_FW_INFO, "Get FW Info"), \ 3357ee605bSBen Widawsky ___C(GET_PARTITION_INFO, "Get Partition Information"), \ 3457ee605bSBen Widawsky ___C(GET_LSA, "Get Label Storage Area"), \ 3557ee605bSBen Widawsky ___C(GET_HEALTH_INFO, "Get Health Info"), \ 3657ee605bSBen Widawsky ___C(GET_LOG, "Get Log"), \ 3787815ee9SBen Widawsky ___C(SET_PARTITION_INFO, "Set Partition Information"), \ 3887815ee9SBen Widawsky ___C(SET_LSA, "Set Label Storage Area"), \ 3987815ee9SBen Widawsky ___C(GET_ALERT_CONFIG, "Get Alert Configuration"), \ 4087815ee9SBen Widawsky ___C(SET_ALERT_CONFIG, "Set Alert Configuration"), \ 4187815ee9SBen Widawsky ___C(GET_SHUTDOWN_STATE, "Get Shutdown State"), \ 4287815ee9SBen Widawsky ___C(SET_SHUTDOWN_STATE, "Set Shutdown State"), \ 433db166d6SDan Williams ___DEPRECATED(GET_POISON, "Get Poison List"), \ 443db166d6SDan Williams ___DEPRECATED(INJECT_POISON, "Inject Poison"), \ 453db166d6SDan Williams ___DEPRECATED(CLEAR_POISON, "Clear Poison"), \ 4687815ee9SBen Widawsky ___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"), \ 473db166d6SDan Williams ___DEPRECATED(SCAN_MEDIA, "Scan Media"), \ 483db166d6SDan Williams ___DEPRECATED(GET_SCAN_MEDIA, "Get Scan Media Results"), \ 49*cb46fca8SDavidlohr Bueso ___C(GET_TIMESTAMP, "Get Timestamp"), \ 50583fa5e7SBen Widawsky ___C(MAX, "invalid / last command") 51583fa5e7SBen Widawsky 52583fa5e7SBen Widawsky #define ___C(a, b) CXL_MEM_COMMAND_ID_##a 533db166d6SDan Williams #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a 54583fa5e7SBen Widawsky enum { CXL_CMDS }; 55583fa5e7SBen Widawsky 56583fa5e7SBen Widawsky #undef ___C 573db166d6SDan Williams #undef ___DEPRECATED 58583fa5e7SBen Widawsky #define ___C(a, b) { b } 593db166d6SDan Williams #define ___DEPRECATED(a, b) { "Deprecated " b } 60583fa5e7SBen Widawsky static const struct { 61583fa5e7SBen Widawsky const char *name; 629d1b3afdSBen Widawsky } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS }; 63583fa5e7SBen Widawsky 64583fa5e7SBen Widawsky /* 65583fa5e7SBen Widawsky * Here's how this actually breaks out: 66583fa5e7SBen Widawsky * cxl_command_names[] = { 67583fa5e7SBen Widawsky * [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" }, 68583fa5e7SBen Widawsky * [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" }, 69583fa5e7SBen Widawsky * ... 70583fa5e7SBen Widawsky * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" }, 71583fa5e7SBen Widawsky * }; 72583fa5e7SBen Widawsky */ 73583fa5e7SBen Widawsky 74583fa5e7SBen Widawsky #undef ___C 753db166d6SDan Williams #undef ___DEPRECATED 763db166d6SDan Williams #define ___C(a, b) (0) 773db166d6SDan Williams #define ___DEPRECATED(a, b) (1) 783db166d6SDan Williams 793db166d6SDan Williams static const __u8 cxl_deprecated_commands[] 803db166d6SDan Williams __attribute__((__unused__)) = { CXL_CMDS }; 813db166d6SDan Williams 823db166d6SDan Williams /* 833db166d6SDan Williams * Here's how this actually breaks out: 843db166d6SDan Williams * cxl_deprecated_commands[] = { 853db166d6SDan Williams * [CXL_MEM_COMMAND_ID_INVALID] = 0, 863db166d6SDan Williams * [CXL_MEM_COMMAND_ID_IDENTIFY] = 0, 873db166d6SDan Williams * ... 883db166d6SDan Williams * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1, 893db166d6SDan Williams * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1, 903db166d6SDan Williams * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1, 913db166d6SDan Williams * ... 923db166d6SDan Williams * }; 933db166d6SDan Williams */ 943db166d6SDan Williams 953db166d6SDan Williams #undef ___C 963db166d6SDan Williams #undef ___DEPRECATED 97583fa5e7SBen Widawsky 98583fa5e7SBen Widawsky /** 99583fa5e7SBen Widawsky * struct cxl_command_info - Command information returned from a query. 100583fa5e7SBen Widawsky * @id: ID number for the command. 101583fa5e7SBen Widawsky * @flags: Flags that specify command behavior. 102814a15f3SIra Weiny * 103814a15f3SIra Weiny * CXL_MEM_COMMAND_FLAG_USER_ENABLED 104814a15f3SIra Weiny * 105814a15f3SIra Weiny * The given command id is supported by the driver and is supported by 106814a15f3SIra Weiny * a related opcode on the device. 107814a15f3SIra Weiny * 108814a15f3SIra Weiny * CXL_MEM_COMMAND_FLAG_EXCLUSIVE 109814a15f3SIra Weiny * 110814a15f3SIra Weiny * Requests with the given command id will terminate with EBUSY as the 111814a15f3SIra Weiny * kernel actively owns management of the given resource. For example, 112814a15f3SIra Weiny * the label-storage-area can not be written while the kernel is 113814a15f3SIra Weiny * actively managing that space. 114814a15f3SIra Weiny * 11526f89535SAlison Schofield * @size_in: Expected input size, or ~0 if variable length. 11626f89535SAlison Schofield * @size_out: Expected output size, or ~0 if variable length. 117583fa5e7SBen Widawsky * 118583fa5e7SBen Widawsky * Represents a single command that is supported by both the driver and the 119583fa5e7SBen Widawsky * hardware. This is returned as part of an array from the query ioctl. The 120583fa5e7SBen Widawsky * following would be a command that takes a variable length input and returns 0 121583fa5e7SBen Widawsky * bytes of output. 122583fa5e7SBen Widawsky * 123583fa5e7SBen Widawsky * - @id = 10 124814a15f3SIra Weiny * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED 12526f89535SAlison Schofield * - @size_in = ~0 126583fa5e7SBen Widawsky * - @size_out = 0 127583fa5e7SBen Widawsky * 128583fa5e7SBen Widawsky * See struct cxl_mem_query_commands. 129583fa5e7SBen Widawsky */ 130583fa5e7SBen Widawsky struct cxl_command_info { 131583fa5e7SBen Widawsky __u32 id; 132583fa5e7SBen Widawsky 133583fa5e7SBen Widawsky __u32 flags; 134814a15f3SIra Weiny #define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0) 135814a15f3SIra Weiny #define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0) 136814a15f3SIra Weiny #define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1) 137583fa5e7SBen Widawsky 13826f89535SAlison Schofield __u32 size_in; 13926f89535SAlison Schofield __u32 size_out; 140583fa5e7SBen Widawsky }; 141583fa5e7SBen Widawsky 142583fa5e7SBen Widawsky /** 143583fa5e7SBen Widawsky * struct cxl_mem_query_commands - Query supported commands. 144583fa5e7SBen Widawsky * @n_commands: In/out parameter. When @n_commands is > 0, the driver will 145583fa5e7SBen Widawsky * return min(num_support_commands, n_commands). When @n_commands 146583fa5e7SBen Widawsky * is 0, driver will return the number of total supported commands. 147583fa5e7SBen Widawsky * @rsvd: Reserved for future use. 148583fa5e7SBen Widawsky * @commands: Output array of supported commands. This array must be allocated 149583fa5e7SBen Widawsky * by userspace to be at least min(num_support_commands, @n_commands) 150583fa5e7SBen Widawsky * 151583fa5e7SBen Widawsky * Allow userspace to query the available commands supported by both the driver, 152583fa5e7SBen Widawsky * and the hardware. Commands that aren't supported by either the driver, or the 153583fa5e7SBen Widawsky * hardware are not returned in the query. 154583fa5e7SBen Widawsky * 155583fa5e7SBen Widawsky * Examples: 156583fa5e7SBen Widawsky * 157583fa5e7SBen Widawsky * - { .n_commands = 0 } // Get number of supported commands 158583fa5e7SBen Widawsky * - { .n_commands = 15, .commands = buf } // Return first 15 (or less) 159583fa5e7SBen Widawsky * supported commands 160583fa5e7SBen Widawsky * 161583fa5e7SBen Widawsky * See struct cxl_command_info. 162583fa5e7SBen Widawsky */ 163583fa5e7SBen Widawsky struct cxl_mem_query_commands { 164583fa5e7SBen Widawsky /* 165583fa5e7SBen Widawsky * Input: Number of commands to return (space allocated by user) 166583fa5e7SBen Widawsky * Output: Number of commands supported by the driver/hardware 167583fa5e7SBen Widawsky * 168583fa5e7SBen Widawsky * If n_commands is 0, kernel will only return number of commands and 169583fa5e7SBen Widawsky * not try to populate commands[], thus allowing userspace to know how 170583fa5e7SBen Widawsky * much space to allocate 171583fa5e7SBen Widawsky */ 172583fa5e7SBen Widawsky __u32 n_commands; 173583fa5e7SBen Widawsky __u32 rsvd; 174583fa5e7SBen Widawsky 175583fa5e7SBen Widawsky struct cxl_command_info __user commands[]; /* out: supported commands */ 176583fa5e7SBen Widawsky }; 177583fa5e7SBen Widawsky 178583fa5e7SBen Widawsky /** 179583fa5e7SBen Widawsky * struct cxl_send_command - Send a command to a memory device. 180583fa5e7SBen Widawsky * @id: The command to send to the memory device. This must be one of the 181583fa5e7SBen Widawsky * commands returned by the query command. 182583fa5e7SBen Widawsky * @flags: Flags for the command (input). 18313237183SBen Widawsky * @raw: Special fields for raw commands 18413237183SBen Widawsky * @raw.opcode: Opcode passed to hardware when using the RAW command. 18513237183SBen Widawsky * @raw.rsvd: Must be zero. 186583fa5e7SBen Widawsky * @rsvd: Must be zero. 187583fa5e7SBen Widawsky * @retval: Return value from the memory device (output). 188583fa5e7SBen Widawsky * @in: Parameters associated with input payload. 189583fa5e7SBen Widawsky * @in.size: Size of the payload to provide to the device (input). 190583fa5e7SBen Widawsky * @in.rsvd: Must be zero. 191583fa5e7SBen Widawsky * @in.payload: Pointer to memory for payload input, payload is little endian. 192583fa5e7SBen Widawsky * @out: Parameters associated with output payload. 193583fa5e7SBen Widawsky * @out.size: Size of the payload received from the device (input/output). This 194583fa5e7SBen Widawsky * field is filled in by userspace to let the driver know how much 195583fa5e7SBen Widawsky * space was allocated for output. It is populated by the driver to 196583fa5e7SBen Widawsky * let userspace know how large the output payload actually was. 197583fa5e7SBen Widawsky * @out.rsvd: Must be zero. 198583fa5e7SBen Widawsky * @out.payload: Pointer to memory for payload output, payload is little endian. 199583fa5e7SBen Widawsky * 200583fa5e7SBen Widawsky * Mechanism for userspace to send a command to the hardware for processing. The 201583fa5e7SBen Widawsky * driver will do basic validation on the command sizes. In some cases even the 202583fa5e7SBen Widawsky * payload may be introspected. Userspace is required to allocate large enough 203583fa5e7SBen Widawsky * buffers for size_out which can be variable length in certain situations. 204583fa5e7SBen Widawsky */ 205583fa5e7SBen Widawsky struct cxl_send_command { 206583fa5e7SBen Widawsky __u32 id; 207583fa5e7SBen Widawsky __u32 flags; 20813237183SBen Widawsky union { 20913237183SBen Widawsky struct { 21013237183SBen Widawsky __u16 opcode; 21113237183SBen Widawsky __u16 rsvd; 21213237183SBen Widawsky } raw; 213583fa5e7SBen Widawsky __u32 rsvd; 21413237183SBen Widawsky }; 215583fa5e7SBen Widawsky __u32 retval; 216583fa5e7SBen Widawsky 217583fa5e7SBen Widawsky struct { 21826f89535SAlison Schofield __u32 size; 219583fa5e7SBen Widawsky __u32 rsvd; 220583fa5e7SBen Widawsky __u64 payload; 221583fa5e7SBen Widawsky } in; 222583fa5e7SBen Widawsky 223583fa5e7SBen Widawsky struct { 22426f89535SAlison Schofield __u32 size; 225583fa5e7SBen Widawsky __u32 rsvd; 226583fa5e7SBen Widawsky __u64 payload; 227583fa5e7SBen Widawsky } out; 228583fa5e7SBen Widawsky }; 229583fa5e7SBen Widawsky 230583fa5e7SBen Widawsky #endif 231