logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

cxl_mem.h (8143B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * CXL IOCTLs for Memory Devices
  4. */
  5. #ifndef _CXL_MEM_H_
  6. #define _CXL_MEM_H_
  7. #include <linux/types.h>
  8. /**
  9. * DOC: UAPI
  10. *
  11. * Not all of the commands that the driver supports are available for use by
  12. * userspace at all times. Userspace can check the result of the QUERY command
  13. * to determine the live set of commands. Alternatively, it can issue the
  14. * command and check for failure.
  15. */
  16. #define CXL_MEM_QUERY_COMMANDS _IOR(0xCE, 1, struct cxl_mem_query_commands)
  17. #define CXL_MEM_SEND_COMMAND _IOWR(0xCE, 2, struct cxl_send_command)
  18. /*
  19. * NOTE: New defines must be added to the end of the list to preserve
  20. * compatibility because this enum is exported to user space.
  21. */
  22. #define CXL_CMDS \
  23. ___C(INVALID, "Invalid Command"), \
  24. ___C(IDENTIFY, "Identify Command"), \
  25. ___C(RAW, "Raw device command"), \
  26. ___C(GET_SUPPORTED_LOGS, "Get Supported Logs"), \
  27. ___C(GET_FW_INFO, "Get FW Info"), \
  28. ___C(GET_PARTITION_INFO, "Get Partition Information"), \
  29. ___C(GET_LSA, "Get Label Storage Area"), \
  30. ___C(GET_HEALTH_INFO, "Get Health Info"), \
  31. ___C(GET_LOG, "Get Log"), \
  32. ___C(SET_PARTITION_INFO, "Set Partition Information"), \
  33. ___C(SET_LSA, "Set Label Storage Area"), \
  34. ___C(GET_ALERT_CONFIG, "Get Alert Configuration"), \
  35. ___C(SET_ALERT_CONFIG, "Set Alert Configuration"), \
  36. ___C(GET_SHUTDOWN_STATE, "Get Shutdown State"), \
  37. ___C(SET_SHUTDOWN_STATE, "Set Shutdown State"), \
  38. ___DEPRECATED(GET_POISON, "Get Poison List"), \
  39. ___DEPRECATED(INJECT_POISON, "Inject Poison"), \
  40. ___DEPRECATED(CLEAR_POISON, "Clear Poison"), \
  41. ___C(GET_SCAN_MEDIA_CAPS, "Get Scan Media Capabilities"), \
  42. ___DEPRECATED(SCAN_MEDIA, "Scan Media"), \
  43. ___DEPRECATED(GET_SCAN_MEDIA, "Get Scan Media Results"), \
  44. ___C(GET_TIMESTAMP, "Get Timestamp"), \
  45. ___C(GET_LOG_CAPS, "Get Log Capabilities"), \
  46. ___C(CLEAR_LOG, "Clear Log"), \
  47. ___C(GET_SUP_LOG_SUBLIST, "Get Supported Logs Sub-List"), \
  48. ___C(MAX, "invalid / last command")
  49. #define ___C(a, b) CXL_MEM_COMMAND_ID_##a
  50. #define ___DEPRECATED(a, b) CXL_MEM_DEPRECATED_ID_##a
  51. enum { CXL_CMDS };
  52. #undef ___C
  53. #undef ___DEPRECATED
  54. #define ___C(a, b) { b }
  55. #define ___DEPRECATED(a, b) { "Deprecated " b }
  56. static const struct {
  57. const char *name;
  58. } cxl_command_names[] __attribute__((__unused__)) = { CXL_CMDS };
  59. /*
  60. * Here's how this actually breaks out:
  61. * cxl_command_names[] = {
  62. * [CXL_MEM_COMMAND_ID_INVALID] = { "Invalid Command" },
  63. * [CXL_MEM_COMMAND_ID_IDENTIFY] = { "Identify Command" },
  64. * ...
  65. * [CXL_MEM_COMMAND_ID_MAX] = { "invalid / last command" },
  66. * };
  67. */
  68. #undef ___C
  69. #undef ___DEPRECATED
  70. #define ___C(a, b) (0)
  71. #define ___DEPRECATED(a, b) (1)
  72. static const __u8 cxl_deprecated_commands[]
  73. __attribute__((__unused__)) = { CXL_CMDS };
  74. /*
  75. * Here's how this actually breaks out:
  76. * cxl_deprecated_commands[] = {
  77. * [CXL_MEM_COMMAND_ID_INVALID] = 0,
  78. * [CXL_MEM_COMMAND_ID_IDENTIFY] = 0,
  79. * ...
  80. * [CXL_MEM_DEPRECATED_ID_GET_POISON] = 1,
  81. * [CXL_MEM_DEPRECATED_ID_INJECT_POISON] = 1,
  82. * [CXL_MEM_DEPRECATED_ID_CLEAR_POISON] = 1,
  83. * ...
  84. * };
  85. */
  86. #undef ___C
  87. #undef ___DEPRECATED
  88. /**
  89. * struct cxl_command_info - Command information returned from a query.
  90. * @id: ID number for the command.
  91. * @flags: Flags that specify command behavior.
  92. *
  93. * CXL_MEM_COMMAND_FLAG_USER_ENABLED
  94. *
  95. * The given command id is supported by the driver and is supported by
  96. * a related opcode on the device.
  97. *
  98. * CXL_MEM_COMMAND_FLAG_EXCLUSIVE
  99. *
  100. * Requests with the given command id will terminate with EBUSY as the
  101. * kernel actively owns management of the given resource. For example,
  102. * the label-storage-area can not be written while the kernel is
  103. * actively managing that space.
  104. *
  105. * @size_in: Expected input size, or ~0 if variable length.
  106. * @size_out: Expected output size, or ~0 if variable length.
  107. *
  108. * Represents a single command that is supported by both the driver and the
  109. * hardware. This is returned as part of an array from the query ioctl. The
  110. * following would be a command that takes a variable length input and returns 0
  111. * bytes of output.
  112. *
  113. * - @id = 10
  114. * - @flags = CXL_MEM_COMMAND_FLAG_ENABLED
  115. * - @size_in = ~0
  116. * - @size_out = 0
  117. *
  118. * See struct cxl_mem_query_commands.
  119. */
  120. struct cxl_command_info {
  121. __u32 id;
  122. __u32 flags;
  123. #define CXL_MEM_COMMAND_FLAG_MASK GENMASK(1, 0)
  124. #define CXL_MEM_COMMAND_FLAG_ENABLED BIT(0)
  125. #define CXL_MEM_COMMAND_FLAG_EXCLUSIVE BIT(1)
  126. __u32 size_in;
  127. __u32 size_out;
  128. };
  129. /**
  130. * struct cxl_mem_query_commands - Query supported commands.
  131. * @n_commands: In/out parameter. When @n_commands is > 0, the driver will
  132. * return min(num_support_commands, n_commands). When @n_commands
  133. * is 0, driver will return the number of total supported commands.
  134. * @rsvd: Reserved for future use.
  135. * @commands: Output array of supported commands. This array must be allocated
  136. * by userspace to be at least min(num_support_commands, @n_commands)
  137. *
  138. * Allow userspace to query the available commands supported by both the driver,
  139. * and the hardware. Commands that aren't supported by either the driver, or the
  140. * hardware are not returned in the query.
  141. *
  142. * Examples:
  143. *
  144. * - { .n_commands = 0 } // Get number of supported commands
  145. * - { .n_commands = 15, .commands = buf } // Return first 15 (or less)
  146. * supported commands
  147. *
  148. * See struct cxl_command_info.
  149. */
  150. struct cxl_mem_query_commands {
  151. /*
  152. * Input: Number of commands to return (space allocated by user)
  153. * Output: Number of commands supported by the driver/hardware
  154. *
  155. * If n_commands is 0, kernel will only return number of commands and
  156. * not try to populate commands[], thus allowing userspace to know how
  157. * much space to allocate
  158. */
  159. __u32 n_commands;
  160. __u32 rsvd;
  161. struct cxl_command_info commands[]; /* out: supported commands */
  162. };
  163. /**
  164. * struct cxl_send_command - Send a command to a memory device.
  165. * @id: The command to send to the memory device. This must be one of the
  166. * commands returned by the query command.
  167. * @flags: Flags for the command (input).
  168. * @raw: Special fields for raw commands
  169. * @raw.opcode: Opcode passed to hardware when using the RAW command.
  170. * @raw.rsvd: Must be zero.
  171. * @rsvd: Must be zero.
  172. * @retval: Return value from the memory device (output).
  173. * @in: Parameters associated with input payload.
  174. * @in.size: Size of the payload to provide to the device (input).
  175. * @in.rsvd: Must be zero.
  176. * @in.payload: Pointer to memory for payload input, payload is little endian.
  177. * @out: Parameters associated with output payload.
  178. * @out.size: Size of the payload received from the device (input/output). This
  179. * field is filled in by userspace to let the driver know how much
  180. * space was allocated for output. It is populated by the driver to
  181. * let userspace know how large the output payload actually was.
  182. * @out.rsvd: Must be zero.
  183. * @out.payload: Pointer to memory for payload output, payload is little endian.
  184. *
  185. * Mechanism for userspace to send a command to the hardware for processing. The
  186. * driver will do basic validation on the command sizes. In some cases even the
  187. * payload may be introspected. Userspace is required to allocate large enough
  188. * buffers for size_out which can be variable length in certain situations.
  189. */
  190. struct cxl_send_command {
  191. __u32 id;
  192. __u32 flags;
  193. union {
  194. struct {
  195. __u16 opcode;
  196. __u16 rsvd;
  197. } raw;
  198. __u32 rsvd;
  199. };
  200. __u32 retval;
  201. struct {
  202. __u32 size;
  203. __u32 rsvd;
  204. __u64 payload;
  205. } in;
  206. struct {
  207. __u32 size;
  208. __u32 rsvd;
  209. __u64 payload;
  210. } out;
  211. };
  212. #endif