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> 926a1a86dSIra Weiny #include <linux/cxl-event.h> 105161a55cSBen Widawsky #include "cxl.h" 115161a55cSBen Widawsky 125161a55cSBen Widawsky /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */ 135161a55cSBen Widawsky #define CXLMDEV_STATUS_OFFSET 0x0 145161a55cSBen Widawsky #define CXLMDEV_DEV_FATAL BIT(0) 155161a55cSBen Widawsky #define CXLMDEV_FW_HALT BIT(1) 165161a55cSBen Widawsky #define CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2) 175161a55cSBen Widawsky #define CXLMDEV_MS_NOT_READY 0 185161a55cSBen Widawsky #define CXLMDEV_MS_READY 1 195161a55cSBen Widawsky #define CXLMDEV_MS_ERROR 2 205161a55cSBen Widawsky #define CXLMDEV_MS_DISABLED 3 215161a55cSBen Widawsky #define CXLMDEV_READY(status) \ 225161a55cSBen Widawsky (FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) == \ 235161a55cSBen Widawsky CXLMDEV_MS_READY) 245161a55cSBen Widawsky #define CXLMDEV_MBOX_IF_READY BIT(4) 255161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5) 265161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_NOT 0 275161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_COLD 1 285161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_WARM 2 295161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_HOT 3 305161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_CXL 4 315161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED(status) \ 325161a55cSBen Widawsky (FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \ 335161a55cSBen Widawsky CXLMDEV_RESET_NEEDED_NOT) 345161a55cSBen Widawsky 355161a55cSBen Widawsky /** 365161a55cSBen Widawsky * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device 375161a55cSBen Widawsky * @dev: driver core device object 385161a55cSBen Widawsky * @cdev: char dev core object for ioctl operations 395e2411aeSIra Weiny * @cxlds: The device state backing this device 408dd2bc0fSBen Widawsky * @detach_work: active memdev lost a port in its ancestry 41f17b558dSDan Williams * @cxl_nvb: coordinate removal of @cxl_nvd if present 42f17b558dSDan Williams * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem 43516b300cSDan Williams * @endpoint: connection to the CXL port topology for this memory device 445161a55cSBen Widawsky * @id: id number of this memdev instance. 452345df54SDan Williams * @depth: endpoint port depth 465161a55cSBen Widawsky */ 475161a55cSBen Widawsky struct cxl_memdev { 485161a55cSBen Widawsky struct device dev; 495161a55cSBen Widawsky struct cdev cdev; 505e2411aeSIra Weiny struct cxl_dev_state *cxlds; 518dd2bc0fSBen Widawsky struct work_struct detach_work; 52f17b558dSDan Williams struct cxl_nvdimm_bridge *cxl_nvb; 53f17b558dSDan Williams struct cxl_nvdimm *cxl_nvd; 54516b300cSDan Williams struct cxl_port *endpoint; 555161a55cSBen Widawsky int id; 562345df54SDan Williams int depth; 575161a55cSBen Widawsky }; 585161a55cSBen Widawsky 593d135db5SBen Widawsky static inline struct cxl_memdev *to_cxl_memdev(struct device *dev) 603d135db5SBen Widawsky { 613d135db5SBen Widawsky return container_of(dev, struct cxl_memdev, dev); 623d135db5SBen Widawsky } 633d135db5SBen Widawsky 649c57cde0SDan Williams static inline struct cxl_port *cxled_to_port(struct cxl_endpoint_decoder *cxled) 659c57cde0SDan Williams { 669c57cde0SDan Williams return to_cxl_port(cxled->cxld.dev.parent); 679c57cde0SDan Williams } 689c57cde0SDan Williams 69384e624bSDan Williams static inline struct cxl_port *cxlrd_to_port(struct cxl_root_decoder *cxlrd) 70384e624bSDan Williams { 71384e624bSDan Williams return to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); 72384e624bSDan Williams } 73384e624bSDan Williams 749c57cde0SDan Williams static inline struct cxl_memdev * 759c57cde0SDan Williams cxled_to_memdev(struct cxl_endpoint_decoder *cxled) 769c57cde0SDan Williams { 779c57cde0SDan Williams struct cxl_port *port = to_cxl_port(cxled->cxld.dev.parent); 789c57cde0SDan Williams 797481653dSDan Williams return to_cxl_memdev(port->uport_dev); 809c57cde0SDan Williams } 819c57cde0SDan Williams 822a81ada3SGreg Kroah-Hartman bool is_cxl_memdev(const struct device *dev); 838dd2bc0fSBen Widawsky static inline bool is_cxl_endpoint(struct cxl_port *port) 848dd2bc0fSBen Widawsky { 857481653dSDan Williams return is_cxl_memdev(port->uport_dev); 868dd2bc0fSBen Widawsky } 878dd2bc0fSBen Widawsky 88f29a824bSDan Williams struct cxl_memdev *devm_cxl_add_memdev(struct device *host, 89f29a824bSDan Williams struct cxl_dev_state *cxlds); 905f2da197SDan Williams int devm_cxl_sanitize_setup_notifier(struct device *host, 915f2da197SDan Williams struct cxl_memdev *cxlmd); 92aeaefabcSDan Williams struct cxl_memdev_state; 93f29a824bSDan Williams int devm_cxl_setup_fw_upload(struct device *host, struct cxl_memdev_state *mds); 943d8f7ccaSDan Williams int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled, 953d8f7ccaSDan Williams resource_size_t base, resource_size_t len, 963d8f7ccaSDan Williams resource_size_t skipped); 973d135db5SBen Widawsky 987592d935SDan Williams static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port, 997592d935SDan Williams struct cxl_memdev *cxlmd) 1007592d935SDan Williams { 1017592d935SDan Williams if (!port) 1027592d935SDan Williams return NULL; 1037592d935SDan Williams 1047592d935SDan Williams return xa_load(&port->endpoints, (unsigned long)&cxlmd->dev); 1057592d935SDan Williams } 1067592d935SDan Williams 1075161a55cSBen Widawsky /** 108b64955a9SDan Williams * struct cxl_mbox_cmd - A command to be submitted to hardware. 109b64955a9SDan Williams * @opcode: (input) The command set and command submitted to hardware. 110b64955a9SDan Williams * @payload_in: (input) Pointer to the input payload. 111b64955a9SDan Williams * @payload_out: (output) Pointer to the output payload. Must be allocated by 112b64955a9SDan Williams * the caller. 113b64955a9SDan Williams * @size_in: (input) Number of bytes to load from @payload_in. 114b64955a9SDan Williams * @size_out: (input) Max number of bytes loaded into @payload_out. 115b64955a9SDan Williams * (output) Number of bytes generated by the device. For fixed size 116b64955a9SDan Williams * outputs commands this is always expected to be deterministic. For 117b64955a9SDan Williams * variable sized output commands, it tells the exact number of bytes 118b64955a9SDan Williams * written. 1192aeaf663SDan Williams * @min_out: (input) internal command output payload size validation 120ccadf131SDavidlohr Bueso * @poll_count: (input) Number of timeouts to attempt. 121ccadf131SDavidlohr Bueso * @poll_interval_ms: (input) Time between mailbox background command polling 122ccadf131SDavidlohr Bueso * interval timeouts. 123b64955a9SDan Williams * @return_code: (output) Error code returned from hardware. 124b64955a9SDan Williams * 125b64955a9SDan Williams * This is the primary mechanism used to send commands to the hardware. 126b64955a9SDan Williams * All the fields except @payload_* correspond exactly to the fields described in 127b64955a9SDan Williams * Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and 128b64955a9SDan Williams * @payload_out are written to, and read from the Command Payload Registers 129b64955a9SDan Williams * defined in CXL 2.0 8.2.8.4.8. 130b64955a9SDan Williams */ 131b64955a9SDan Williams struct cxl_mbox_cmd { 132b64955a9SDan Williams u16 opcode; 133b64955a9SDan Williams void *payload_in; 134b64955a9SDan Williams void *payload_out; 135b64955a9SDan Williams size_t size_in; 136b64955a9SDan Williams size_t size_out; 1372aeaf663SDan Williams size_t min_out; 138ccadf131SDavidlohr Bueso int poll_count; 139ccadf131SDavidlohr Bueso int poll_interval_ms; 140b64955a9SDan Williams u16 return_code; 141b64955a9SDan Williams }; 142b64955a9SDan Williams 143b64955a9SDan Williams /* 144bfe58458SDavidlohr Bueso * Per CXL 3.0 Section 8.2.8.4.5.1 14592fcc1abSDavidlohr Bueso */ 14692fcc1abSDavidlohr Bueso #define CMD_CMD_RC_TABLE \ 14792fcc1abSDavidlohr Bueso C(SUCCESS, 0, NULL), \ 14892fcc1abSDavidlohr Bueso C(BACKGROUND, -ENXIO, "background cmd started successfully"), \ 14992fcc1abSDavidlohr Bueso C(INPUT, -ENXIO, "cmd input was invalid"), \ 15092fcc1abSDavidlohr Bueso C(UNSUPPORTED, -ENXIO, "cmd is not supported"), \ 15192fcc1abSDavidlohr Bueso C(INTERNAL, -ENXIO, "internal device error"), \ 15292fcc1abSDavidlohr Bueso C(RETRY, -ENXIO, "temporary error, retry once"), \ 15392fcc1abSDavidlohr Bueso C(BUSY, -ENXIO, "ongoing background operation"), \ 15492fcc1abSDavidlohr Bueso C(MEDIADISABLED, -ENXIO, "media access is disabled"), \ 15592fcc1abSDavidlohr Bueso C(FWINPROGRESS, -ENXIO, "one FW package can be transferred at a time"), \ 15692fcc1abSDavidlohr Bueso C(FWOOO, -ENXIO, "FW package content was transferred out of order"), \ 15792fcc1abSDavidlohr Bueso C(FWAUTH, -ENXIO, "FW package authentication failed"), \ 15892fcc1abSDavidlohr Bueso C(FWSLOT, -ENXIO, "FW slot is not supported for requested operation"), \ 15992fcc1abSDavidlohr Bueso C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"), \ 16092fcc1abSDavidlohr Bueso C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"), \ 16192fcc1abSDavidlohr Bueso C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"), \ 1627ff6ad10SAlison Schofield C(PADDR, -EFAULT, "physical address specified is invalid"), \ 16392fcc1abSDavidlohr Bueso C(POISONLMT, -ENXIO, "poison injection limit has been reached"), \ 16492fcc1abSDavidlohr Bueso C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"), \ 16592fcc1abSDavidlohr Bueso C(ABORT, -ENXIO, "background cmd was aborted by device"), \ 16692fcc1abSDavidlohr Bueso C(SECURITY, -ENXIO, "not valid in the current security state"), \ 16792fcc1abSDavidlohr Bueso C(PASSPHRASE, -ENXIO, "phrase doesn't match current set passphrase"), \ 16892fcc1abSDavidlohr Bueso C(MBUNSUPPORTED, -ENXIO, "unsupported on the mailbox it was issued on"),\ 169bfe58458SDavidlohr Bueso C(PAYLOADLEN, -ENXIO, "invalid payload length"), \ 170bfe58458SDavidlohr Bueso C(LOG, -ENXIO, "invalid or unsupported log page"), \ 171bfe58458SDavidlohr Bueso C(INTERRUPTED, -ENXIO, "asynchronous event occured"), \ 172bfe58458SDavidlohr Bueso C(FEATUREVERSION, -ENXIO, "unsupported feature version"), \ 173bfe58458SDavidlohr Bueso C(FEATURESELVALUE, -ENXIO, "unsupported feature selection value"), \ 174bfe58458SDavidlohr Bueso C(FEATURETRANSFERIP, -ENXIO, "feature transfer in progress"), \ 175bfe58458SDavidlohr Bueso C(FEATURETRANSFEROOO, -ENXIO, "feature transfer out of order"), \ 176bfe58458SDavidlohr Bueso C(RESOURCEEXHAUSTED, -ENXIO, "resources are exhausted"), \ 177bfe58458SDavidlohr Bueso C(EXTLIST, -ENXIO, "invalid Extent List"), \ 17892fcc1abSDavidlohr Bueso 17992fcc1abSDavidlohr Bueso #undef C 18092fcc1abSDavidlohr Bueso #define C(a, b, c) CXL_MBOX_CMD_RC_##a 18192fcc1abSDavidlohr Bueso enum { CMD_CMD_RC_TABLE }; 18292fcc1abSDavidlohr Bueso #undef C 18392fcc1abSDavidlohr Bueso #define C(a, b, c) { b, c } 18492fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc { 18592fcc1abSDavidlohr Bueso int err; 18692fcc1abSDavidlohr Bueso const char *desc; 18792fcc1abSDavidlohr Bueso }; 18892fcc1abSDavidlohr Bueso 18992fcc1abSDavidlohr Bueso static const 19092fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE }; 19192fcc1abSDavidlohr Bueso #undef C 19292fcc1abSDavidlohr Bueso 19392fcc1abSDavidlohr Bueso static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd) 19492fcc1abSDavidlohr Bueso { 19592fcc1abSDavidlohr Bueso return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc; 19692fcc1abSDavidlohr Bueso } 19792fcc1abSDavidlohr Bueso 19892fcc1abSDavidlohr Bueso static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd) 19992fcc1abSDavidlohr Bueso { 20092fcc1abSDavidlohr Bueso return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err; 20192fcc1abSDavidlohr Bueso } 20292fcc1abSDavidlohr Bueso 20392fcc1abSDavidlohr Bueso /* 204b64955a9SDan Williams * CXL 2.0 - Memory capacity multiplier 205b64955a9SDan Williams * See Section 8.2.9.5 206b64955a9SDan Williams * 207b64955a9SDan Williams * Volatile, Persistent, and Partition capacities are specified to be in 208b64955a9SDan Williams * multiples of 256MB - define a multiplier to convert to/from bytes. 209b64955a9SDan Williams */ 210b64955a9SDan Williams #define CXL_CAPACITY_MULTIPLIER SZ_256M 211b64955a9SDan Williams 212c192e543SDan Williams /* 213a49aa814SDavidlohr Bueso * Event Interrupt Policy 214a49aa814SDavidlohr Bueso * 215a49aa814SDavidlohr Bueso * CXL rev 3.0 section 8.2.9.2.4; Table 8-52 216560f7855SBen Widawsky */ 217a49aa814SDavidlohr Bueso enum cxl_event_int_mode { 218a49aa814SDavidlohr Bueso CXL_INT_NONE = 0x00, 219a49aa814SDavidlohr Bueso CXL_INT_MSI_MSIX = 0x01, 220a49aa814SDavidlohr Bueso CXL_INT_FW = 0x02 221a49aa814SDavidlohr Bueso }; 222a49aa814SDavidlohr Bueso struct cxl_event_interrupt_policy { 223a49aa814SDavidlohr Bueso u8 info_settings; 224a49aa814SDavidlohr Bueso u8 warn_settings; 225a49aa814SDavidlohr Bueso u8 failure_settings; 226a49aa814SDavidlohr Bueso u8 fatal_settings; 227a49aa814SDavidlohr Bueso } __packed; 228a49aa814SDavidlohr Bueso 229a49aa814SDavidlohr Bueso /** 2306ebe28f9SIra Weiny * struct cxl_event_state - Event log driver state 2316ebe28f9SIra Weiny * 232c192e543SDan Williams * @buf: Buffer to receive event data 233c192e543SDan Williams * @log_lock: Serialize event_buf and log use 2346ebe28f9SIra Weiny */ 2356ebe28f9SIra Weiny struct cxl_event_state { 2366ebe28f9SIra Weiny struct cxl_get_event_payload *buf; 2376ebe28f9SIra Weiny struct mutex log_lock; 238560f7855SBen Widawsky }; 239560f7855SBen Widawsky 240d0abf578SAlison Schofield /* Device enabled poison commands */ 241d0abf578SAlison Schofield enum poison_cmd_enabled_bits { 242d0abf578SAlison Schofield CXL_POISON_ENABLED_LIST, 243d0abf578SAlison Schofield CXL_POISON_ENABLED_INJECT, 244d0abf578SAlison Schofield CXL_POISON_ENABLED_CLEAR, 245d0abf578SAlison Schofield CXL_POISON_ENABLED_SCAN_CAPS, 246d0abf578SAlison Schofield CXL_POISON_ENABLED_SCAN_MEDIA, 247d0abf578SAlison Schofield CXL_POISON_ENABLED_SCAN_RESULTS, 248d0abf578SAlison Schofield CXL_POISON_ENABLED_MAX 249d0abf578SAlison Schofield }; 250d0abf578SAlison Schofield 251ad64f595SDavidlohr Bueso /* Device enabled security commands */ 252ad64f595SDavidlohr Bueso enum security_cmd_enabled_bits { 253ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_SANITIZE, 254ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_SECURE_ERASE, 255ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_GET_SECURITY_STATE, 256ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_SET_PASSPHRASE, 257ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_DISABLE_PASSPHRASE, 258ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_UNLOCK, 259ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_FREEZE_SECURITY, 260ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_PASSPHRASE_SECURE_ERASE, 261ad64f595SDavidlohr Bueso CXL_SEC_ENABLED_MAX 262ad64f595SDavidlohr Bueso }; 263ad64f595SDavidlohr Bueso 264d0abf578SAlison Schofield /** 265d0abf578SAlison Schofield * struct cxl_poison_state - Driver poison state info 266d0abf578SAlison Schofield * 267d0abf578SAlison Schofield * @max_errors: Maximum media error records held in device cache 268d0abf578SAlison Schofield * @enabled_cmds: All poison commands enabled in the CEL 269d0abf578SAlison Schofield * @list_out: The poison list payload returned by device 270d0abf578SAlison Schofield * @lock: Protect reads of the poison list 271d0abf578SAlison Schofield * 272d0abf578SAlison Schofield * Reads of the poison list are synchronized to ensure that a reader 273d0abf578SAlison Schofield * does not get an incomplete list because their request overlapped 274d0abf578SAlison Schofield * (was interrupted or preceded by) another read request of the same 275d0abf578SAlison Schofield * DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1 276d0abf578SAlison Schofield */ 277d0abf578SAlison Schofield struct cxl_poison_state { 278d0abf578SAlison Schofield u32 max_errors; 279d0abf578SAlison Schofield DECLARE_BITMAP(enabled_cmds, CXL_POISON_ENABLED_MAX); 280d0abf578SAlison Schofield struct cxl_mbox_poison_out *list_out; 281d0abf578SAlison Schofield struct mutex lock; /* Protect reads of poison list */ 282d0abf578SAlison Schofield }; 283d0abf578SAlison Schofield 2849521875bSVishal Verma /* 2859521875bSVishal Verma * Get FW Info 2869521875bSVishal Verma * CXL rev 3.0 section 8.2.9.3.1; Table 8-56 2879521875bSVishal Verma */ 2889521875bSVishal Verma struct cxl_mbox_get_fw_info { 2899521875bSVishal Verma u8 num_slots; 2909521875bSVishal Verma u8 slot_info; 2919521875bSVishal Verma u8 activation_cap; 2929521875bSVishal Verma u8 reserved[13]; 2939521875bSVishal Verma char slot_1_revision[16]; 2949521875bSVishal Verma char slot_2_revision[16]; 2959521875bSVishal Verma char slot_3_revision[16]; 2969521875bSVishal Verma char slot_4_revision[16]; 2979521875bSVishal Verma } __packed; 2989521875bSVishal Verma 2999521875bSVishal Verma #define CXL_FW_INFO_SLOT_INFO_CUR_MASK GENMASK(2, 0) 3009521875bSVishal Verma #define CXL_FW_INFO_SLOT_INFO_NEXT_MASK GENMASK(5, 3) 3019521875bSVishal Verma #define CXL_FW_INFO_SLOT_INFO_NEXT_SHIFT 3 3029521875bSVishal Verma #define CXL_FW_INFO_ACTIVATION_CAP_HAS_LIVE_ACTIVATE BIT(0) 3039521875bSVishal Verma 3049521875bSVishal Verma /* 3059521875bSVishal Verma * Transfer FW Input Payload 3069521875bSVishal Verma * CXL rev 3.0 section 8.2.9.3.2; Table 8-57 3079521875bSVishal Verma */ 3089521875bSVishal Verma struct cxl_mbox_transfer_fw { 3099521875bSVishal Verma u8 action; 3109521875bSVishal Verma u8 slot; 3119521875bSVishal Verma u8 reserved[2]; 3129521875bSVishal Verma __le32 offset; 3139521875bSVishal Verma u8 reserved2[0x78]; 3149521875bSVishal Verma u8 data[]; 3159521875bSVishal Verma } __packed; 3169521875bSVishal Verma 3179521875bSVishal Verma #define CXL_FW_TRANSFER_ACTION_FULL 0x0 3189521875bSVishal Verma #define CXL_FW_TRANSFER_ACTION_INITIATE 0x1 3199521875bSVishal Verma #define CXL_FW_TRANSFER_ACTION_CONTINUE 0x2 3209521875bSVishal Verma #define CXL_FW_TRANSFER_ACTION_END 0x3 3219521875bSVishal Verma #define CXL_FW_TRANSFER_ACTION_ABORT 0x4 3229521875bSVishal Verma 3239521875bSVishal Verma /* 3249521875bSVishal Verma * CXL rev 3.0 section 8.2.9.3.2 mandates 128-byte alignment for FW packages 3259521875bSVishal Verma * and for each part transferred in a Transfer FW command. 3269521875bSVishal Verma */ 3279521875bSVishal Verma #define CXL_FW_TRANSFER_ALIGNMENT 128 3289521875bSVishal Verma 3299521875bSVishal Verma /* 3309521875bSVishal Verma * Activate FW Input Payload 3319521875bSVishal Verma * CXL rev 3.0 section 8.2.9.3.3; Table 8-58 3329521875bSVishal Verma */ 3339521875bSVishal Verma struct cxl_mbox_activate_fw { 3349521875bSVishal Verma u8 action; 3359521875bSVishal Verma u8 slot; 3369521875bSVishal Verma } __packed; 3379521875bSVishal Verma 3389521875bSVishal Verma #define CXL_FW_ACTIVATE_ONLINE 0x0 3399521875bSVishal Verma #define CXL_FW_ACTIVATE_OFFLINE 0x1 3409521875bSVishal Verma 3419521875bSVishal Verma /* FW state bits */ 3429521875bSVishal Verma #define CXL_FW_STATE_BITS 32 34395c6bff7SDan Carpenter #define CXL_FW_CANCEL 0 3449521875bSVishal Verma 3459521875bSVishal Verma /** 3469521875bSVishal Verma * struct cxl_fw_state - Firmware upload / activation state 3479521875bSVishal Verma * 3489521875bSVishal Verma * @state: fw_uploader state bitmask 3499521875bSVishal Verma * @oneshot: whether the fw upload fits in a single transfer 3509521875bSVishal Verma * @num_slots: Number of FW slots available 3519521875bSVishal Verma * @cur_slot: Slot number currently active 3529521875bSVishal Verma * @next_slot: Slot number for the new firmware 3539521875bSVishal Verma */ 3549521875bSVishal Verma struct cxl_fw_state { 3559521875bSVishal Verma DECLARE_BITMAP(state, CXL_FW_STATE_BITS); 3569521875bSVishal Verma bool oneshot; 3579521875bSVishal Verma int num_slots; 3589521875bSVishal Verma int cur_slot; 3599521875bSVishal Verma int next_slot; 3609521875bSVishal Verma }; 3619521875bSVishal Verma 362560f7855SBen Widawsky /** 3639968c9ddSDavidlohr Bueso * struct cxl_security_state - Device security state 3649968c9ddSDavidlohr Bueso * 3659968c9ddSDavidlohr Bueso * @state: state of last security operation 366ad64f595SDavidlohr Bueso * @enabled_cmds: All security commands enabled in the CEL 3670c36b6adSDavidlohr Bueso * @poll_tmo_secs: polling timeout 36833981838SDan Williams * @sanitize_active: sanitize completion pending 3690c36b6adSDavidlohr Bueso * @poll_dwork: polling work item 37048dcdbb1SDavidlohr Bueso * @sanitize_node: sanitation sysfs file to notify 3719968c9ddSDavidlohr Bueso */ 3729968c9ddSDavidlohr Bueso struct cxl_security_state { 3739968c9ddSDavidlohr Bueso unsigned long state; 374ad64f595SDavidlohr Bueso DECLARE_BITMAP(enabled_cmds, CXL_SEC_ENABLED_MAX); 3750c36b6adSDavidlohr Bueso int poll_tmo_secs; 37633981838SDan Williams bool sanitize_active; 3770c36b6adSDavidlohr Bueso struct delayed_work poll_dwork; 37848dcdbb1SDavidlohr Bueso struct kernfs_node *sanitize_node; 3799968c9ddSDavidlohr Bueso }; 3809968c9ddSDavidlohr Bueso 381aeaefabcSDan Williams /* 382f6b8ab32SDan Williams * enum cxl_devtype - delineate type-2 from a generic type-3 device 383f6b8ab32SDan Williams * @CXL_DEVTYPE_DEVMEM - Vendor specific CXL Type-2 device implementing HDM-D or 384f6b8ab32SDan Williams * HDM-DB, no requirement that this device implements a 385f6b8ab32SDan Williams * mailbox, or other memory-device-standard manageability 386f6b8ab32SDan Williams * flows. 387f6b8ab32SDan Williams * @CXL_DEVTYPE_CLASSMEM - Common class definition of a CXL Type-3 device with 388f6b8ab32SDan Williams * HDM-H and class-mandatory memory device registers 389f6b8ab32SDan Williams */ 390f6b8ab32SDan Williams enum cxl_devtype { 391f6b8ab32SDan Williams CXL_DEVTYPE_DEVMEM, 392f6b8ab32SDan Williams CXL_DEVTYPE_CLASSMEM, 393f6b8ab32SDan Williams }; 394f6b8ab32SDan Williams 3959968c9ddSDavidlohr Bueso /** 3965e2411aeSIra Weiny * struct cxl_dev_state - The driver device state 3975e2411aeSIra Weiny * 3985e2411aeSIra Weiny * cxl_dev_state represents the CXL driver/device state. It provides an 3995e2411aeSIra Weiny * interface to mailbox commands as well as some cached data about the device. 4005e2411aeSIra Weiny * Currently only memory devices are represented. 4015e2411aeSIra Weiny * 4025e2411aeSIra Weiny * @dev: The device associated with this CXL state 4032905cb52SDan Williams * @cxlmd: The device representing the CXL.mem capabilities of @dev 4042dd18279SRobert Richter * @reg_map: component and ras register mapping parameters 4055161a55cSBen Widawsky * @regs: Parsed register blocks 40606e279e5SBen Widawsky * @cxl_dvsec: Offset to the PCIe device DVSEC 4070a19bfc8SDan Williams * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) 408e764f122SDave Jiang * @media_ready: Indicate whether the device media is usable 40959f8d151SDan Williams * @dpa_res: Overall DPA resource tree for the device 41059f8d151SDan Williams * @pmem_res: Active Persistent memory capacity configuration 41159f8d151SDan Williams * @ram_res: Active Volatile memory capacity configuration 41259f8d151SDan Williams * @serial: PCIe Device Serial Number 413f6b8ab32SDan Williams * @type: Generic Memory Class device or Vendor Specific Memory device 41459f8d151SDan Williams */ 41559f8d151SDan Williams struct cxl_dev_state { 41659f8d151SDan Williams struct device *dev; 41759f8d151SDan Williams struct cxl_memdev *cxlmd; 4182dd18279SRobert Richter struct cxl_register_map reg_map; 41959f8d151SDan Williams struct cxl_regs regs; 42059f8d151SDan Williams int cxl_dvsec; 42159f8d151SDan Williams bool rcd; 42259f8d151SDan Williams bool media_ready; 42359f8d151SDan Williams struct resource dpa_res; 42459f8d151SDan Williams struct resource pmem_res; 42559f8d151SDan Williams struct resource ram_res; 42659f8d151SDan Williams u64 serial; 427f6b8ab32SDan Williams enum cxl_devtype type; 42859f8d151SDan Williams }; 42959f8d151SDan Williams 43059f8d151SDan Williams /** 43159f8d151SDan Williams * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data 43259f8d151SDan Williams * 43359f8d151SDan Williams * CXL 8.1.12.1 PCI Header - Class Code Register Memory Device defines 43459f8d151SDan Williams * common memory device functionality like the presence of a mailbox and 43559f8d151SDan Williams * the functionality related to that like Identify Memory Device and Get 43659f8d151SDan Williams * Partition Info 43759f8d151SDan Williams * @cxlds: Core driver state common across Type-2 and Type-3 devices 4385161a55cSBen Widawsky * @payload_size: Size of space for payload 4395161a55cSBen Widawsky * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) 4405161a55cSBen Widawsky * @lsa_size: Size of Label Storage Area 4415161a55cSBen Widawsky * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) 4425161a55cSBen Widawsky * @mbox_mutex: Mutex to synchronize mailbox access. 4435161a55cSBen Widawsky * @firmware_version: Firmware version for the memory device. 4445161a55cSBen Widawsky * @enabled_cmds: Hardware commands found enabled in CEL. 44512f3856aSDan Williams * @exclusive_cmds: Commands that are kernel-internal only 44613e7749dSDan Williams * @total_bytes: sum of all possible capacities 44713e7749dSDan Williams * @volatile_only_bytes: hard volatile capacity 44813e7749dSDan Williams * @persistent_only_bytes: hard persistent capacity 44913e7749dSDan Williams * @partition_align_bytes: alignment size for partition-able capacity 45013e7749dSDan Williams * @active_volatile_bytes: sum of hard + soft volatile 45113e7749dSDan Williams * @active_persistent_bytes: sum of hard + soft persistent 45213e7749dSDan Williams * @next_volatile_bytes: volatile capacity change pending device reset 45313e7749dSDan Williams * @next_persistent_bytes: persistent capacity change pending device reset 4541bb31131SAlison Schofield * @event: event log driver state 455d0abf578SAlison Schofield * @poison: poison driver state info 4563de8cd22SDavidlohr Bueso * @security: security driver state info 4579521875bSVishal Verma * @fw: firmware upload / activation state 458b64955a9SDan Williams * @mbox_send: @dev specific transport for transmitting mailbox commands 45913e7749dSDan Williams * 46059f8d151SDan Williams * See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for 46113e7749dSDan Williams * details on capacity parameters. 4625161a55cSBen Widawsky */ 46359f8d151SDan Williams struct cxl_memdev_state { 46459f8d151SDan Williams struct cxl_dev_state cxlds; 4655161a55cSBen Widawsky size_t payload_size; 4665161a55cSBen Widawsky size_t lsa_size; 4675161a55cSBen Widawsky struct mutex mbox_mutex; /* Protects device mailbox and firmware */ 4685161a55cSBen Widawsky char firmware_version[0x10]; 469ff56ab9eSDan Williams DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); 47012f3856aSDan Williams DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX); 4710b9159d0SIra Weiny u64 total_bytes; 4720b9159d0SIra Weiny u64 volatile_only_bytes; 4730b9159d0SIra Weiny u64 persistent_only_bytes; 4740b9159d0SIra Weiny u64 partition_align_bytes; 475f847502aSIra Weiny u64 active_volatile_bytes; 476f847502aSIra Weiny u64 active_persistent_bytes; 477f847502aSIra Weiny u64 next_volatile_bytes; 478f847502aSIra Weiny u64 next_persistent_bytes; 4796ebe28f9SIra Weiny struct cxl_event_state event; 480d0abf578SAlison Schofield struct cxl_poison_state poison; 4819968c9ddSDavidlohr Bueso struct cxl_security_state security; 4829521875bSVishal Verma struct cxl_fw_state fw; 4836ebe28f9SIra Weiny 484ccadf131SDavidlohr Bueso struct rcuwait mbox_wait; 48559f8d151SDan Williams int (*mbox_send)(struct cxl_memdev_state *mds, 48659f8d151SDan Williams struct cxl_mbox_cmd *cmd); 4875161a55cSBen Widawsky }; 4884faf31b4SDan Williams 48959f8d151SDan Williams static inline struct cxl_memdev_state * 49059f8d151SDan Williams to_cxl_memdev_state(struct cxl_dev_state *cxlds) 49159f8d151SDan Williams { 492f6b8ab32SDan Williams if (cxlds->type != CXL_DEVTYPE_CLASSMEM) 493f6b8ab32SDan Williams return NULL; 49459f8d151SDan Williams return container_of(cxlds, struct cxl_memdev_state, cxlds); 49559f8d151SDan Williams } 49659f8d151SDan Williams 4974faf31b4SDan Williams enum cxl_opcode { 4984faf31b4SDan Williams CXL_MBOX_OP_INVALID = 0x0000, 4994faf31b4SDan Williams CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID, 5006ebe28f9SIra Weiny CXL_MBOX_OP_GET_EVENT_RECORD = 0x0100, 5016ebe28f9SIra Weiny CXL_MBOX_OP_CLEAR_EVENT_RECORD = 0x0101, 502a49aa814SDavidlohr Bueso CXL_MBOX_OP_GET_EVT_INT_POLICY = 0x0102, 503a49aa814SDavidlohr Bueso CXL_MBOX_OP_SET_EVT_INT_POLICY = 0x0103, 5044faf31b4SDan Williams CXL_MBOX_OP_GET_FW_INFO = 0x0200, 5059521875bSVishal Verma CXL_MBOX_OP_TRANSFER_FW = 0x0201, 5064faf31b4SDan Williams CXL_MBOX_OP_ACTIVATE_FW = 0x0202, 507fa884345SJonathan Cameron CXL_MBOX_OP_SET_TIMESTAMP = 0x0301, 5084faf31b4SDan Williams CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400, 5094faf31b4SDan Williams CXL_MBOX_OP_GET_LOG = 0x0401, 5104faf31b4SDan Williams CXL_MBOX_OP_IDENTIFY = 0x4000, 5114faf31b4SDan Williams CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, 5124faf31b4SDan Williams CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, 5134faf31b4SDan Williams CXL_MBOX_OP_GET_LSA = 0x4102, 5144faf31b4SDan Williams CXL_MBOX_OP_SET_LSA = 0x4103, 5154faf31b4SDan Williams CXL_MBOX_OP_GET_HEALTH_INFO = 0x4200, 5164faf31b4SDan Williams CXL_MBOX_OP_GET_ALERT_CONFIG = 0x4201, 5174faf31b4SDan Williams CXL_MBOX_OP_SET_ALERT_CONFIG = 0x4202, 5184faf31b4SDan Williams CXL_MBOX_OP_GET_SHUTDOWN_STATE = 0x4203, 5194faf31b4SDan Williams CXL_MBOX_OP_SET_SHUTDOWN_STATE = 0x4204, 5204faf31b4SDan Williams CXL_MBOX_OP_GET_POISON = 0x4300, 5214faf31b4SDan Williams CXL_MBOX_OP_INJECT_POISON = 0x4301, 5224faf31b4SDan Williams CXL_MBOX_OP_CLEAR_POISON = 0x4302, 5234faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303, 5244faf31b4SDan Williams CXL_MBOX_OP_SCAN_MEDIA = 0x4304, 5254faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305, 5260c36b6adSDavidlohr Bueso CXL_MBOX_OP_SANITIZE = 0x4400, 527180ffd33SDavidlohr Bueso CXL_MBOX_OP_SECURE_ERASE = 0x4401, 52832828115SDave Jiang CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500, 52999746940SDave Jiang CXL_MBOX_OP_SET_PASSPHRASE = 0x4501, 530c4ef680dSDave Jiang CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502, 5312bb692f7SDave Jiang CXL_MBOX_OP_UNLOCK = 0x4503, 532a072f7b7SDave Jiang CXL_MBOX_OP_FREEZE_SECURITY = 0x4504, 5333b502e88SDave Jiang CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE = 0x4505, 5344faf31b4SDan Williams CXL_MBOX_OP_MAX = 0x10000 5354faf31b4SDan Williams }; 5364faf31b4SDan Williams 53749be6dd8SDan Williams #define DEFINE_CXL_CEL_UUID \ 53849be6dd8SDan Williams UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62, \ 53949be6dd8SDan Williams 0x3b, 0x3f, 0x17) 54049be6dd8SDan Williams 54149be6dd8SDan Williams #define DEFINE_CXL_VENDOR_DEBUG_UUID \ 54249be6dd8SDan Williams UUID_INIT(0xe1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19, \ 54349be6dd8SDan Williams 0x40, 0x3d, 0x86) 54449be6dd8SDan Williams 54549be6dd8SDan Williams struct cxl_mbox_get_supported_logs { 54649be6dd8SDan Williams __le16 entries; 54749be6dd8SDan Williams u8 rsvd[6]; 54849be6dd8SDan Williams struct cxl_gsl_entry { 54949be6dd8SDan Williams uuid_t uuid; 55049be6dd8SDan Williams __le32 size; 55149be6dd8SDan Williams } __packed entry[]; 55249be6dd8SDan Williams } __packed; 55349be6dd8SDan Williams 55449be6dd8SDan Williams struct cxl_cel_entry { 55549be6dd8SDan Williams __le16 opcode; 55649be6dd8SDan Williams __le16 effect; 55749be6dd8SDan Williams } __packed; 55849be6dd8SDan Williams 55949be6dd8SDan Williams struct cxl_mbox_get_log { 56049be6dd8SDan Williams uuid_t uuid; 56149be6dd8SDan Williams __le32 offset; 56249be6dd8SDan Williams __le32 length; 56349be6dd8SDan Williams } __packed; 56449be6dd8SDan Williams 56549be6dd8SDan Williams /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ 56649be6dd8SDan Williams struct cxl_mbox_identify { 56749be6dd8SDan Williams char fw_revision[0x10]; 56849be6dd8SDan Williams __le64 total_capacity; 56949be6dd8SDan Williams __le64 volatile_capacity; 57049be6dd8SDan Williams __le64 persistent_capacity; 57149be6dd8SDan Williams __le64 partition_align; 57249be6dd8SDan Williams __le16 info_event_log_size; 57349be6dd8SDan Williams __le16 warning_event_log_size; 57449be6dd8SDan Williams __le16 failure_event_log_size; 57549be6dd8SDan Williams __le16 fatal_event_log_size; 57649be6dd8SDan Williams __le32 lsa_size; 57749be6dd8SDan Williams u8 poison_list_max_mer[3]; 57849be6dd8SDan Williams __le16 inject_poison_limit; 57949be6dd8SDan Williams u8 poison_caps; 58049be6dd8SDan Williams u8 qos_telemetry_caps; 58149be6dd8SDan Williams } __packed; 58249be6dd8SDan Williams 5836ebe28f9SIra Weiny /* 5844c115c9cSIra Weiny * General Media Event Record UUID 5854c115c9cSIra Weiny * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43 5864c115c9cSIra Weiny */ 5874c115c9cSIra Weiny #define CXL_EVENT_GEN_MEDIA_UUID \ 5884c115c9cSIra Weiny UUID_INIT(0xfbcd0a77, 0xc260, 0x417f, 0x85, 0xa9, 0x08, 0x8b, 0x16, \ 5894c115c9cSIra Weiny 0x21, 0xeb, 0xa6) 5904c115c9cSIra Weiny 5914c115c9cSIra Weiny /* 5924c115c9cSIra Weiny * DRAM Event Record UUID 5934c115c9cSIra Weiny * CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44 5944c115c9cSIra Weiny */ 5954c115c9cSIra Weiny #define CXL_EVENT_DRAM_UUID \ 5964c115c9cSIra Weiny UUID_INIT(0x601dcbb3, 0x9c06, 0x4eab, 0xb8, 0xaf, 0x4e, 0x9b, 0xfb, \ 5974c115c9cSIra Weiny 0x5c, 0x96, 0x24) 5984c115c9cSIra Weiny 5994c115c9cSIra Weiny /* 6004c115c9cSIra Weiny * Memory Module Event Record UUID 6014c115c9cSIra Weiny * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45 6024c115c9cSIra Weiny */ 6034c115c9cSIra Weiny #define CXL_EVENT_MEM_MODULE_UUID \ 6044c115c9cSIra Weiny UUID_INIT(0xfe927475, 0xdd59, 0x4339, 0xa5, 0x86, 0x79, 0xba, 0xb1, \ 6054c115c9cSIra Weiny 0x13, 0xb7, 0x74) 6064c115c9cSIra Weiny 6074c115c9cSIra Weiny /* 6086ebe28f9SIra Weiny * Get Event Records output payload 6096ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.2; Table 8-50 6106ebe28f9SIra Weiny */ 6116ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_OVERFLOW BIT(0) 6126ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_MORE_RECORDS BIT(1) 6136ebe28f9SIra Weiny struct cxl_get_event_payload { 6146ebe28f9SIra Weiny u8 flags; 6156ebe28f9SIra Weiny u8 reserved1; 6166ebe28f9SIra Weiny __le16 overflow_err_count; 6176ebe28f9SIra Weiny __le64 first_overflow_timestamp; 6186ebe28f9SIra Weiny __le64 last_overflow_timestamp; 6196ebe28f9SIra Weiny __le16 record_count; 6206ebe28f9SIra Weiny u8 reserved2[10]; 6216ebe28f9SIra Weiny struct cxl_event_record_raw records[]; 6226ebe28f9SIra Weiny } __packed; 6236ebe28f9SIra Weiny 6246ebe28f9SIra Weiny /* 6256ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.2; Table 8-49 6266ebe28f9SIra Weiny */ 6276ebe28f9SIra Weiny enum cxl_event_log_type { 6286ebe28f9SIra Weiny CXL_EVENT_TYPE_INFO = 0x00, 6296ebe28f9SIra Weiny CXL_EVENT_TYPE_WARN, 6306ebe28f9SIra Weiny CXL_EVENT_TYPE_FAIL, 6316ebe28f9SIra Weiny CXL_EVENT_TYPE_FATAL, 6326ebe28f9SIra Weiny CXL_EVENT_TYPE_MAX 6336ebe28f9SIra Weiny }; 6346ebe28f9SIra Weiny 6356ebe28f9SIra Weiny /* 6366ebe28f9SIra Weiny * Clear Event Records input payload 6376ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.3; Table 8-51 6386ebe28f9SIra Weiny */ 6396ebe28f9SIra Weiny struct cxl_mbox_clear_event_payload { 6406ebe28f9SIra Weiny u8 event_log; /* enum cxl_event_log_type */ 6416ebe28f9SIra Weiny u8 clear_flags; 6426ebe28f9SIra Weiny u8 nr_recs; 6436ebe28f9SIra Weiny u8 reserved[3]; 6446ebe28f9SIra Weiny __le16 handles[]; 6456ebe28f9SIra Weiny } __packed; 6466ebe28f9SIra Weiny #define CXL_CLEAR_EVENT_MAX_HANDLES U8_MAX 6476ebe28f9SIra Weiny 648e7ad1bf6SDan Williams struct cxl_mbox_get_partition_info { 649e7ad1bf6SDan Williams __le64 active_volatile_cap; 650e7ad1bf6SDan Williams __le64 active_persistent_cap; 651e7ad1bf6SDan Williams __le64 next_volatile_cap; 652e7ad1bf6SDan Williams __le64 next_persistent_cap; 653e7ad1bf6SDan Williams } __packed; 654e7ad1bf6SDan Williams 65549be6dd8SDan Williams struct cxl_mbox_get_lsa { 6568a664875SAlison Schofield __le32 offset; 6578a664875SAlison Schofield __le32 length; 65849be6dd8SDan Williams } __packed; 65949be6dd8SDan Williams 66049be6dd8SDan Williams struct cxl_mbox_set_lsa { 6618a664875SAlison Schofield __le32 offset; 6628a664875SAlison Schofield __le32 reserved; 66349be6dd8SDan Williams u8 data[]; 66449be6dd8SDan Williams } __packed; 66549be6dd8SDan Williams 6666179045cSAlison Schofield struct cxl_mbox_set_partition_info { 6676179045cSAlison Schofield __le64 volatile_capacity; 6686179045cSAlison Schofield u8 flags; 6696179045cSAlison Schofield } __packed; 6706179045cSAlison Schofield 6716179045cSAlison Schofield #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) 6726179045cSAlison Schofield 673fa884345SJonathan Cameron /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ 674fa884345SJonathan Cameron struct cxl_mbox_set_timestamp_in { 675fa884345SJonathan Cameron __le64 timestamp; 676fa884345SJonathan Cameron 677fa884345SJonathan Cameron } __packed; 678fa884345SJonathan Cameron 679ed83f7caSAlison Schofield /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ 680ed83f7caSAlison Schofield struct cxl_mbox_poison_in { 681ed83f7caSAlison Schofield __le64 offset; 682ed83f7caSAlison Schofield __le64 length; 683ed83f7caSAlison Schofield } __packed; 684ed83f7caSAlison Schofield 685ed83f7caSAlison Schofield struct cxl_mbox_poison_out { 686ed83f7caSAlison Schofield u8 flags; 687ed83f7caSAlison Schofield u8 rsvd1; 688ed83f7caSAlison Schofield __le64 overflow_ts; 689ed83f7caSAlison Schofield __le16 count; 690ed83f7caSAlison Schofield u8 rsvd2[20]; 691ed83f7caSAlison Schofield struct cxl_poison_record { 692ed83f7caSAlison Schofield __le64 address; 693ed83f7caSAlison Schofield __le32 length; 694ed83f7caSAlison Schofield __le32 rsvd; 695ed83f7caSAlison Schofield } __packed record[]; 696ed83f7caSAlison Schofield } __packed; 697ed83f7caSAlison Schofield 698ed83f7caSAlison Schofield /* 699ed83f7caSAlison Schofield * Get Poison List address field encodes the starting 700ed83f7caSAlison Schofield * address of poison, and the source of the poison. 701ed83f7caSAlison Schofield */ 702ed83f7caSAlison Schofield #define CXL_POISON_START_MASK GENMASK_ULL(63, 6) 703ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_MASK GENMASK(2, 0) 704ed83f7caSAlison Schofield 705ed83f7caSAlison Schofield /* Get Poison List record length is in units of 64 bytes */ 706ed83f7caSAlison Schofield #define CXL_POISON_LEN_MULT 64 707ed83f7caSAlison Schofield 708ed83f7caSAlison Schofield /* Kernel defined maximum for a list of poison errors */ 709ed83f7caSAlison Schofield #define CXL_POISON_LIST_MAX 1024 710ed83f7caSAlison Schofield 711ed83f7caSAlison Schofield /* Get Poison List: Payload out flags */ 712ed83f7caSAlison Schofield #define CXL_POISON_FLAG_MORE BIT(0) 713ed83f7caSAlison Schofield #define CXL_POISON_FLAG_OVERFLOW BIT(1) 714ed83f7caSAlison Schofield #define CXL_POISON_FLAG_SCANNING BIT(2) 715ed83f7caSAlison Schofield 716ed83f7caSAlison Schofield /* Get Poison List: Poison Source */ 717ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_UNKNOWN 0 718ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_EXTERNAL 1 719ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INTERNAL 2 720ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INJECTED 3 721ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_VENDOR 7 722ed83f7caSAlison Schofield 723d2fbc486SAlison Schofield /* Inject & Clear Poison CXL 3.0 Spec 8.2.9.8.4.2/3 */ 724d2fbc486SAlison Schofield struct cxl_mbox_inject_poison { 725d2fbc486SAlison Schofield __le64 address; 726d2fbc486SAlison Schofield }; 727d2fbc486SAlison Schofield 7289690b077SAlison Schofield /* Clear Poison CXL 3.0 Spec 8.2.9.8.4.3 */ 7299690b077SAlison Schofield struct cxl_mbox_clear_poison { 7309690b077SAlison Schofield __le64 address; 7319690b077SAlison Schofield u8 write_data[CXL_POISON_LEN_MULT]; 7329690b077SAlison Schofield } __packed; 7339690b077SAlison Schofield 7344faf31b4SDan Williams /** 7354faf31b4SDan Williams * struct cxl_mem_command - Driver representation of a memory device command 7364faf31b4SDan Williams * @info: Command information as it exists for the UAPI 7374faf31b4SDan Williams * @opcode: The actual bits used for the mailbox protocol 7384faf31b4SDan Williams * @flags: Set of flags effecting driver behavior. 7394faf31b4SDan Williams * 7404faf31b4SDan Williams * * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag 7414faf31b4SDan Williams * will be enabled by the driver regardless of what hardware may have 7424faf31b4SDan Williams * advertised. 7434faf31b4SDan Williams * 7444faf31b4SDan Williams * The cxl_mem_command is the driver's internal representation of commands that 7454faf31b4SDan Williams * are supported by the driver. Some of these commands may not be supported by 7464faf31b4SDan Williams * the hardware. The driver will use @info to validate the fields passed in by 7474faf31b4SDan Williams * the user then submit the @opcode to the hardware. 7484faf31b4SDan Williams * 7494faf31b4SDan Williams * See struct cxl_command_info. 7504faf31b4SDan Williams */ 7514faf31b4SDan Williams struct cxl_mem_command { 7524faf31b4SDan Williams struct cxl_command_info info; 7534faf31b4SDan Williams enum cxl_opcode opcode; 7544faf31b4SDan Williams u32 flags; 7554faf31b4SDan Williams #define CXL_CMD_FLAG_FORCE_ENABLE BIT(0) 7564faf31b4SDan Williams }; 7574faf31b4SDan Williams 75832828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PASS_SET 0x01 75932828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PASS_SET 0x02 76032828115SDave Jiang #define CXL_PMEM_SEC_STATE_LOCKED 0x04 76132828115SDave Jiang #define CXL_PMEM_SEC_STATE_FROZEN 0x08 76232828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PLIMIT 0x10 76332828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PLIMIT 0x20 76432828115SDave Jiang 76599746940SDave Jiang /* set passphrase input payload */ 76699746940SDave Jiang struct cxl_set_pass { 76799746940SDave Jiang u8 type; 76899746940SDave Jiang u8 reserved[31]; 76999746940SDave Jiang /* CXL field using NVDIMM define, same length */ 77099746940SDave Jiang u8 old_pass[NVDIMM_PASSPHRASE_LEN]; 77199746940SDave Jiang u8 new_pass[NVDIMM_PASSPHRASE_LEN]; 77299746940SDave Jiang } __packed; 77399746940SDave Jiang 774c4ef680dSDave Jiang /* disable passphrase input payload */ 775c4ef680dSDave Jiang struct cxl_disable_pass { 776c4ef680dSDave Jiang u8 type; 777c4ef680dSDave Jiang u8 reserved[31]; 778c4ef680dSDave Jiang u8 pass[NVDIMM_PASSPHRASE_LEN]; 779c4ef680dSDave Jiang } __packed; 780c4ef680dSDave Jiang 7813b502e88SDave Jiang /* passphrase secure erase payload */ 7823b502e88SDave Jiang struct cxl_pass_erase { 7833b502e88SDave Jiang u8 type; 7843b502e88SDave Jiang u8 reserved[31]; 7853b502e88SDave Jiang u8 pass[NVDIMM_PASSPHRASE_LEN]; 7863b502e88SDave Jiang } __packed; 7873b502e88SDave Jiang 78899746940SDave Jiang enum { 78999746940SDave Jiang CXL_PMEM_SEC_PASS_MASTER = 0, 79099746940SDave Jiang CXL_PMEM_SEC_PASS_USER, 79199746940SDave Jiang }; 79299746940SDave Jiang 79359f8d151SDan Williams int cxl_internal_send_cmd(struct cxl_memdev_state *mds, 7945331cdf4SDan Williams struct cxl_mbox_cmd *cmd); 79559f8d151SDan Williams int cxl_dev_state_identify(struct cxl_memdev_state *mds); 7962e4ba0ecSDan Williams int cxl_await_media_ready(struct cxl_dev_state *cxlds); 79759f8d151SDan Williams int cxl_enumerate_cmds(struct cxl_memdev_state *mds); 79859f8d151SDan Williams int cxl_mem_create_range_info(struct cxl_memdev_state *mds); 79959f8d151SDan Williams struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev); 80059f8d151SDan Williams void set_exclusive_cxl_commands(struct cxl_memdev_state *mds, 80159f8d151SDan Williams unsigned long *cmds); 80259f8d151SDan Williams void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, 80359f8d151SDan Williams unsigned long *cmds); 80459f8d151SDan Williams void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status); 805*dc97f634SIra Weiny void cxl_event_trace_record(const struct cxl_memdev *cxlmd, 806*dc97f634SIra Weiny enum cxl_event_log_type type, 807*dc97f634SIra Weiny enum cxl_event_type event_type, 808*dc97f634SIra Weiny const uuid_t *uuid, union cxl_event *evt); 80959f8d151SDan Williams int cxl_set_timestamp(struct cxl_memdev_state *mds); 81059f8d151SDan Williams int cxl_poison_state_init(struct cxl_memdev_state *mds); 811ed83f7caSAlison Schofield int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, 812ed83f7caSAlison Schofield struct cxl_region *cxlr); 8137ff6ad10SAlison Schofield int cxl_trigger_poison_list(struct cxl_memdev *cxlmd); 814d2fbc486SAlison Schofield int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa); 8159690b077SAlison Schofield int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); 816fa884345SJonathan Cameron 8179ea4dcf4SDan Williams #ifdef CONFIG_CXL_SUSPEND 8189ea4dcf4SDan Williams void cxl_mem_active_inc(void); 8199ea4dcf4SDan Williams void cxl_mem_active_dec(void); 8209ea4dcf4SDan Williams #else 8219ea4dcf4SDan Williams static inline void cxl_mem_active_inc(void) 8229ea4dcf4SDan Williams { 8239ea4dcf4SDan Williams } 8249ea4dcf4SDan Williams static inline void cxl_mem_active_dec(void) 8259ea4dcf4SDan Williams { 8269ea4dcf4SDan Williams } 8279ea4dcf4SDan Williams #endif 828d17d0540SDan Williams 82933981838SDan Williams int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd); 83048dcdbb1SDavidlohr Bueso 831d17d0540SDan Williams struct cxl_hdm { 832d17d0540SDan Williams struct cxl_component_regs regs; 833d17d0540SDan Williams unsigned int decoder_count; 834d17d0540SDan Williams unsigned int target_count; 835d17d0540SDan Williams unsigned int interleave_mask; 836d17d0540SDan Williams struct cxl_port *port; 837d17d0540SDan Williams }; 838cc2a4878SDan Williams 839cc2a4878SDan Williams struct seq_file; 840cc2a4878SDan Williams struct dentry *cxl_debugfs_create_dir(const char *dir); 841cc2a4878SDan Williams void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); 8425161a55cSBen Widawsky #endif /* __CXL_MEM_H__ */ 843