xref: /openbmc/linux/drivers/cxl/cxlmem.h (revision 0c36b6ad436a38b167af16e6c690c890b8b2df62)
15161a55cSBen Widawsky /* SPDX-License-Identifier: GPL-2.0-only */
25161a55cSBen Widawsky /* Copyright(c) 2020-2021 Intel Corporation. */
35161a55cSBen Widawsky #ifndef __CXL_MEM_H__
45161a55cSBen Widawsky #define __CXL_MEM_H__
54faf31b4SDan Williams #include <uapi/linux/cxl_mem.h>
65161a55cSBen Widawsky #include <linux/cdev.h>
76ebe28f9SIra Weiny #include <linux/uuid.h>
8ccadf131SDavidlohr Bueso #include <linux/rcuwait.h>
95161a55cSBen Widawsky #include "cxl.h"
105161a55cSBen Widawsky 
115161a55cSBen Widawsky /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
125161a55cSBen Widawsky #define CXLMDEV_STATUS_OFFSET 0x0
135161a55cSBen Widawsky #define   CXLMDEV_DEV_FATAL BIT(0)
145161a55cSBen Widawsky #define   CXLMDEV_FW_HALT BIT(1)
155161a55cSBen Widawsky #define   CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2)
165161a55cSBen Widawsky #define     CXLMDEV_MS_NOT_READY 0
175161a55cSBen Widawsky #define     CXLMDEV_MS_READY 1
185161a55cSBen Widawsky #define     CXLMDEV_MS_ERROR 2
195161a55cSBen Widawsky #define     CXLMDEV_MS_DISABLED 3
205161a55cSBen Widawsky #define CXLMDEV_READY(status)                                                  \
215161a55cSBen Widawsky 	(FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) ==                \
225161a55cSBen Widawsky 	 CXLMDEV_MS_READY)
235161a55cSBen Widawsky #define   CXLMDEV_MBOX_IF_READY BIT(4)
245161a55cSBen Widawsky #define   CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5)
255161a55cSBen Widawsky #define     CXLMDEV_RESET_NEEDED_NOT 0
265161a55cSBen Widawsky #define     CXLMDEV_RESET_NEEDED_COLD 1
275161a55cSBen Widawsky #define     CXLMDEV_RESET_NEEDED_WARM 2
285161a55cSBen Widawsky #define     CXLMDEV_RESET_NEEDED_HOT 3
295161a55cSBen Widawsky #define     CXLMDEV_RESET_NEEDED_CXL 4
305161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED(status)                                           \
315161a55cSBen Widawsky 	(FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) !=                       \
325161a55cSBen Widawsky 	 CXLMDEV_RESET_NEEDED_NOT)
335161a55cSBen Widawsky 
345161a55cSBen Widawsky /**
355161a55cSBen Widawsky  * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device
365161a55cSBen Widawsky  * @dev: driver core device object
375161a55cSBen Widawsky  * @cdev: char dev core object for ioctl operations
385e2411aeSIra Weiny  * @cxlds: The device state backing this device
398dd2bc0fSBen Widawsky  * @detach_work: active memdev lost a port in its ancestry
40f17b558dSDan Williams  * @cxl_nvb: coordinate removal of @cxl_nvd if present
41f17b558dSDan Williams  * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
425161a55cSBen Widawsky  * @id: id number of this memdev instance.
432345df54SDan Williams  * @depth: endpoint port depth
445161a55cSBen Widawsky  */
455161a55cSBen Widawsky struct cxl_memdev {
465161a55cSBen Widawsky 	struct device dev;
475161a55cSBen Widawsky 	struct cdev cdev;
485e2411aeSIra Weiny 	struct cxl_dev_state *cxlds;
498dd2bc0fSBen Widawsky 	struct work_struct detach_work;
50f17b558dSDan Williams 	struct cxl_nvdimm_bridge *cxl_nvb;
51f17b558dSDan Williams 	struct cxl_nvdimm *cxl_nvd;
525161a55cSBen Widawsky 	int id;
532345df54SDan Williams 	int depth;
545161a55cSBen Widawsky };
555161a55cSBen Widawsky 
563d135db5SBen Widawsky static inline struct cxl_memdev *to_cxl_memdev(struct device *dev)
573d135db5SBen Widawsky {
583d135db5SBen Widawsky 	return container_of(dev, struct cxl_memdev, dev);
593d135db5SBen Widawsky }
603d135db5SBen Widawsky 
619c57cde0SDan Williams static inline struct cxl_port *cxled_to_port(struct cxl_endpoint_decoder *cxled)
629c57cde0SDan Williams {
639c57cde0SDan Williams 	return to_cxl_port(cxled->cxld.dev.parent);
649c57cde0SDan Williams }
659c57cde0SDan Williams 
66384e624bSDan Williams static inline struct cxl_port *cxlrd_to_port(struct cxl_root_decoder *cxlrd)
67384e624bSDan Williams {
68384e624bSDan Williams 	return to_cxl_port(cxlrd->cxlsd.cxld.dev.parent);
69384e624bSDan Williams }
70384e624bSDan Williams 
719c57cde0SDan Williams static inline struct cxl_memdev *
729c57cde0SDan Williams cxled_to_memdev(struct cxl_endpoint_decoder *cxled)
739c57cde0SDan Williams {
749c57cde0SDan Williams 	struct cxl_port *port = to_cxl_port(cxled->cxld.dev.parent);
759c57cde0SDan Williams 
769c57cde0SDan Williams 	return to_cxl_memdev(port->uport);
779c57cde0SDan Williams }
789c57cde0SDan Williams 
792a81ada3SGreg Kroah-Hartman bool is_cxl_memdev(const struct device *dev);
808dd2bc0fSBen Widawsky static inline bool is_cxl_endpoint(struct cxl_port *port)
818dd2bc0fSBen Widawsky {
828dd2bc0fSBen Widawsky 	return is_cxl_memdev(port->uport);
838dd2bc0fSBen Widawsky }
848dd2bc0fSBen Widawsky 
855e2411aeSIra Weiny struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds);
863d8f7ccaSDan Williams int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
873d8f7ccaSDan Williams 			 resource_size_t base, resource_size_t len,
883d8f7ccaSDan Williams 			 resource_size_t skipped);
893d135db5SBen Widawsky 
907592d935SDan Williams static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port,
917592d935SDan Williams 					 struct cxl_memdev *cxlmd)
927592d935SDan Williams {
937592d935SDan Williams 	if (!port)
947592d935SDan Williams 		return NULL;
957592d935SDan Williams 
967592d935SDan Williams 	return xa_load(&port->endpoints, (unsigned long)&cxlmd->dev);
977592d935SDan Williams }
987592d935SDan Williams 
995161a55cSBen Widawsky /**
100b64955a9SDan Williams  * struct cxl_mbox_cmd - A command to be submitted to hardware.
101b64955a9SDan Williams  * @opcode: (input) The command set and command submitted to hardware.
102b64955a9SDan Williams  * @payload_in: (input) Pointer to the input payload.
103b64955a9SDan Williams  * @payload_out: (output) Pointer to the output payload. Must be allocated by
104b64955a9SDan Williams  *		 the caller.
105b64955a9SDan Williams  * @size_in: (input) Number of bytes to load from @payload_in.
106b64955a9SDan Williams  * @size_out: (input) Max number of bytes loaded into @payload_out.
107b64955a9SDan Williams  *            (output) Number of bytes generated by the device. For fixed size
108b64955a9SDan Williams  *            outputs commands this is always expected to be deterministic. For
109b64955a9SDan Williams  *            variable sized output commands, it tells the exact number of bytes
110b64955a9SDan Williams  *            written.
1112aeaf663SDan Williams  * @min_out: (input) internal command output payload size validation
112ccadf131SDavidlohr Bueso  * @poll_count: (input) Number of timeouts to attempt.
113ccadf131SDavidlohr Bueso  * @poll_interval_ms: (input) Time between mailbox background command polling
114ccadf131SDavidlohr Bueso  *                    interval timeouts.
115b64955a9SDan Williams  * @return_code: (output) Error code returned from hardware.
116b64955a9SDan Williams  *
117b64955a9SDan Williams  * This is the primary mechanism used to send commands to the hardware.
118b64955a9SDan Williams  * All the fields except @payload_* correspond exactly to the fields described in
119b64955a9SDan Williams  * Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and
120b64955a9SDan Williams  * @payload_out are written to, and read from the Command Payload Registers
121b64955a9SDan Williams  * defined in CXL 2.0 8.2.8.4.8.
122b64955a9SDan Williams  */
123b64955a9SDan Williams struct cxl_mbox_cmd {
124b64955a9SDan Williams 	u16 opcode;
125b64955a9SDan Williams 	void *payload_in;
126b64955a9SDan Williams 	void *payload_out;
127b64955a9SDan Williams 	size_t size_in;
128b64955a9SDan Williams 	size_t size_out;
1292aeaf663SDan Williams 	size_t min_out;
130ccadf131SDavidlohr Bueso 	int poll_count;
131ccadf131SDavidlohr Bueso 	int poll_interval_ms;
132b64955a9SDan Williams 	u16 return_code;
133b64955a9SDan Williams };
134b64955a9SDan Williams 
135b64955a9SDan Williams /*
136bfe58458SDavidlohr Bueso  * Per CXL 3.0 Section 8.2.8.4.5.1
13792fcc1abSDavidlohr Bueso  */
13892fcc1abSDavidlohr Bueso #define CMD_CMD_RC_TABLE							\
13992fcc1abSDavidlohr Bueso 	C(SUCCESS, 0, NULL),							\
14092fcc1abSDavidlohr Bueso 	C(BACKGROUND, -ENXIO, "background cmd started successfully"),           \
14192fcc1abSDavidlohr Bueso 	C(INPUT, -ENXIO, "cmd input was invalid"),				\
14292fcc1abSDavidlohr Bueso 	C(UNSUPPORTED, -ENXIO, "cmd is not supported"),				\
14392fcc1abSDavidlohr Bueso 	C(INTERNAL, -ENXIO, "internal device error"),				\
14492fcc1abSDavidlohr Bueso 	C(RETRY, -ENXIO, "temporary error, retry once"),			\
14592fcc1abSDavidlohr Bueso 	C(BUSY, -ENXIO, "ongoing background operation"),			\
14692fcc1abSDavidlohr Bueso 	C(MEDIADISABLED, -ENXIO, "media access is disabled"),			\
14792fcc1abSDavidlohr Bueso 	C(FWINPROGRESS, -ENXIO,	"one FW package can be transferred at a time"), \
14892fcc1abSDavidlohr Bueso 	C(FWOOO, -ENXIO, "FW package content was transferred out of order"),    \
14992fcc1abSDavidlohr Bueso 	C(FWAUTH, -ENXIO, "FW package authentication failed"),			\
15092fcc1abSDavidlohr Bueso 	C(FWSLOT, -ENXIO, "FW slot is not supported for requested operation"),  \
15192fcc1abSDavidlohr Bueso 	C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"),         \
15292fcc1abSDavidlohr Bueso 	C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"),		\
15392fcc1abSDavidlohr Bueso 	C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"),     \
1547ff6ad10SAlison Schofield 	C(PADDR, -EFAULT, "physical address specified is invalid"),		\
15592fcc1abSDavidlohr Bueso 	C(POISONLMT, -ENXIO, "poison injection limit has been reached"),        \
15692fcc1abSDavidlohr Bueso 	C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"),		\
15792fcc1abSDavidlohr Bueso 	C(ABORT, -ENXIO, "background cmd was aborted by device"),               \
15892fcc1abSDavidlohr Bueso 	C(SECURITY, -ENXIO, "not valid in the current security state"),         \
15992fcc1abSDavidlohr Bueso 	C(PASSPHRASE, -ENXIO, "phrase doesn't match current set passphrase"),   \
16092fcc1abSDavidlohr Bueso 	C(MBUNSUPPORTED, -ENXIO, "unsupported on the mailbox it was issued on"),\
161bfe58458SDavidlohr Bueso 	C(PAYLOADLEN, -ENXIO, "invalid payload length"),			\
162bfe58458SDavidlohr Bueso 	C(LOG, -ENXIO, "invalid or unsupported log page"),			\
163bfe58458SDavidlohr Bueso 	C(INTERRUPTED, -ENXIO, "asynchronous event occured"),			\
164bfe58458SDavidlohr Bueso 	C(FEATUREVERSION, -ENXIO, "unsupported feature version"),		\
165bfe58458SDavidlohr Bueso 	C(FEATURESELVALUE, -ENXIO, "unsupported feature selection value"),	\
166bfe58458SDavidlohr Bueso 	C(FEATURETRANSFERIP, -ENXIO, "feature transfer in progress"),		\
167bfe58458SDavidlohr Bueso 	C(FEATURETRANSFEROOO, -ENXIO, "feature transfer out of order"),		\
168bfe58458SDavidlohr Bueso 	C(RESOURCEEXHAUSTED, -ENXIO, "resources are exhausted"),		\
169bfe58458SDavidlohr Bueso 	C(EXTLIST, -ENXIO, "invalid Extent List"),				\
17092fcc1abSDavidlohr Bueso 
17192fcc1abSDavidlohr Bueso #undef C
17292fcc1abSDavidlohr Bueso #define C(a, b, c) CXL_MBOX_CMD_RC_##a
17392fcc1abSDavidlohr Bueso enum  { CMD_CMD_RC_TABLE };
17492fcc1abSDavidlohr Bueso #undef C
17592fcc1abSDavidlohr Bueso #define C(a, b, c) { b, c }
17692fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc {
17792fcc1abSDavidlohr Bueso 	int err;
17892fcc1abSDavidlohr Bueso 	const char *desc;
17992fcc1abSDavidlohr Bueso };
18092fcc1abSDavidlohr Bueso 
18192fcc1abSDavidlohr Bueso static const
18292fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE };
18392fcc1abSDavidlohr Bueso #undef C
18492fcc1abSDavidlohr Bueso 
18592fcc1abSDavidlohr Bueso static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd)
18692fcc1abSDavidlohr Bueso {
18792fcc1abSDavidlohr Bueso 	return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc;
18892fcc1abSDavidlohr Bueso }
18992fcc1abSDavidlohr Bueso 
19092fcc1abSDavidlohr Bueso static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd)
19192fcc1abSDavidlohr Bueso {
19292fcc1abSDavidlohr Bueso 	return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err;
19392fcc1abSDavidlohr Bueso }
19492fcc1abSDavidlohr Bueso 
19592fcc1abSDavidlohr Bueso /*
196b64955a9SDan Williams  * CXL 2.0 - Memory capacity multiplier
197b64955a9SDan Williams  * See Section 8.2.9.5
198b64955a9SDan Williams  *
199b64955a9SDan Williams  * Volatile, Persistent, and Partition capacities are specified to be in
200b64955a9SDan Williams  * multiples of 256MB - define a multiplier to convert to/from bytes.
201b64955a9SDan Williams  */
202b64955a9SDan Williams #define CXL_CAPACITY_MULTIPLIER SZ_256M
203b64955a9SDan Williams 
204b64955a9SDan Williams /**
205a49aa814SDavidlohr Bueso  * Event Interrupt Policy
206a49aa814SDavidlohr Bueso  *
207a49aa814SDavidlohr Bueso  * CXL rev 3.0 section 8.2.9.2.4; Table 8-52
208560f7855SBen Widawsky  */
209a49aa814SDavidlohr Bueso enum cxl_event_int_mode {
210a49aa814SDavidlohr Bueso 	CXL_INT_NONE		= 0x00,
211a49aa814SDavidlohr Bueso 	CXL_INT_MSI_MSIX	= 0x01,
212a49aa814SDavidlohr Bueso 	CXL_INT_FW		= 0x02
213a49aa814SDavidlohr Bueso };
214a49aa814SDavidlohr Bueso struct cxl_event_interrupt_policy {
215a49aa814SDavidlohr Bueso 	u8 info_settings;
216a49aa814SDavidlohr Bueso 	u8 warn_settings;
217a49aa814SDavidlohr Bueso 	u8 failure_settings;
218a49aa814SDavidlohr Bueso 	u8 fatal_settings;
219a49aa814SDavidlohr Bueso } __packed;
220a49aa814SDavidlohr Bueso 
221a49aa814SDavidlohr Bueso /**
2226ebe28f9SIra Weiny  * struct cxl_event_state - Event log driver state
2236ebe28f9SIra Weiny  *
2246ebe28f9SIra Weiny  * @event_buf: Buffer to receive event data
2256ebe28f9SIra Weiny  * @event_log_lock: Serialize event_buf and log use
2266ebe28f9SIra Weiny  */
2276ebe28f9SIra Weiny struct cxl_event_state {
2286ebe28f9SIra Weiny 	struct cxl_get_event_payload *buf;
2296ebe28f9SIra Weiny 	struct mutex log_lock;
230560f7855SBen Widawsky };
231560f7855SBen Widawsky 
232d0abf578SAlison Schofield /* Device enabled poison commands */
233d0abf578SAlison Schofield enum poison_cmd_enabled_bits {
234d0abf578SAlison Schofield 	CXL_POISON_ENABLED_LIST,
235d0abf578SAlison Schofield 	CXL_POISON_ENABLED_INJECT,
236d0abf578SAlison Schofield 	CXL_POISON_ENABLED_CLEAR,
237d0abf578SAlison Schofield 	CXL_POISON_ENABLED_SCAN_CAPS,
238d0abf578SAlison Schofield 	CXL_POISON_ENABLED_SCAN_MEDIA,
239d0abf578SAlison Schofield 	CXL_POISON_ENABLED_SCAN_RESULTS,
240d0abf578SAlison Schofield 	CXL_POISON_ENABLED_MAX
241d0abf578SAlison Schofield };
242d0abf578SAlison Schofield 
243d0abf578SAlison Schofield /**
244d0abf578SAlison Schofield  * struct cxl_poison_state - Driver poison state info
245d0abf578SAlison Schofield  *
246d0abf578SAlison Schofield  * @max_errors: Maximum media error records held in device cache
247d0abf578SAlison Schofield  * @enabled_cmds: All poison commands enabled in the CEL
248d0abf578SAlison Schofield  * @list_out: The poison list payload returned by device
249d0abf578SAlison Schofield  * @lock: Protect reads of the poison list
250d0abf578SAlison Schofield  *
251d0abf578SAlison Schofield  * Reads of the poison list are synchronized to ensure that a reader
252d0abf578SAlison Schofield  * does not get an incomplete list because their request overlapped
253d0abf578SAlison Schofield  * (was interrupted or preceded by) another read request of the same
254d0abf578SAlison Schofield  * DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1
255d0abf578SAlison Schofield  */
256d0abf578SAlison Schofield struct cxl_poison_state {
257d0abf578SAlison Schofield 	u32 max_errors;
258d0abf578SAlison Schofield 	DECLARE_BITMAP(enabled_cmds, CXL_POISON_ENABLED_MAX);
259d0abf578SAlison Schofield 	struct cxl_mbox_poison_out *list_out;
260d0abf578SAlison Schofield 	struct mutex lock;  /* Protect reads of poison list */
261d0abf578SAlison Schofield };
262d0abf578SAlison Schofield 
263560f7855SBen Widawsky /**
2649968c9ddSDavidlohr Bueso  * struct cxl_security_state - Device security state
2659968c9ddSDavidlohr Bueso  *
2669968c9ddSDavidlohr Bueso  * @state: state of last security operation
267*0c36b6adSDavidlohr Bueso  * @poll: polling for sanitization is enabled, device has no mbox irq support
268*0c36b6adSDavidlohr Bueso  * @poll_tmo_secs: polling timeout
269*0c36b6adSDavidlohr Bueso  * @poll_dwork: polling work item
2709968c9ddSDavidlohr Bueso  */
2719968c9ddSDavidlohr Bueso struct cxl_security_state {
2729968c9ddSDavidlohr Bueso 	unsigned long state;
273*0c36b6adSDavidlohr Bueso 	bool poll;
274*0c36b6adSDavidlohr Bueso 	int poll_tmo_secs;
275*0c36b6adSDavidlohr Bueso 	struct delayed_work poll_dwork;
2769968c9ddSDavidlohr Bueso };
2779968c9ddSDavidlohr Bueso 
2789968c9ddSDavidlohr Bueso /**
2795e2411aeSIra Weiny  * struct cxl_dev_state - The driver device state
2805e2411aeSIra Weiny  *
2815e2411aeSIra Weiny  * cxl_dev_state represents the CXL driver/device state.  It provides an
2825e2411aeSIra Weiny  * interface to mailbox commands as well as some cached data about the device.
2835e2411aeSIra Weiny  * Currently only memory devices are represented.
2845e2411aeSIra Weiny  *
2855e2411aeSIra Weiny  * @dev: The device associated with this CXL state
2862905cb52SDan Williams  * @cxlmd: The device representing the CXL.mem capabilities of @dev
2875161a55cSBen Widawsky  * @regs: Parsed register blocks
28806e279e5SBen Widawsky  * @cxl_dvsec: Offset to the PCIe device DVSEC
2890a19bfc8SDan Williams  * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
290e764f122SDave Jiang  * @media_ready: Indicate whether the device media is usable
2915161a55cSBen Widawsky  * @payload_size: Size of space for payload
2925161a55cSBen Widawsky  *                (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
2935161a55cSBen Widawsky  * @lsa_size: Size of Label Storage Area
2945161a55cSBen Widawsky  *                (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
2955161a55cSBen Widawsky  * @mbox_mutex: Mutex to synchronize mailbox access.
2965161a55cSBen Widawsky  * @firmware_version: Firmware version for the memory device.
2975161a55cSBen Widawsky  * @enabled_cmds: Hardware commands found enabled in CEL.
29812f3856aSDan Williams  * @exclusive_cmds: Commands that are kernel-internal only
299d3b75029SDan Williams  * @dpa_res: Overall DPA resource tree for the device
300d3b75029SDan Williams  * @pmem_res: Active Persistent memory capacity configuration
301d3b75029SDan Williams  * @ram_res: Active Volatile memory capacity configuration
30213e7749dSDan Williams  * @total_bytes: sum of all possible capacities
30313e7749dSDan Williams  * @volatile_only_bytes: hard volatile capacity
30413e7749dSDan Williams  * @persistent_only_bytes: hard persistent capacity
30513e7749dSDan Williams  * @partition_align_bytes: alignment size for partition-able capacity
30613e7749dSDan Williams  * @active_volatile_bytes: sum of hard + soft volatile
30713e7749dSDan Williams  * @active_persistent_bytes: sum of hard + soft persistent
30813e7749dSDan Williams  * @next_volatile_bytes: volatile capacity change pending device reset
30913e7749dSDan Williams  * @next_persistent_bytes: persistent capacity change pending device reset
3104112a08dSBen Widawsky  * @component_reg_phys: register base of component registers
311560f7855SBen Widawsky  * @info: Cached DVSEC information about the device.
312bcc79ea3SDan Williams  * @serial: PCIe Device Serial Number
3131bb31131SAlison Schofield  * @event: event log driver state
314d0abf578SAlison Schofield  * @poison: poison driver state info
315b64955a9SDan Williams  * @mbox_send: @dev specific transport for transmitting mailbox commands
31613e7749dSDan Williams  *
31713e7749dSDan Williams  * See section 8.2.9.5.2 Capacity Configuration and Label Storage for
31813e7749dSDan Williams  * details on capacity parameters.
3195161a55cSBen Widawsky  */
3205e2411aeSIra Weiny struct cxl_dev_state {
32199e222a5SDan Williams 	struct device *dev;
3222905cb52SDan Williams 	struct cxl_memdev *cxlmd;
3235161a55cSBen Widawsky 
3245161a55cSBen Widawsky 	struct cxl_regs regs;
32506e279e5SBen Widawsky 	int cxl_dvsec;
3265161a55cSBen Widawsky 
3270a19bfc8SDan Williams 	bool rcd;
328e764f122SDave Jiang 	bool media_ready;
3295161a55cSBen Widawsky 	size_t payload_size;
3305161a55cSBen Widawsky 	size_t lsa_size;
3315161a55cSBen Widawsky 	struct mutex mbox_mutex; /* Protects device mailbox and firmware */
3325161a55cSBen Widawsky 	char firmware_version[0x10];
333ff56ab9eSDan Williams 	DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX);
33412f3856aSDan Williams 	DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX);
3355161a55cSBen Widawsky 
336d3b75029SDan Williams 	struct resource dpa_res;
337d3b75029SDan Williams 	struct resource pmem_res;
338d3b75029SDan Williams 	struct resource ram_res;
3390b9159d0SIra Weiny 	u64 total_bytes;
3400b9159d0SIra Weiny 	u64 volatile_only_bytes;
3410b9159d0SIra Weiny 	u64 persistent_only_bytes;
3420b9159d0SIra Weiny 	u64 partition_align_bytes;
343f847502aSIra Weiny 
344f847502aSIra Weiny 	u64 active_volatile_bytes;
345f847502aSIra Weiny 	u64 active_persistent_bytes;
346f847502aSIra Weiny 	u64 next_volatile_bytes;
347f847502aSIra Weiny 	u64 next_persistent_bytes;
348b64955a9SDan Williams 
3494112a08dSBen Widawsky 	resource_size_t component_reg_phys;
350bcc79ea3SDan Williams 	u64 serial;
3514112a08dSBen Widawsky 
3526ebe28f9SIra Weiny 	struct cxl_event_state event;
353d0abf578SAlison Schofield 	struct cxl_poison_state poison;
3549968c9ddSDavidlohr Bueso 	struct cxl_security_state security;
3556ebe28f9SIra Weiny 
356ccadf131SDavidlohr Bueso 	struct rcuwait mbox_wait;
3575e2411aeSIra Weiny 	int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);
3585161a55cSBen Widawsky };
3594faf31b4SDan Williams 
3604faf31b4SDan Williams enum cxl_opcode {
3614faf31b4SDan Williams 	CXL_MBOX_OP_INVALID		= 0x0000,
3624faf31b4SDan Williams 	CXL_MBOX_OP_RAW			= CXL_MBOX_OP_INVALID,
3636ebe28f9SIra Weiny 	CXL_MBOX_OP_GET_EVENT_RECORD	= 0x0100,
3646ebe28f9SIra Weiny 	CXL_MBOX_OP_CLEAR_EVENT_RECORD	= 0x0101,
365a49aa814SDavidlohr Bueso 	CXL_MBOX_OP_GET_EVT_INT_POLICY	= 0x0102,
366a49aa814SDavidlohr Bueso 	CXL_MBOX_OP_SET_EVT_INT_POLICY	= 0x0103,
3674faf31b4SDan Williams 	CXL_MBOX_OP_GET_FW_INFO		= 0x0200,
3684faf31b4SDan Williams 	CXL_MBOX_OP_ACTIVATE_FW		= 0x0202,
369fa884345SJonathan Cameron 	CXL_MBOX_OP_SET_TIMESTAMP	= 0x0301,
3704faf31b4SDan Williams 	CXL_MBOX_OP_GET_SUPPORTED_LOGS	= 0x0400,
3714faf31b4SDan Williams 	CXL_MBOX_OP_GET_LOG		= 0x0401,
3724faf31b4SDan Williams 	CXL_MBOX_OP_IDENTIFY		= 0x4000,
3734faf31b4SDan Williams 	CXL_MBOX_OP_GET_PARTITION_INFO	= 0x4100,
3744faf31b4SDan Williams 	CXL_MBOX_OP_SET_PARTITION_INFO	= 0x4101,
3754faf31b4SDan Williams 	CXL_MBOX_OP_GET_LSA		= 0x4102,
3764faf31b4SDan Williams 	CXL_MBOX_OP_SET_LSA		= 0x4103,
3774faf31b4SDan Williams 	CXL_MBOX_OP_GET_HEALTH_INFO	= 0x4200,
3784faf31b4SDan Williams 	CXL_MBOX_OP_GET_ALERT_CONFIG	= 0x4201,
3794faf31b4SDan Williams 	CXL_MBOX_OP_SET_ALERT_CONFIG	= 0x4202,
3804faf31b4SDan Williams 	CXL_MBOX_OP_GET_SHUTDOWN_STATE	= 0x4203,
3814faf31b4SDan Williams 	CXL_MBOX_OP_SET_SHUTDOWN_STATE	= 0x4204,
3824faf31b4SDan Williams 	CXL_MBOX_OP_GET_POISON		= 0x4300,
3834faf31b4SDan Williams 	CXL_MBOX_OP_INJECT_POISON	= 0x4301,
3844faf31b4SDan Williams 	CXL_MBOX_OP_CLEAR_POISON	= 0x4302,
3854faf31b4SDan Williams 	CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS	= 0x4303,
3864faf31b4SDan Williams 	CXL_MBOX_OP_SCAN_MEDIA		= 0x4304,
3874faf31b4SDan Williams 	CXL_MBOX_OP_GET_SCAN_MEDIA	= 0x4305,
388*0c36b6adSDavidlohr Bueso 	CXL_MBOX_OP_SANITIZE		= 0x4400,
38932828115SDave Jiang 	CXL_MBOX_OP_GET_SECURITY_STATE	= 0x4500,
39099746940SDave Jiang 	CXL_MBOX_OP_SET_PASSPHRASE	= 0x4501,
391c4ef680dSDave Jiang 	CXL_MBOX_OP_DISABLE_PASSPHRASE	= 0x4502,
3922bb692f7SDave Jiang 	CXL_MBOX_OP_UNLOCK		= 0x4503,
393a072f7b7SDave Jiang 	CXL_MBOX_OP_FREEZE_SECURITY	= 0x4504,
3943b502e88SDave Jiang 	CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE	= 0x4505,
3954faf31b4SDan Williams 	CXL_MBOX_OP_MAX			= 0x10000
3964faf31b4SDan Williams };
3974faf31b4SDan Williams 
39849be6dd8SDan Williams #define DEFINE_CXL_CEL_UUID                                                    \
39949be6dd8SDan Williams 	UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62,     \
40049be6dd8SDan Williams 		  0x3b, 0x3f, 0x17)
40149be6dd8SDan Williams 
40249be6dd8SDan Williams #define DEFINE_CXL_VENDOR_DEBUG_UUID                                           \
40349be6dd8SDan Williams 	UUID_INIT(0xe1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19,     \
40449be6dd8SDan Williams 		  0x40, 0x3d, 0x86)
40549be6dd8SDan Williams 
40649be6dd8SDan Williams struct cxl_mbox_get_supported_logs {
40749be6dd8SDan Williams 	__le16 entries;
40849be6dd8SDan Williams 	u8 rsvd[6];
40949be6dd8SDan Williams 	struct cxl_gsl_entry {
41049be6dd8SDan Williams 		uuid_t uuid;
41149be6dd8SDan Williams 		__le32 size;
41249be6dd8SDan Williams 	} __packed entry[];
41349be6dd8SDan Williams }  __packed;
41449be6dd8SDan Williams 
41549be6dd8SDan Williams struct cxl_cel_entry {
41649be6dd8SDan Williams 	__le16 opcode;
41749be6dd8SDan Williams 	__le16 effect;
41849be6dd8SDan Williams } __packed;
41949be6dd8SDan Williams 
42049be6dd8SDan Williams struct cxl_mbox_get_log {
42149be6dd8SDan Williams 	uuid_t uuid;
42249be6dd8SDan Williams 	__le32 offset;
42349be6dd8SDan Williams 	__le32 length;
42449be6dd8SDan Williams } __packed;
42549be6dd8SDan Williams 
42649be6dd8SDan Williams /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
42749be6dd8SDan Williams struct cxl_mbox_identify {
42849be6dd8SDan Williams 	char fw_revision[0x10];
42949be6dd8SDan Williams 	__le64 total_capacity;
43049be6dd8SDan Williams 	__le64 volatile_capacity;
43149be6dd8SDan Williams 	__le64 persistent_capacity;
43249be6dd8SDan Williams 	__le64 partition_align;
43349be6dd8SDan Williams 	__le16 info_event_log_size;
43449be6dd8SDan Williams 	__le16 warning_event_log_size;
43549be6dd8SDan Williams 	__le16 failure_event_log_size;
43649be6dd8SDan Williams 	__le16 fatal_event_log_size;
43749be6dd8SDan Williams 	__le32 lsa_size;
43849be6dd8SDan Williams 	u8 poison_list_max_mer[3];
43949be6dd8SDan Williams 	__le16 inject_poison_limit;
44049be6dd8SDan Williams 	u8 poison_caps;
44149be6dd8SDan Williams 	u8 qos_telemetry_caps;
44249be6dd8SDan Williams } __packed;
44349be6dd8SDan Williams 
4446ebe28f9SIra Weiny /*
4456ebe28f9SIra Weiny  * Common Event Record Format
4466ebe28f9SIra Weiny  * CXL rev 3.0 section 8.2.9.2.1; Table 8-42
4476ebe28f9SIra Weiny  */
4486ebe28f9SIra Weiny struct cxl_event_record_hdr {
4496ebe28f9SIra Weiny 	uuid_t id;
4506ebe28f9SIra Weiny 	u8 length;
4516ebe28f9SIra Weiny 	u8 flags[3];
4526ebe28f9SIra Weiny 	__le16 handle;
4536ebe28f9SIra Weiny 	__le16 related_handle;
4546ebe28f9SIra Weiny 	__le64 timestamp;
4556ebe28f9SIra Weiny 	u8 maint_op_class;
4566ebe28f9SIra Weiny 	u8 reserved[15];
4576ebe28f9SIra Weiny } __packed;
4586ebe28f9SIra Weiny 
4596ebe28f9SIra Weiny #define CXL_EVENT_RECORD_DATA_LENGTH 0x50
4606ebe28f9SIra Weiny struct cxl_event_record_raw {
4616ebe28f9SIra Weiny 	struct cxl_event_record_hdr hdr;
4626ebe28f9SIra Weiny 	u8 data[CXL_EVENT_RECORD_DATA_LENGTH];
4636ebe28f9SIra Weiny } __packed;
4646ebe28f9SIra Weiny 
4656ebe28f9SIra Weiny /*
4666ebe28f9SIra Weiny  * Get Event Records output payload
4676ebe28f9SIra Weiny  * CXL rev 3.0 section 8.2.9.2.2; Table 8-50
4686ebe28f9SIra Weiny  */
4696ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_OVERFLOW		BIT(0)
4706ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_MORE_RECORDS		BIT(1)
4716ebe28f9SIra Weiny struct cxl_get_event_payload {
4726ebe28f9SIra Weiny 	u8 flags;
4736ebe28f9SIra Weiny 	u8 reserved1;
4746ebe28f9SIra Weiny 	__le16 overflow_err_count;
4756ebe28f9SIra Weiny 	__le64 first_overflow_timestamp;
4766ebe28f9SIra Weiny 	__le64 last_overflow_timestamp;
4776ebe28f9SIra Weiny 	__le16 record_count;
4786ebe28f9SIra Weiny 	u8 reserved2[10];
4796ebe28f9SIra Weiny 	struct cxl_event_record_raw records[];
4806ebe28f9SIra Weiny } __packed;
4816ebe28f9SIra Weiny 
4826ebe28f9SIra Weiny /*
4836ebe28f9SIra Weiny  * CXL rev 3.0 section 8.2.9.2.2; Table 8-49
4846ebe28f9SIra Weiny  */
4856ebe28f9SIra Weiny enum cxl_event_log_type {
4866ebe28f9SIra Weiny 	CXL_EVENT_TYPE_INFO = 0x00,
4876ebe28f9SIra Weiny 	CXL_EVENT_TYPE_WARN,
4886ebe28f9SIra Weiny 	CXL_EVENT_TYPE_FAIL,
4896ebe28f9SIra Weiny 	CXL_EVENT_TYPE_FATAL,
4906ebe28f9SIra Weiny 	CXL_EVENT_TYPE_MAX
4916ebe28f9SIra Weiny };
4926ebe28f9SIra Weiny 
4936ebe28f9SIra Weiny /*
4946ebe28f9SIra Weiny  * Clear Event Records input payload
4956ebe28f9SIra Weiny  * CXL rev 3.0 section 8.2.9.2.3; Table 8-51
4966ebe28f9SIra Weiny  */
4976ebe28f9SIra Weiny struct cxl_mbox_clear_event_payload {
4986ebe28f9SIra Weiny 	u8 event_log;		/* enum cxl_event_log_type */
4996ebe28f9SIra Weiny 	u8 clear_flags;
5006ebe28f9SIra Weiny 	u8 nr_recs;
5016ebe28f9SIra Weiny 	u8 reserved[3];
5026ebe28f9SIra Weiny 	__le16 handles[];
5036ebe28f9SIra Weiny } __packed;
5046ebe28f9SIra Weiny #define CXL_CLEAR_EVENT_MAX_HANDLES U8_MAX
5056ebe28f9SIra Weiny 
506d54a531aSIra Weiny /*
507d54a531aSIra Weiny  * General Media Event Record
508d54a531aSIra Weiny  * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
509d54a531aSIra Weiny  */
510d54a531aSIra Weiny #define CXL_EVENT_GEN_MED_COMP_ID_SIZE	0x10
511d54a531aSIra Weiny struct cxl_event_gen_media {
512d54a531aSIra Weiny 	struct cxl_event_record_hdr hdr;
513d54a531aSIra Weiny 	__le64 phys_addr;
514d54a531aSIra Weiny 	u8 descriptor;
515d54a531aSIra Weiny 	u8 type;
516d54a531aSIra Weiny 	u8 transaction_type;
517d54a531aSIra Weiny 	u8 validity_flags[2];
518d54a531aSIra Weiny 	u8 channel;
519d54a531aSIra Weiny 	u8 rank;
520d54a531aSIra Weiny 	u8 device[3];
521d54a531aSIra Weiny 	u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
522d54a531aSIra Weiny 	u8 reserved[46];
523d54a531aSIra Weiny } __packed;
524d54a531aSIra Weiny 
5252d6c1e6dSIra Weiny /*
5262d6c1e6dSIra Weiny  * DRAM Event Record - DER
5272d6c1e6dSIra Weiny  * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
5282d6c1e6dSIra Weiny  */
5292d6c1e6dSIra Weiny #define CXL_EVENT_DER_CORRECTION_MASK_SIZE	0x20
5302d6c1e6dSIra Weiny struct cxl_event_dram {
5312d6c1e6dSIra Weiny 	struct cxl_event_record_hdr hdr;
5322d6c1e6dSIra Weiny 	__le64 phys_addr;
5332d6c1e6dSIra Weiny 	u8 descriptor;
5342d6c1e6dSIra Weiny 	u8 type;
5352d6c1e6dSIra Weiny 	u8 transaction_type;
5362d6c1e6dSIra Weiny 	u8 validity_flags[2];
5372d6c1e6dSIra Weiny 	u8 channel;
5382d6c1e6dSIra Weiny 	u8 rank;
5392d6c1e6dSIra Weiny 	u8 nibble_mask[3];
5402d6c1e6dSIra Weiny 	u8 bank_group;
5412d6c1e6dSIra Weiny 	u8 bank;
5422d6c1e6dSIra Weiny 	u8 row[3];
5432d6c1e6dSIra Weiny 	u8 column[2];
5442d6c1e6dSIra Weiny 	u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];
5452d6c1e6dSIra Weiny 	u8 reserved[0x17];
5462d6c1e6dSIra Weiny } __packed;
5472d6c1e6dSIra Weiny 
54895b49479SIra Weiny /*
54995b49479SIra Weiny  * Get Health Info Record
55095b49479SIra Weiny  * CXL rev 3.0 section 8.2.9.8.3.1; Table 8-100
55195b49479SIra Weiny  */
55295b49479SIra Weiny struct cxl_get_health_info {
55395b49479SIra Weiny 	u8 health_status;
55495b49479SIra Weiny 	u8 media_status;
55595b49479SIra Weiny 	u8 add_status;
55695b49479SIra Weiny 	u8 life_used;
55795b49479SIra Weiny 	u8 device_temp[2];
55895b49479SIra Weiny 	u8 dirty_shutdown_cnt[4];
55995b49479SIra Weiny 	u8 cor_vol_err_cnt[4];
56095b49479SIra Weiny 	u8 cor_per_err_cnt[4];
56195b49479SIra Weiny } __packed;
56295b49479SIra Weiny 
56395b49479SIra Weiny /*
56495b49479SIra Weiny  * Memory Module Event Record
56595b49479SIra Weiny  * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
56695b49479SIra Weiny  */
56795b49479SIra Weiny struct cxl_event_mem_module {
56895b49479SIra Weiny 	struct cxl_event_record_hdr hdr;
56995b49479SIra Weiny 	u8 event_type;
57095b49479SIra Weiny 	struct cxl_get_health_info info;
57195b49479SIra Weiny 	u8 reserved[0x3d];
57295b49479SIra Weiny } __packed;
57395b49479SIra Weiny 
574e7ad1bf6SDan Williams struct cxl_mbox_get_partition_info {
575e7ad1bf6SDan Williams 	__le64 active_volatile_cap;
576e7ad1bf6SDan Williams 	__le64 active_persistent_cap;
577e7ad1bf6SDan Williams 	__le64 next_volatile_cap;
578e7ad1bf6SDan Williams 	__le64 next_persistent_cap;
579e7ad1bf6SDan Williams } __packed;
580e7ad1bf6SDan Williams 
58149be6dd8SDan Williams struct cxl_mbox_get_lsa {
5828a664875SAlison Schofield 	__le32 offset;
5838a664875SAlison Schofield 	__le32 length;
58449be6dd8SDan Williams } __packed;
58549be6dd8SDan Williams 
58649be6dd8SDan Williams struct cxl_mbox_set_lsa {
5878a664875SAlison Schofield 	__le32 offset;
5888a664875SAlison Schofield 	__le32 reserved;
58949be6dd8SDan Williams 	u8 data[];
59049be6dd8SDan Williams } __packed;
59149be6dd8SDan Williams 
5926179045cSAlison Schofield struct cxl_mbox_set_partition_info {
5936179045cSAlison Schofield 	__le64 volatile_capacity;
5946179045cSAlison Schofield 	u8 flags;
5956179045cSAlison Schofield } __packed;
5966179045cSAlison Schofield 
5976179045cSAlison Schofield #define  CXL_SET_PARTITION_IMMEDIATE_FLAG	BIT(0)
5986179045cSAlison Schofield 
599fa884345SJonathan Cameron /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
600fa884345SJonathan Cameron struct cxl_mbox_set_timestamp_in {
601fa884345SJonathan Cameron 	__le64 timestamp;
602fa884345SJonathan Cameron 
603fa884345SJonathan Cameron } __packed;
604fa884345SJonathan Cameron 
605ed83f7caSAlison Schofield /* Get Poison List  CXL 3.0 Spec 8.2.9.8.4.1 */
606ed83f7caSAlison Schofield struct cxl_mbox_poison_in {
607ed83f7caSAlison Schofield 	__le64 offset;
608ed83f7caSAlison Schofield 	__le64 length;
609ed83f7caSAlison Schofield } __packed;
610ed83f7caSAlison Schofield 
611ed83f7caSAlison Schofield struct cxl_mbox_poison_out {
612ed83f7caSAlison Schofield 	u8 flags;
613ed83f7caSAlison Schofield 	u8 rsvd1;
614ed83f7caSAlison Schofield 	__le64 overflow_ts;
615ed83f7caSAlison Schofield 	__le16 count;
616ed83f7caSAlison Schofield 	u8 rsvd2[20];
617ed83f7caSAlison Schofield 	struct cxl_poison_record {
618ed83f7caSAlison Schofield 		__le64 address;
619ed83f7caSAlison Schofield 		__le32 length;
620ed83f7caSAlison Schofield 		__le32 rsvd;
621ed83f7caSAlison Schofield 	} __packed record[];
622ed83f7caSAlison Schofield } __packed;
623ed83f7caSAlison Schofield 
624ed83f7caSAlison Schofield /*
625ed83f7caSAlison Schofield  * Get Poison List address field encodes the starting
626ed83f7caSAlison Schofield  * address of poison, and the source of the poison.
627ed83f7caSAlison Schofield  */
628ed83f7caSAlison Schofield #define CXL_POISON_START_MASK		GENMASK_ULL(63, 6)
629ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_MASK		GENMASK(2, 0)
630ed83f7caSAlison Schofield 
631ed83f7caSAlison Schofield /* Get Poison List record length is in units of 64 bytes */
632ed83f7caSAlison Schofield #define CXL_POISON_LEN_MULT	64
633ed83f7caSAlison Schofield 
634ed83f7caSAlison Schofield /* Kernel defined maximum for a list of poison errors */
635ed83f7caSAlison Schofield #define CXL_POISON_LIST_MAX	1024
636ed83f7caSAlison Schofield 
637ed83f7caSAlison Schofield /* Get Poison List: Payload out flags */
638ed83f7caSAlison Schofield #define CXL_POISON_FLAG_MORE            BIT(0)
639ed83f7caSAlison Schofield #define CXL_POISON_FLAG_OVERFLOW        BIT(1)
640ed83f7caSAlison Schofield #define CXL_POISON_FLAG_SCANNING        BIT(2)
641ed83f7caSAlison Schofield 
642ed83f7caSAlison Schofield /* Get Poison List: Poison Source */
643ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_UNKNOWN	0
644ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_EXTERNAL	1
645ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INTERNAL	2
646ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INJECTED	3
647ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_VENDOR	7
648ed83f7caSAlison Schofield 
649d2fbc486SAlison Schofield /* Inject & Clear Poison  CXL 3.0 Spec 8.2.9.8.4.2/3 */
650d2fbc486SAlison Schofield struct cxl_mbox_inject_poison {
651d2fbc486SAlison Schofield 	__le64 address;
652d2fbc486SAlison Schofield };
653d2fbc486SAlison Schofield 
6549690b077SAlison Schofield /* Clear Poison  CXL 3.0 Spec 8.2.9.8.4.3 */
6559690b077SAlison Schofield struct cxl_mbox_clear_poison {
6569690b077SAlison Schofield 	__le64 address;
6579690b077SAlison Schofield 	u8 write_data[CXL_POISON_LEN_MULT];
6589690b077SAlison Schofield } __packed;
6599690b077SAlison Schofield 
6604faf31b4SDan Williams /**
6614faf31b4SDan Williams  * struct cxl_mem_command - Driver representation of a memory device command
6624faf31b4SDan Williams  * @info: Command information as it exists for the UAPI
6634faf31b4SDan Williams  * @opcode: The actual bits used for the mailbox protocol
6644faf31b4SDan Williams  * @flags: Set of flags effecting driver behavior.
6654faf31b4SDan Williams  *
6664faf31b4SDan Williams  *  * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag
6674faf31b4SDan Williams  *    will be enabled by the driver regardless of what hardware may have
6684faf31b4SDan Williams  *    advertised.
6694faf31b4SDan Williams  *
6704faf31b4SDan Williams  * The cxl_mem_command is the driver's internal representation of commands that
6714faf31b4SDan Williams  * are supported by the driver. Some of these commands may not be supported by
6724faf31b4SDan Williams  * the hardware. The driver will use @info to validate the fields passed in by
6734faf31b4SDan Williams  * the user then submit the @opcode to the hardware.
6744faf31b4SDan Williams  *
6754faf31b4SDan Williams  * See struct cxl_command_info.
6764faf31b4SDan Williams  */
6774faf31b4SDan Williams struct cxl_mem_command {
6784faf31b4SDan Williams 	struct cxl_command_info info;
6794faf31b4SDan Williams 	enum cxl_opcode opcode;
6804faf31b4SDan Williams 	u32 flags;
6814faf31b4SDan Williams #define CXL_CMD_FLAG_FORCE_ENABLE BIT(0)
6824faf31b4SDan Williams };
6834faf31b4SDan Williams 
68432828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PASS_SET	0x01
68532828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PASS_SET	0x02
68632828115SDave Jiang #define CXL_PMEM_SEC_STATE_LOCKED		0x04
68732828115SDave Jiang #define CXL_PMEM_SEC_STATE_FROZEN		0x08
68832828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PLIMIT		0x10
68932828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PLIMIT	0x20
69032828115SDave Jiang 
69199746940SDave Jiang /* set passphrase input payload */
69299746940SDave Jiang struct cxl_set_pass {
69399746940SDave Jiang 	u8 type;
69499746940SDave Jiang 	u8 reserved[31];
69599746940SDave Jiang 	/* CXL field using NVDIMM define, same length */
69699746940SDave Jiang 	u8 old_pass[NVDIMM_PASSPHRASE_LEN];
69799746940SDave Jiang 	u8 new_pass[NVDIMM_PASSPHRASE_LEN];
69899746940SDave Jiang } __packed;
69999746940SDave Jiang 
700c4ef680dSDave Jiang /* disable passphrase input payload */
701c4ef680dSDave Jiang struct cxl_disable_pass {
702c4ef680dSDave Jiang 	u8 type;
703c4ef680dSDave Jiang 	u8 reserved[31];
704c4ef680dSDave Jiang 	u8 pass[NVDIMM_PASSPHRASE_LEN];
705c4ef680dSDave Jiang } __packed;
706c4ef680dSDave Jiang 
7073b502e88SDave Jiang /* passphrase secure erase payload */
7083b502e88SDave Jiang struct cxl_pass_erase {
7093b502e88SDave Jiang 	u8 type;
7103b502e88SDave Jiang 	u8 reserved[31];
7113b502e88SDave Jiang 	u8 pass[NVDIMM_PASSPHRASE_LEN];
7123b502e88SDave Jiang } __packed;
7133b502e88SDave Jiang 
71499746940SDave Jiang enum {
71599746940SDave Jiang 	CXL_PMEM_SEC_PASS_MASTER = 0,
71699746940SDave Jiang 	CXL_PMEM_SEC_PASS_USER,
71799746940SDave Jiang };
71899746940SDave Jiang 
7195331cdf4SDan Williams int cxl_internal_send_cmd(struct cxl_dev_state *cxlds,
7205331cdf4SDan Williams 			  struct cxl_mbox_cmd *cmd);
7215e2411aeSIra Weiny int cxl_dev_state_identify(struct cxl_dev_state *cxlds);
7222e4ba0ecSDan Williams int cxl_await_media_ready(struct cxl_dev_state *cxlds);
7235e2411aeSIra Weiny int cxl_enumerate_cmds(struct cxl_dev_state *cxlds);
7245e2411aeSIra Weiny int cxl_mem_create_range_info(struct cxl_dev_state *cxlds);
7255e2411aeSIra Weiny struct cxl_dev_state *cxl_dev_state_create(struct device *dev);
7265e2411aeSIra Weiny void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
7275e2411aeSIra Weiny void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds);
7286ebe28f9SIra Weiny void cxl_mem_get_event_records(struct cxl_dev_state *cxlds, u32 status);
729fa884345SJonathan Cameron int cxl_set_timestamp(struct cxl_dev_state *cxlds);
730d0abf578SAlison Schofield int cxl_poison_state_init(struct cxl_dev_state *cxlds);
731ed83f7caSAlison Schofield int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
732ed83f7caSAlison Schofield 		       struct cxl_region *cxlr);
7337ff6ad10SAlison Schofield int cxl_trigger_poison_list(struct cxl_memdev *cxlmd);
734d2fbc486SAlison Schofield int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa);
7359690b077SAlison Schofield int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa);
736fa884345SJonathan Cameron 
7379ea4dcf4SDan Williams #ifdef CONFIG_CXL_SUSPEND
7389ea4dcf4SDan Williams void cxl_mem_active_inc(void);
7399ea4dcf4SDan Williams void cxl_mem_active_dec(void);
7409ea4dcf4SDan Williams #else
7419ea4dcf4SDan Williams static inline void cxl_mem_active_inc(void)
7429ea4dcf4SDan Williams {
7439ea4dcf4SDan Williams }
7449ea4dcf4SDan Williams static inline void cxl_mem_active_dec(void)
7459ea4dcf4SDan Williams {
7469ea4dcf4SDan Williams }
7479ea4dcf4SDan Williams #endif
748d17d0540SDan Williams 
749d17d0540SDan Williams struct cxl_hdm {
750d17d0540SDan Williams 	struct cxl_component_regs regs;
751d17d0540SDan Williams 	unsigned int decoder_count;
752d17d0540SDan Williams 	unsigned int target_count;
753d17d0540SDan Williams 	unsigned int interleave_mask;
754d17d0540SDan Williams 	struct cxl_port *port;
755d17d0540SDan Williams };
756cc2a4878SDan Williams 
757cc2a4878SDan Williams struct seq_file;
758cc2a4878SDan Williams struct dentry *cxl_debugfs_create_dir(const char *dir);
759cc2a4878SDan Williams void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds);
7605161a55cSBen Widawsky #endif /* __CXL_MEM_H__ */
761