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> 9*86557b7eSDave Jiang #include <linux/node.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 /** 396*86557b7eSDave Jiang * struct cxl_dpa_perf - DPA performance property entry 397*86557b7eSDave Jiang * @list - list entry 398*86557b7eSDave Jiang * @dpa_range - range for DPA address 399*86557b7eSDave Jiang * @coord - QoS performance data (i.e. latency, bandwidth) 400*86557b7eSDave Jiang * @qos_class - QoS Class cookies 401*86557b7eSDave Jiang */ 402*86557b7eSDave Jiang struct cxl_dpa_perf { 403*86557b7eSDave Jiang struct list_head list; 404*86557b7eSDave Jiang struct range dpa_range; 405*86557b7eSDave Jiang struct access_coordinate coord; 406*86557b7eSDave Jiang int qos_class; 407*86557b7eSDave Jiang }; 408*86557b7eSDave Jiang 409*86557b7eSDave Jiang /** 4105e2411aeSIra Weiny * struct cxl_dev_state - The driver device state 4115e2411aeSIra Weiny * 4125e2411aeSIra Weiny * cxl_dev_state represents the CXL driver/device state. It provides an 4135e2411aeSIra Weiny * interface to mailbox commands as well as some cached data about the device. 4145e2411aeSIra Weiny * Currently only memory devices are represented. 4155e2411aeSIra Weiny * 4165e2411aeSIra Weiny * @dev: The device associated with this CXL state 4172905cb52SDan Williams * @cxlmd: The device representing the CXL.mem capabilities of @dev 4182dd18279SRobert Richter * @reg_map: component and ras register mapping parameters 4195161a55cSBen Widawsky * @regs: Parsed register blocks 42006e279e5SBen Widawsky * @cxl_dvsec: Offset to the PCIe device DVSEC 4210a19bfc8SDan Williams * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH) 422e764f122SDave Jiang * @media_ready: Indicate whether the device media is usable 42359f8d151SDan Williams * @dpa_res: Overall DPA resource tree for the device 42459f8d151SDan Williams * @pmem_res: Active Persistent memory capacity configuration 42559f8d151SDan Williams * @ram_res: Active Volatile memory capacity configuration 42659f8d151SDan Williams * @serial: PCIe Device Serial Number 427f6b8ab32SDan Williams * @type: Generic Memory Class device or Vendor Specific Memory device 42859f8d151SDan Williams */ 42959f8d151SDan Williams struct cxl_dev_state { 43059f8d151SDan Williams struct device *dev; 43159f8d151SDan Williams struct cxl_memdev *cxlmd; 4322dd18279SRobert Richter struct cxl_register_map reg_map; 43359f8d151SDan Williams struct cxl_regs regs; 43459f8d151SDan Williams int cxl_dvsec; 43559f8d151SDan Williams bool rcd; 43659f8d151SDan Williams bool media_ready; 43759f8d151SDan Williams struct resource dpa_res; 43859f8d151SDan Williams struct resource pmem_res; 43959f8d151SDan Williams struct resource ram_res; 44059f8d151SDan Williams u64 serial; 441f6b8ab32SDan Williams enum cxl_devtype type; 44259f8d151SDan Williams }; 44359f8d151SDan Williams 44459f8d151SDan Williams /** 44559f8d151SDan Williams * struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data 44659f8d151SDan Williams * 44759f8d151SDan Williams * CXL 8.1.12.1 PCI Header - Class Code Register Memory Device defines 44859f8d151SDan Williams * common memory device functionality like the presence of a mailbox and 44959f8d151SDan Williams * the functionality related to that like Identify Memory Device and Get 45059f8d151SDan Williams * Partition Info 45159f8d151SDan Williams * @cxlds: Core driver state common across Type-2 and Type-3 devices 4525161a55cSBen Widawsky * @payload_size: Size of space for payload 4535161a55cSBen Widawsky * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) 4545161a55cSBen Widawsky * @lsa_size: Size of Label Storage Area 4555161a55cSBen Widawsky * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) 4565161a55cSBen Widawsky * @mbox_mutex: Mutex to synchronize mailbox access. 4575161a55cSBen Widawsky * @firmware_version: Firmware version for the memory device. 4585161a55cSBen Widawsky * @enabled_cmds: Hardware commands found enabled in CEL. 45912f3856aSDan Williams * @exclusive_cmds: Commands that are kernel-internal only 46013e7749dSDan Williams * @total_bytes: sum of all possible capacities 46113e7749dSDan Williams * @volatile_only_bytes: hard volatile capacity 46213e7749dSDan Williams * @persistent_only_bytes: hard persistent capacity 46313e7749dSDan Williams * @partition_align_bytes: alignment size for partition-able capacity 46413e7749dSDan Williams * @active_volatile_bytes: sum of hard + soft volatile 46513e7749dSDan Williams * @active_persistent_bytes: sum of hard + soft persistent 46613e7749dSDan Williams * @next_volatile_bytes: volatile capacity change pending device reset 46713e7749dSDan Williams * @next_persistent_bytes: persistent capacity change pending device reset 4681bb31131SAlison Schofield * @event: event log driver state 469d0abf578SAlison Schofield * @poison: poison driver state info 4703de8cd22SDavidlohr Bueso * @security: security driver state info 4719521875bSVishal Verma * @fw: firmware upload / activation state 472b64955a9SDan Williams * @mbox_send: @dev specific transport for transmitting mailbox commands 473*86557b7eSDave Jiang * @ram_perf_list: performance data entries matched to RAM 474*86557b7eSDave Jiang * @pmem_perf_list: performance data entries matched to PMEM 47513e7749dSDan Williams * 47659f8d151SDan Williams * See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for 47713e7749dSDan Williams * details on capacity parameters. 4785161a55cSBen Widawsky */ 47959f8d151SDan Williams struct cxl_memdev_state { 48059f8d151SDan Williams struct cxl_dev_state cxlds; 4815161a55cSBen Widawsky size_t payload_size; 4825161a55cSBen Widawsky size_t lsa_size; 4835161a55cSBen Widawsky struct mutex mbox_mutex; /* Protects device mailbox and firmware */ 4845161a55cSBen Widawsky char firmware_version[0x10]; 485ff56ab9eSDan Williams DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); 48612f3856aSDan Williams DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX); 4870b9159d0SIra Weiny u64 total_bytes; 4880b9159d0SIra Weiny u64 volatile_only_bytes; 4890b9159d0SIra Weiny u64 persistent_only_bytes; 4900b9159d0SIra Weiny u64 partition_align_bytes; 491f847502aSIra Weiny u64 active_volatile_bytes; 492f847502aSIra Weiny u64 active_persistent_bytes; 493f847502aSIra Weiny u64 next_volatile_bytes; 494f847502aSIra Weiny u64 next_persistent_bytes; 495*86557b7eSDave Jiang 496*86557b7eSDave Jiang struct list_head ram_perf_list; 497*86557b7eSDave Jiang struct list_head pmem_perf_list; 498*86557b7eSDave Jiang 4996ebe28f9SIra Weiny struct cxl_event_state event; 500d0abf578SAlison Schofield struct cxl_poison_state poison; 5019968c9ddSDavidlohr Bueso struct cxl_security_state security; 5029521875bSVishal Verma struct cxl_fw_state fw; 5036ebe28f9SIra Weiny 504ccadf131SDavidlohr Bueso struct rcuwait mbox_wait; 50559f8d151SDan Williams int (*mbox_send)(struct cxl_memdev_state *mds, 50659f8d151SDan Williams struct cxl_mbox_cmd *cmd); 5075161a55cSBen Widawsky }; 5084faf31b4SDan Williams 50959f8d151SDan Williams static inline struct cxl_memdev_state * 51059f8d151SDan Williams to_cxl_memdev_state(struct cxl_dev_state *cxlds) 51159f8d151SDan Williams { 512f6b8ab32SDan Williams if (cxlds->type != CXL_DEVTYPE_CLASSMEM) 513f6b8ab32SDan Williams return NULL; 51459f8d151SDan Williams return container_of(cxlds, struct cxl_memdev_state, cxlds); 51559f8d151SDan Williams } 51659f8d151SDan Williams 5174faf31b4SDan Williams enum cxl_opcode { 5184faf31b4SDan Williams CXL_MBOX_OP_INVALID = 0x0000, 5194faf31b4SDan Williams CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID, 5206ebe28f9SIra Weiny CXL_MBOX_OP_GET_EVENT_RECORD = 0x0100, 5216ebe28f9SIra Weiny CXL_MBOX_OP_CLEAR_EVENT_RECORD = 0x0101, 522a49aa814SDavidlohr Bueso CXL_MBOX_OP_GET_EVT_INT_POLICY = 0x0102, 523a49aa814SDavidlohr Bueso CXL_MBOX_OP_SET_EVT_INT_POLICY = 0x0103, 5244faf31b4SDan Williams CXL_MBOX_OP_GET_FW_INFO = 0x0200, 5259521875bSVishal Verma CXL_MBOX_OP_TRANSFER_FW = 0x0201, 5264faf31b4SDan Williams CXL_MBOX_OP_ACTIVATE_FW = 0x0202, 527fa884345SJonathan Cameron CXL_MBOX_OP_SET_TIMESTAMP = 0x0301, 5284faf31b4SDan Williams CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400, 5294faf31b4SDan Williams CXL_MBOX_OP_GET_LOG = 0x0401, 5304faf31b4SDan Williams CXL_MBOX_OP_IDENTIFY = 0x4000, 5314faf31b4SDan Williams CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, 5324faf31b4SDan Williams CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, 5334faf31b4SDan Williams CXL_MBOX_OP_GET_LSA = 0x4102, 5344faf31b4SDan Williams CXL_MBOX_OP_SET_LSA = 0x4103, 5354faf31b4SDan Williams CXL_MBOX_OP_GET_HEALTH_INFO = 0x4200, 5364faf31b4SDan Williams CXL_MBOX_OP_GET_ALERT_CONFIG = 0x4201, 5374faf31b4SDan Williams CXL_MBOX_OP_SET_ALERT_CONFIG = 0x4202, 5384faf31b4SDan Williams CXL_MBOX_OP_GET_SHUTDOWN_STATE = 0x4203, 5394faf31b4SDan Williams CXL_MBOX_OP_SET_SHUTDOWN_STATE = 0x4204, 5404faf31b4SDan Williams CXL_MBOX_OP_GET_POISON = 0x4300, 5414faf31b4SDan Williams CXL_MBOX_OP_INJECT_POISON = 0x4301, 5424faf31b4SDan Williams CXL_MBOX_OP_CLEAR_POISON = 0x4302, 5434faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303, 5444faf31b4SDan Williams CXL_MBOX_OP_SCAN_MEDIA = 0x4304, 5454faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305, 5460c36b6adSDavidlohr Bueso CXL_MBOX_OP_SANITIZE = 0x4400, 547180ffd33SDavidlohr Bueso CXL_MBOX_OP_SECURE_ERASE = 0x4401, 54832828115SDave Jiang CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500, 54999746940SDave Jiang CXL_MBOX_OP_SET_PASSPHRASE = 0x4501, 550c4ef680dSDave Jiang CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502, 5512bb692f7SDave Jiang CXL_MBOX_OP_UNLOCK = 0x4503, 552a072f7b7SDave Jiang CXL_MBOX_OP_FREEZE_SECURITY = 0x4504, 5533b502e88SDave Jiang CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE = 0x4505, 5544faf31b4SDan Williams CXL_MBOX_OP_MAX = 0x10000 5554faf31b4SDan Williams }; 5564faf31b4SDan Williams 55749be6dd8SDan Williams #define DEFINE_CXL_CEL_UUID \ 55849be6dd8SDan Williams UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62, \ 55949be6dd8SDan Williams 0x3b, 0x3f, 0x17) 56049be6dd8SDan Williams 56149be6dd8SDan Williams #define DEFINE_CXL_VENDOR_DEBUG_UUID \ 56249be6dd8SDan Williams UUID_INIT(0xe1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19, \ 56349be6dd8SDan Williams 0x40, 0x3d, 0x86) 56449be6dd8SDan Williams 56549be6dd8SDan Williams struct cxl_mbox_get_supported_logs { 56649be6dd8SDan Williams __le16 entries; 56749be6dd8SDan Williams u8 rsvd[6]; 56849be6dd8SDan Williams struct cxl_gsl_entry { 56949be6dd8SDan Williams uuid_t uuid; 57049be6dd8SDan Williams __le32 size; 57149be6dd8SDan Williams } __packed entry[]; 57249be6dd8SDan Williams } __packed; 57349be6dd8SDan Williams 57449be6dd8SDan Williams struct cxl_cel_entry { 57549be6dd8SDan Williams __le16 opcode; 57649be6dd8SDan Williams __le16 effect; 57749be6dd8SDan Williams } __packed; 57849be6dd8SDan Williams 57949be6dd8SDan Williams struct cxl_mbox_get_log { 58049be6dd8SDan Williams uuid_t uuid; 58149be6dd8SDan Williams __le32 offset; 58249be6dd8SDan Williams __le32 length; 58349be6dd8SDan Williams } __packed; 58449be6dd8SDan Williams 58549be6dd8SDan Williams /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ 58649be6dd8SDan Williams struct cxl_mbox_identify { 58749be6dd8SDan Williams char fw_revision[0x10]; 58849be6dd8SDan Williams __le64 total_capacity; 58949be6dd8SDan Williams __le64 volatile_capacity; 59049be6dd8SDan Williams __le64 persistent_capacity; 59149be6dd8SDan Williams __le64 partition_align; 59249be6dd8SDan Williams __le16 info_event_log_size; 59349be6dd8SDan Williams __le16 warning_event_log_size; 59449be6dd8SDan Williams __le16 failure_event_log_size; 59549be6dd8SDan Williams __le16 fatal_event_log_size; 59649be6dd8SDan Williams __le32 lsa_size; 59749be6dd8SDan Williams u8 poison_list_max_mer[3]; 59849be6dd8SDan Williams __le16 inject_poison_limit; 59949be6dd8SDan Williams u8 poison_caps; 60049be6dd8SDan Williams u8 qos_telemetry_caps; 60149be6dd8SDan Williams } __packed; 60249be6dd8SDan Williams 6036ebe28f9SIra Weiny /* 6046ebe28f9SIra Weiny * Common Event Record Format 6056ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.1; Table 8-42 6066ebe28f9SIra Weiny */ 6076ebe28f9SIra Weiny struct cxl_event_record_hdr { 6086ebe28f9SIra Weiny uuid_t id; 6096ebe28f9SIra Weiny u8 length; 6106ebe28f9SIra Weiny u8 flags[3]; 6116ebe28f9SIra Weiny __le16 handle; 6126ebe28f9SIra Weiny __le16 related_handle; 6136ebe28f9SIra Weiny __le64 timestamp; 6146ebe28f9SIra Weiny u8 maint_op_class; 6156ebe28f9SIra Weiny u8 reserved[15]; 6166ebe28f9SIra Weiny } __packed; 6176ebe28f9SIra Weiny 6186ebe28f9SIra Weiny #define CXL_EVENT_RECORD_DATA_LENGTH 0x50 6196ebe28f9SIra Weiny struct cxl_event_record_raw { 6206ebe28f9SIra Weiny struct cxl_event_record_hdr hdr; 6216ebe28f9SIra Weiny u8 data[CXL_EVENT_RECORD_DATA_LENGTH]; 6226ebe28f9SIra Weiny } __packed; 6236ebe28f9SIra Weiny 6246ebe28f9SIra Weiny /* 6256ebe28f9SIra Weiny * Get Event Records output payload 6266ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.2; Table 8-50 6276ebe28f9SIra Weiny */ 6286ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_OVERFLOW BIT(0) 6296ebe28f9SIra Weiny #define CXL_GET_EVENT_FLAG_MORE_RECORDS BIT(1) 6306ebe28f9SIra Weiny struct cxl_get_event_payload { 6316ebe28f9SIra Weiny u8 flags; 6326ebe28f9SIra Weiny u8 reserved1; 6336ebe28f9SIra Weiny __le16 overflow_err_count; 6346ebe28f9SIra Weiny __le64 first_overflow_timestamp; 6356ebe28f9SIra Weiny __le64 last_overflow_timestamp; 6366ebe28f9SIra Weiny __le16 record_count; 6376ebe28f9SIra Weiny u8 reserved2[10]; 6386ebe28f9SIra Weiny struct cxl_event_record_raw records[]; 6396ebe28f9SIra Weiny } __packed; 6406ebe28f9SIra Weiny 6416ebe28f9SIra Weiny /* 6426ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.2; Table 8-49 6436ebe28f9SIra Weiny */ 6446ebe28f9SIra Weiny enum cxl_event_log_type { 6456ebe28f9SIra Weiny CXL_EVENT_TYPE_INFO = 0x00, 6466ebe28f9SIra Weiny CXL_EVENT_TYPE_WARN, 6476ebe28f9SIra Weiny CXL_EVENT_TYPE_FAIL, 6486ebe28f9SIra Weiny CXL_EVENT_TYPE_FATAL, 6496ebe28f9SIra Weiny CXL_EVENT_TYPE_MAX 6506ebe28f9SIra Weiny }; 6516ebe28f9SIra Weiny 6526ebe28f9SIra Weiny /* 6536ebe28f9SIra Weiny * Clear Event Records input payload 6546ebe28f9SIra Weiny * CXL rev 3.0 section 8.2.9.2.3; Table 8-51 6556ebe28f9SIra Weiny */ 6566ebe28f9SIra Weiny struct cxl_mbox_clear_event_payload { 6576ebe28f9SIra Weiny u8 event_log; /* enum cxl_event_log_type */ 6586ebe28f9SIra Weiny u8 clear_flags; 6596ebe28f9SIra Weiny u8 nr_recs; 6606ebe28f9SIra Weiny u8 reserved[3]; 6616ebe28f9SIra Weiny __le16 handles[]; 6626ebe28f9SIra Weiny } __packed; 6636ebe28f9SIra Weiny #define CXL_CLEAR_EVENT_MAX_HANDLES U8_MAX 6646ebe28f9SIra Weiny 665d54a531aSIra Weiny /* 666d54a531aSIra Weiny * General Media Event Record 667d54a531aSIra Weiny * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43 668d54a531aSIra Weiny */ 669d54a531aSIra Weiny #define CXL_EVENT_GEN_MED_COMP_ID_SIZE 0x10 670d54a531aSIra Weiny struct cxl_event_gen_media { 671d54a531aSIra Weiny struct cxl_event_record_hdr hdr; 672d54a531aSIra Weiny __le64 phys_addr; 673d54a531aSIra Weiny u8 descriptor; 674d54a531aSIra Weiny u8 type; 675d54a531aSIra Weiny u8 transaction_type; 676d54a531aSIra Weiny u8 validity_flags[2]; 677d54a531aSIra Weiny u8 channel; 678d54a531aSIra Weiny u8 rank; 679d54a531aSIra Weiny u8 device[3]; 680d54a531aSIra Weiny u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE]; 681d54a531aSIra Weiny u8 reserved[46]; 682d54a531aSIra Weiny } __packed; 683d54a531aSIra Weiny 6842d6c1e6dSIra Weiny /* 6852d6c1e6dSIra Weiny * DRAM Event Record - DER 6862d6c1e6dSIra Weiny * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44 6872d6c1e6dSIra Weiny */ 6882d6c1e6dSIra Weiny #define CXL_EVENT_DER_CORRECTION_MASK_SIZE 0x20 6892d6c1e6dSIra Weiny struct cxl_event_dram { 6902d6c1e6dSIra Weiny struct cxl_event_record_hdr hdr; 6912d6c1e6dSIra Weiny __le64 phys_addr; 6922d6c1e6dSIra Weiny u8 descriptor; 6932d6c1e6dSIra Weiny u8 type; 6942d6c1e6dSIra Weiny u8 transaction_type; 6952d6c1e6dSIra Weiny u8 validity_flags[2]; 6962d6c1e6dSIra Weiny u8 channel; 6972d6c1e6dSIra Weiny u8 rank; 6982d6c1e6dSIra Weiny u8 nibble_mask[3]; 6992d6c1e6dSIra Weiny u8 bank_group; 7002d6c1e6dSIra Weiny u8 bank; 7012d6c1e6dSIra Weiny u8 row[3]; 7022d6c1e6dSIra Weiny u8 column[2]; 7032d6c1e6dSIra Weiny u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE]; 7042d6c1e6dSIra Weiny u8 reserved[0x17]; 7052d6c1e6dSIra Weiny } __packed; 7062d6c1e6dSIra Weiny 70795b49479SIra Weiny /* 70895b49479SIra Weiny * Get Health Info Record 70995b49479SIra Weiny * CXL rev 3.0 section 8.2.9.8.3.1; Table 8-100 71095b49479SIra Weiny */ 71195b49479SIra Weiny struct cxl_get_health_info { 71295b49479SIra Weiny u8 health_status; 71395b49479SIra Weiny u8 media_status; 71495b49479SIra Weiny u8 add_status; 71595b49479SIra Weiny u8 life_used; 71695b49479SIra Weiny u8 device_temp[2]; 71795b49479SIra Weiny u8 dirty_shutdown_cnt[4]; 71895b49479SIra Weiny u8 cor_vol_err_cnt[4]; 71995b49479SIra Weiny u8 cor_per_err_cnt[4]; 72095b49479SIra Weiny } __packed; 72195b49479SIra Weiny 72295b49479SIra Weiny /* 72395b49479SIra Weiny * Memory Module Event Record 72495b49479SIra Weiny * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45 72595b49479SIra Weiny */ 72695b49479SIra Weiny struct cxl_event_mem_module { 72795b49479SIra Weiny struct cxl_event_record_hdr hdr; 72895b49479SIra Weiny u8 event_type; 72995b49479SIra Weiny struct cxl_get_health_info info; 73095b49479SIra Weiny u8 reserved[0x3d]; 73195b49479SIra Weiny } __packed; 73295b49479SIra Weiny 733e7ad1bf6SDan Williams struct cxl_mbox_get_partition_info { 734e7ad1bf6SDan Williams __le64 active_volatile_cap; 735e7ad1bf6SDan Williams __le64 active_persistent_cap; 736e7ad1bf6SDan Williams __le64 next_volatile_cap; 737e7ad1bf6SDan Williams __le64 next_persistent_cap; 738e7ad1bf6SDan Williams } __packed; 739e7ad1bf6SDan Williams 74049be6dd8SDan Williams struct cxl_mbox_get_lsa { 7418a664875SAlison Schofield __le32 offset; 7428a664875SAlison Schofield __le32 length; 74349be6dd8SDan Williams } __packed; 74449be6dd8SDan Williams 74549be6dd8SDan Williams struct cxl_mbox_set_lsa { 7468a664875SAlison Schofield __le32 offset; 7478a664875SAlison Schofield __le32 reserved; 74849be6dd8SDan Williams u8 data[]; 74949be6dd8SDan Williams } __packed; 75049be6dd8SDan Williams 7516179045cSAlison Schofield struct cxl_mbox_set_partition_info { 7526179045cSAlison Schofield __le64 volatile_capacity; 7536179045cSAlison Schofield u8 flags; 7546179045cSAlison Schofield } __packed; 7556179045cSAlison Schofield 7566179045cSAlison Schofield #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) 7576179045cSAlison Schofield 758fa884345SJonathan Cameron /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */ 759fa884345SJonathan Cameron struct cxl_mbox_set_timestamp_in { 760fa884345SJonathan Cameron __le64 timestamp; 761fa884345SJonathan Cameron 762fa884345SJonathan Cameron } __packed; 763fa884345SJonathan Cameron 764ed83f7caSAlison Schofield /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ 765ed83f7caSAlison Schofield struct cxl_mbox_poison_in { 766ed83f7caSAlison Schofield __le64 offset; 767ed83f7caSAlison Schofield __le64 length; 768ed83f7caSAlison Schofield } __packed; 769ed83f7caSAlison Schofield 770ed83f7caSAlison Schofield struct cxl_mbox_poison_out { 771ed83f7caSAlison Schofield u8 flags; 772ed83f7caSAlison Schofield u8 rsvd1; 773ed83f7caSAlison Schofield __le64 overflow_ts; 774ed83f7caSAlison Schofield __le16 count; 775ed83f7caSAlison Schofield u8 rsvd2[20]; 776ed83f7caSAlison Schofield struct cxl_poison_record { 777ed83f7caSAlison Schofield __le64 address; 778ed83f7caSAlison Schofield __le32 length; 779ed83f7caSAlison Schofield __le32 rsvd; 780ed83f7caSAlison Schofield } __packed record[]; 781ed83f7caSAlison Schofield } __packed; 782ed83f7caSAlison Schofield 783ed83f7caSAlison Schofield /* 784ed83f7caSAlison Schofield * Get Poison List address field encodes the starting 785ed83f7caSAlison Schofield * address of poison, and the source of the poison. 786ed83f7caSAlison Schofield */ 787ed83f7caSAlison Schofield #define CXL_POISON_START_MASK GENMASK_ULL(63, 6) 788ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_MASK GENMASK(2, 0) 789ed83f7caSAlison Schofield 790ed83f7caSAlison Schofield /* Get Poison List record length is in units of 64 bytes */ 791ed83f7caSAlison Schofield #define CXL_POISON_LEN_MULT 64 792ed83f7caSAlison Schofield 793ed83f7caSAlison Schofield /* Kernel defined maximum for a list of poison errors */ 794ed83f7caSAlison Schofield #define CXL_POISON_LIST_MAX 1024 795ed83f7caSAlison Schofield 796ed83f7caSAlison Schofield /* Get Poison List: Payload out flags */ 797ed83f7caSAlison Schofield #define CXL_POISON_FLAG_MORE BIT(0) 798ed83f7caSAlison Schofield #define CXL_POISON_FLAG_OVERFLOW BIT(1) 799ed83f7caSAlison Schofield #define CXL_POISON_FLAG_SCANNING BIT(2) 800ed83f7caSAlison Schofield 801ed83f7caSAlison Schofield /* Get Poison List: Poison Source */ 802ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_UNKNOWN 0 803ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_EXTERNAL 1 804ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INTERNAL 2 805ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_INJECTED 3 806ed83f7caSAlison Schofield #define CXL_POISON_SOURCE_VENDOR 7 807ed83f7caSAlison Schofield 808d2fbc486SAlison Schofield /* Inject & Clear Poison CXL 3.0 Spec 8.2.9.8.4.2/3 */ 809d2fbc486SAlison Schofield struct cxl_mbox_inject_poison { 810d2fbc486SAlison Schofield __le64 address; 811d2fbc486SAlison Schofield }; 812d2fbc486SAlison Schofield 8139690b077SAlison Schofield /* Clear Poison CXL 3.0 Spec 8.2.9.8.4.3 */ 8149690b077SAlison Schofield struct cxl_mbox_clear_poison { 8159690b077SAlison Schofield __le64 address; 8169690b077SAlison Schofield u8 write_data[CXL_POISON_LEN_MULT]; 8179690b077SAlison Schofield } __packed; 8189690b077SAlison Schofield 8194faf31b4SDan Williams /** 8204faf31b4SDan Williams * struct cxl_mem_command - Driver representation of a memory device command 8214faf31b4SDan Williams * @info: Command information as it exists for the UAPI 8224faf31b4SDan Williams * @opcode: The actual bits used for the mailbox protocol 8234faf31b4SDan Williams * @flags: Set of flags effecting driver behavior. 8244faf31b4SDan Williams * 8254faf31b4SDan Williams * * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag 8264faf31b4SDan Williams * will be enabled by the driver regardless of what hardware may have 8274faf31b4SDan Williams * advertised. 8284faf31b4SDan Williams * 8294faf31b4SDan Williams * The cxl_mem_command is the driver's internal representation of commands that 8304faf31b4SDan Williams * are supported by the driver. Some of these commands may not be supported by 8314faf31b4SDan Williams * the hardware. The driver will use @info to validate the fields passed in by 8324faf31b4SDan Williams * the user then submit the @opcode to the hardware. 8334faf31b4SDan Williams * 8344faf31b4SDan Williams * See struct cxl_command_info. 8354faf31b4SDan Williams */ 8364faf31b4SDan Williams struct cxl_mem_command { 8374faf31b4SDan Williams struct cxl_command_info info; 8384faf31b4SDan Williams enum cxl_opcode opcode; 8394faf31b4SDan Williams u32 flags; 8404faf31b4SDan Williams #define CXL_CMD_FLAG_FORCE_ENABLE BIT(0) 8414faf31b4SDan Williams }; 8424faf31b4SDan Williams 84332828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PASS_SET 0x01 84432828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PASS_SET 0x02 84532828115SDave Jiang #define CXL_PMEM_SEC_STATE_LOCKED 0x04 84632828115SDave Jiang #define CXL_PMEM_SEC_STATE_FROZEN 0x08 84732828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PLIMIT 0x10 84832828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PLIMIT 0x20 84932828115SDave Jiang 85099746940SDave Jiang /* set passphrase input payload */ 85199746940SDave Jiang struct cxl_set_pass { 85299746940SDave Jiang u8 type; 85399746940SDave Jiang u8 reserved[31]; 85499746940SDave Jiang /* CXL field using NVDIMM define, same length */ 85599746940SDave Jiang u8 old_pass[NVDIMM_PASSPHRASE_LEN]; 85699746940SDave Jiang u8 new_pass[NVDIMM_PASSPHRASE_LEN]; 85799746940SDave Jiang } __packed; 85899746940SDave Jiang 859c4ef680dSDave Jiang /* disable passphrase input payload */ 860c4ef680dSDave Jiang struct cxl_disable_pass { 861c4ef680dSDave Jiang u8 type; 862c4ef680dSDave Jiang u8 reserved[31]; 863c4ef680dSDave Jiang u8 pass[NVDIMM_PASSPHRASE_LEN]; 864c4ef680dSDave Jiang } __packed; 865c4ef680dSDave Jiang 8663b502e88SDave Jiang /* passphrase secure erase payload */ 8673b502e88SDave Jiang struct cxl_pass_erase { 8683b502e88SDave Jiang u8 type; 8693b502e88SDave Jiang u8 reserved[31]; 8703b502e88SDave Jiang u8 pass[NVDIMM_PASSPHRASE_LEN]; 8713b502e88SDave Jiang } __packed; 8723b502e88SDave Jiang 87399746940SDave Jiang enum { 87499746940SDave Jiang CXL_PMEM_SEC_PASS_MASTER = 0, 87599746940SDave Jiang CXL_PMEM_SEC_PASS_USER, 87699746940SDave Jiang }; 87799746940SDave Jiang 87859f8d151SDan Williams int cxl_internal_send_cmd(struct cxl_memdev_state *mds, 8795331cdf4SDan Williams struct cxl_mbox_cmd *cmd); 88059f8d151SDan Williams int cxl_dev_state_identify(struct cxl_memdev_state *mds); 8812e4ba0ecSDan Williams int cxl_await_media_ready(struct cxl_dev_state *cxlds); 88259f8d151SDan Williams int cxl_enumerate_cmds(struct cxl_memdev_state *mds); 88359f8d151SDan Williams int cxl_mem_create_range_info(struct cxl_memdev_state *mds); 88459f8d151SDan Williams struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev); 88559f8d151SDan Williams void set_exclusive_cxl_commands(struct cxl_memdev_state *mds, 88659f8d151SDan Williams unsigned long *cmds); 88759f8d151SDan Williams void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, 88859f8d151SDan Williams unsigned long *cmds); 88959f8d151SDan Williams void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status); 89059f8d151SDan Williams int cxl_set_timestamp(struct cxl_memdev_state *mds); 89159f8d151SDan Williams int cxl_poison_state_init(struct cxl_memdev_state *mds); 892ed83f7caSAlison Schofield int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, 893ed83f7caSAlison Schofield struct cxl_region *cxlr); 8947ff6ad10SAlison Schofield int cxl_trigger_poison_list(struct cxl_memdev *cxlmd); 895d2fbc486SAlison Schofield int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa); 8969690b077SAlison Schofield int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); 897fa884345SJonathan Cameron 8989ea4dcf4SDan Williams #ifdef CONFIG_CXL_SUSPEND 8999ea4dcf4SDan Williams void cxl_mem_active_inc(void); 9009ea4dcf4SDan Williams void cxl_mem_active_dec(void); 9019ea4dcf4SDan Williams #else 9029ea4dcf4SDan Williams static inline void cxl_mem_active_inc(void) 9039ea4dcf4SDan Williams { 9049ea4dcf4SDan Williams } 9059ea4dcf4SDan Williams static inline void cxl_mem_active_dec(void) 9069ea4dcf4SDan Williams { 9079ea4dcf4SDan Williams } 9089ea4dcf4SDan Williams #endif 909d17d0540SDan Williams 91033981838SDan Williams int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd); 91148dcdbb1SDavidlohr Bueso 912d17d0540SDan Williams struct cxl_hdm { 913d17d0540SDan Williams struct cxl_component_regs regs; 914d17d0540SDan Williams unsigned int decoder_count; 915d17d0540SDan Williams unsigned int target_count; 916d17d0540SDan Williams unsigned int interleave_mask; 917d17d0540SDan Williams struct cxl_port *port; 918d17d0540SDan Williams }; 919cc2a4878SDan Williams 920cc2a4878SDan Williams struct seq_file; 921cc2a4878SDan Williams struct dentry *cxl_debugfs_create_dir(const char *dir); 922cc2a4878SDan Williams void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); 9235161a55cSBen Widawsky #endif /* __CXL_MEM_H__ */ 924