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> 75161a55cSBen Widawsky #include "cxl.h" 85161a55cSBen Widawsky 95161a55cSBen Widawsky /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */ 105161a55cSBen Widawsky #define CXLMDEV_STATUS_OFFSET 0x0 115161a55cSBen Widawsky #define CXLMDEV_DEV_FATAL BIT(0) 125161a55cSBen Widawsky #define CXLMDEV_FW_HALT BIT(1) 135161a55cSBen Widawsky #define CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2) 145161a55cSBen Widawsky #define CXLMDEV_MS_NOT_READY 0 155161a55cSBen Widawsky #define CXLMDEV_MS_READY 1 165161a55cSBen Widawsky #define CXLMDEV_MS_ERROR 2 175161a55cSBen Widawsky #define CXLMDEV_MS_DISABLED 3 185161a55cSBen Widawsky #define CXLMDEV_READY(status) \ 195161a55cSBen Widawsky (FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) == \ 205161a55cSBen Widawsky CXLMDEV_MS_READY) 215161a55cSBen Widawsky #define CXLMDEV_MBOX_IF_READY BIT(4) 225161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5) 235161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_NOT 0 245161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_COLD 1 255161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_WARM 2 265161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_HOT 3 275161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED_CXL 4 285161a55cSBen Widawsky #define CXLMDEV_RESET_NEEDED(status) \ 295161a55cSBen Widawsky (FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \ 305161a55cSBen Widawsky CXLMDEV_RESET_NEEDED_NOT) 315161a55cSBen Widawsky 325161a55cSBen Widawsky /** 335161a55cSBen Widawsky * struct cxl_memdev - CXL bus object representing a Type-3 Memory Device 345161a55cSBen Widawsky * @dev: driver core device object 355161a55cSBen Widawsky * @cdev: char dev core object for ioctl operations 365e2411aeSIra Weiny * @cxlds: The device state backing this device 378dd2bc0fSBen Widawsky * @detach_work: active memdev lost a port in its ancestry 385161a55cSBen Widawsky * @id: id number of this memdev instance. 395161a55cSBen Widawsky */ 405161a55cSBen Widawsky struct cxl_memdev { 415161a55cSBen Widawsky struct device dev; 425161a55cSBen Widawsky struct cdev cdev; 435e2411aeSIra Weiny struct cxl_dev_state *cxlds; 448dd2bc0fSBen Widawsky struct work_struct detach_work; 455161a55cSBen Widawsky int id; 465161a55cSBen Widawsky }; 475161a55cSBen Widawsky 483d135db5SBen Widawsky static inline struct cxl_memdev *to_cxl_memdev(struct device *dev) 493d135db5SBen Widawsky { 503d135db5SBen Widawsky return container_of(dev, struct cxl_memdev, dev); 513d135db5SBen Widawsky } 523d135db5SBen Widawsky 539c57cde0SDan Williams static inline struct cxl_port *cxled_to_port(struct cxl_endpoint_decoder *cxled) 549c57cde0SDan Williams { 559c57cde0SDan Williams return to_cxl_port(cxled->cxld.dev.parent); 569c57cde0SDan Williams } 579c57cde0SDan Williams 58384e624bSDan Williams static inline struct cxl_port *cxlrd_to_port(struct cxl_root_decoder *cxlrd) 59384e624bSDan Williams { 60384e624bSDan Williams return to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); 61384e624bSDan Williams } 62384e624bSDan Williams 639c57cde0SDan Williams static inline struct cxl_memdev * 649c57cde0SDan Williams cxled_to_memdev(struct cxl_endpoint_decoder *cxled) 659c57cde0SDan Williams { 669c57cde0SDan Williams struct cxl_port *port = to_cxl_port(cxled->cxld.dev.parent); 679c57cde0SDan Williams 689c57cde0SDan Williams return to_cxl_memdev(port->uport); 699c57cde0SDan Williams } 709c57cde0SDan Williams 718dd2bc0fSBen Widawsky bool is_cxl_memdev(struct device *dev); 728dd2bc0fSBen Widawsky static inline bool is_cxl_endpoint(struct cxl_port *port) 738dd2bc0fSBen Widawsky { 748dd2bc0fSBen Widawsky return is_cxl_memdev(port->uport); 758dd2bc0fSBen Widawsky } 768dd2bc0fSBen Widawsky 775e2411aeSIra Weiny struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds); 783d135db5SBen Widawsky 795161a55cSBen Widawsky /** 80b64955a9SDan Williams * struct cxl_mbox_cmd - A command to be submitted to hardware. 81b64955a9SDan Williams * @opcode: (input) The command set and command submitted to hardware. 82b64955a9SDan Williams * @payload_in: (input) Pointer to the input payload. 83b64955a9SDan Williams * @payload_out: (output) Pointer to the output payload. Must be allocated by 84b64955a9SDan Williams * the caller. 85b64955a9SDan Williams * @size_in: (input) Number of bytes to load from @payload_in. 86b64955a9SDan Williams * @size_out: (input) Max number of bytes loaded into @payload_out. 87b64955a9SDan Williams * (output) Number of bytes generated by the device. For fixed size 88b64955a9SDan Williams * outputs commands this is always expected to be deterministic. For 89b64955a9SDan Williams * variable sized output commands, it tells the exact number of bytes 90b64955a9SDan Williams * written. 91b64955a9SDan Williams * @return_code: (output) Error code returned from hardware. 92b64955a9SDan Williams * 93b64955a9SDan Williams * This is the primary mechanism used to send commands to the hardware. 94b64955a9SDan Williams * All the fields except @payload_* correspond exactly to the fields described in 95b64955a9SDan Williams * Command Register section of the CXL 2.0 8.2.8.4.5. @payload_in and 96b64955a9SDan Williams * @payload_out are written to, and read from the Command Payload Registers 97b64955a9SDan Williams * defined in CXL 2.0 8.2.8.4.8. 98b64955a9SDan Williams */ 99b64955a9SDan Williams struct cxl_mbox_cmd { 100b64955a9SDan Williams u16 opcode; 101b64955a9SDan Williams void *payload_in; 102b64955a9SDan Williams void *payload_out; 103b64955a9SDan Williams size_t size_in; 104b64955a9SDan Williams size_t size_out; 105b64955a9SDan Williams u16 return_code; 106b64955a9SDan Williams }; 107b64955a9SDan Williams 108b64955a9SDan Williams /* 10992fcc1abSDavidlohr Bueso * Per CXL 2.0 Section 8.2.8.4.5.1 11092fcc1abSDavidlohr Bueso */ 11192fcc1abSDavidlohr Bueso #define CMD_CMD_RC_TABLE \ 11292fcc1abSDavidlohr Bueso C(SUCCESS, 0, NULL), \ 11392fcc1abSDavidlohr Bueso C(BACKGROUND, -ENXIO, "background cmd started successfully"), \ 11492fcc1abSDavidlohr Bueso C(INPUT, -ENXIO, "cmd input was invalid"), \ 11592fcc1abSDavidlohr Bueso C(UNSUPPORTED, -ENXIO, "cmd is not supported"), \ 11692fcc1abSDavidlohr Bueso C(INTERNAL, -ENXIO, "internal device error"), \ 11792fcc1abSDavidlohr Bueso C(RETRY, -ENXIO, "temporary error, retry once"), \ 11892fcc1abSDavidlohr Bueso C(BUSY, -ENXIO, "ongoing background operation"), \ 11992fcc1abSDavidlohr Bueso C(MEDIADISABLED, -ENXIO, "media access is disabled"), \ 12092fcc1abSDavidlohr Bueso C(FWINPROGRESS, -ENXIO, "one FW package can be transferred at a time"), \ 12192fcc1abSDavidlohr Bueso C(FWOOO, -ENXIO, "FW package content was transferred out of order"), \ 12292fcc1abSDavidlohr Bueso C(FWAUTH, -ENXIO, "FW package authentication failed"), \ 12392fcc1abSDavidlohr Bueso C(FWSLOT, -ENXIO, "FW slot is not supported for requested operation"), \ 12492fcc1abSDavidlohr Bueso C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"), \ 12592fcc1abSDavidlohr Bueso C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"), \ 12692fcc1abSDavidlohr Bueso C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"), \ 12792fcc1abSDavidlohr Bueso C(PADDR, -ENXIO, "physical address specified is invalid"), \ 12892fcc1abSDavidlohr Bueso C(POISONLMT, -ENXIO, "poison injection limit has been reached"), \ 12992fcc1abSDavidlohr Bueso C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"), \ 13092fcc1abSDavidlohr Bueso C(ABORT, -ENXIO, "background cmd was aborted by device"), \ 13192fcc1abSDavidlohr Bueso C(SECURITY, -ENXIO, "not valid in the current security state"), \ 13292fcc1abSDavidlohr Bueso C(PASSPHRASE, -ENXIO, "phrase doesn't match current set passphrase"), \ 13392fcc1abSDavidlohr Bueso C(MBUNSUPPORTED, -ENXIO, "unsupported on the mailbox it was issued on"),\ 13492fcc1abSDavidlohr Bueso C(PAYLOADLEN, -ENXIO, "invalid payload length") 13592fcc1abSDavidlohr Bueso 13692fcc1abSDavidlohr Bueso #undef C 13792fcc1abSDavidlohr Bueso #define C(a, b, c) CXL_MBOX_CMD_RC_##a 13892fcc1abSDavidlohr Bueso enum { CMD_CMD_RC_TABLE }; 13992fcc1abSDavidlohr Bueso #undef C 14092fcc1abSDavidlohr Bueso #define C(a, b, c) { b, c } 14192fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc { 14292fcc1abSDavidlohr Bueso int err; 14392fcc1abSDavidlohr Bueso const char *desc; 14492fcc1abSDavidlohr Bueso }; 14592fcc1abSDavidlohr Bueso 14692fcc1abSDavidlohr Bueso static const 14792fcc1abSDavidlohr Bueso struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE }; 14892fcc1abSDavidlohr Bueso #undef C 14992fcc1abSDavidlohr Bueso 15092fcc1abSDavidlohr Bueso static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd) 15192fcc1abSDavidlohr Bueso { 15292fcc1abSDavidlohr Bueso return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc; 15392fcc1abSDavidlohr Bueso } 15492fcc1abSDavidlohr Bueso 15592fcc1abSDavidlohr Bueso static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd) 15692fcc1abSDavidlohr Bueso { 15792fcc1abSDavidlohr Bueso return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err; 15892fcc1abSDavidlohr Bueso } 15992fcc1abSDavidlohr Bueso 16092fcc1abSDavidlohr Bueso /* 161b64955a9SDan Williams * CXL 2.0 - Memory capacity multiplier 162b64955a9SDan Williams * See Section 8.2.9.5 163b64955a9SDan Williams * 164b64955a9SDan Williams * Volatile, Persistent, and Partition capacities are specified to be in 165b64955a9SDan Williams * multiples of 256MB - define a multiplier to convert to/from bytes. 166b64955a9SDan Williams */ 167b64955a9SDan Williams #define CXL_CAPACITY_MULTIPLIER SZ_256M 168b64955a9SDan Williams 169b64955a9SDan Williams /** 170560f7855SBen Widawsky * struct cxl_endpoint_dvsec_info - Cached DVSEC info 171560f7855SBen Widawsky * @mem_enabled: cached value of mem_enabled in the DVSEC, PCIE_DEVICE 172560f7855SBen Widawsky * @ranges: Number of active HDM ranges this device uses. 173560f7855SBen Widawsky * @dvsec_range: cached attributes of the ranges in the DVSEC, PCIE_DEVICE 174560f7855SBen Widawsky */ 175560f7855SBen Widawsky struct cxl_endpoint_dvsec_info { 176560f7855SBen Widawsky bool mem_enabled; 177560f7855SBen Widawsky int ranges; 178560f7855SBen Widawsky struct range dvsec_range[2]; 179560f7855SBen Widawsky }; 180560f7855SBen Widawsky 181560f7855SBen Widawsky /** 1825e2411aeSIra Weiny * struct cxl_dev_state - The driver device state 1835e2411aeSIra Weiny * 1845e2411aeSIra Weiny * cxl_dev_state represents the CXL driver/device state. It provides an 1855e2411aeSIra Weiny * interface to mailbox commands as well as some cached data about the device. 1865e2411aeSIra Weiny * Currently only memory devices are represented. 1875e2411aeSIra Weiny * 1885e2411aeSIra Weiny * @dev: The device associated with this CXL state 1895161a55cSBen Widawsky * @regs: Parsed register blocks 19006e279e5SBen Widawsky * @cxl_dvsec: Offset to the PCIe device DVSEC 1915161a55cSBen Widawsky * @payload_size: Size of space for payload 1925161a55cSBen Widawsky * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) 1935161a55cSBen Widawsky * @lsa_size: Size of Label Storage Area 1945161a55cSBen Widawsky * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) 1955161a55cSBen Widawsky * @mbox_mutex: Mutex to synchronize mailbox access. 1965161a55cSBen Widawsky * @firmware_version: Firmware version for the memory device. 1975161a55cSBen Widawsky * @enabled_cmds: Hardware commands found enabled in CEL. 19812f3856aSDan Williams * @exclusive_cmds: Commands that are kernel-internal only 199d3b75029SDan Williams * @dpa_res: Overall DPA resource tree for the device 200d3b75029SDan Williams * @pmem_res: Active Persistent memory capacity configuration 201d3b75029SDan Williams * @ram_res: Active Volatile memory capacity configuration 20213e7749dSDan Williams * @total_bytes: sum of all possible capacities 20313e7749dSDan Williams * @volatile_only_bytes: hard volatile capacity 20413e7749dSDan Williams * @persistent_only_bytes: hard persistent capacity 20513e7749dSDan Williams * @partition_align_bytes: alignment size for partition-able capacity 20613e7749dSDan Williams * @active_volatile_bytes: sum of hard + soft volatile 20713e7749dSDan Williams * @active_persistent_bytes: sum of hard + soft persistent 20813e7749dSDan Williams * @next_volatile_bytes: volatile capacity change pending device reset 20913e7749dSDan Williams * @next_persistent_bytes: persistent capacity change pending device reset 2104112a08dSBen Widawsky * @component_reg_phys: register base of component registers 211560f7855SBen Widawsky * @info: Cached DVSEC information about the device. 212bcc79ea3SDan Williams * @serial: PCIe Device Serial Number 2133eddcc93SIra Weiny * @doe_mbs: PCI DOE mailbox array 214b64955a9SDan Williams * @mbox_send: @dev specific transport for transmitting mailbox commands 21513e7749dSDan Williams * 21613e7749dSDan Williams * See section 8.2.9.5.2 Capacity Configuration and Label Storage for 21713e7749dSDan Williams * details on capacity parameters. 2185161a55cSBen Widawsky */ 2195e2411aeSIra Weiny struct cxl_dev_state { 22099e222a5SDan Williams struct device *dev; 2215161a55cSBen Widawsky 2225161a55cSBen Widawsky struct cxl_regs regs; 22306e279e5SBen Widawsky int cxl_dvsec; 2245161a55cSBen Widawsky 2255161a55cSBen Widawsky size_t payload_size; 2265161a55cSBen Widawsky size_t lsa_size; 2275161a55cSBen Widawsky struct mutex mbox_mutex; /* Protects device mailbox and firmware */ 2285161a55cSBen Widawsky char firmware_version[0x10]; 229ff56ab9eSDan Williams DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); 23012f3856aSDan Williams DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX); 2315161a55cSBen Widawsky 232d3b75029SDan Williams struct resource dpa_res; 233d3b75029SDan Williams struct resource pmem_res; 234d3b75029SDan Williams struct resource ram_res; 2350b9159d0SIra Weiny u64 total_bytes; 2360b9159d0SIra Weiny u64 volatile_only_bytes; 2370b9159d0SIra Weiny u64 persistent_only_bytes; 2380b9159d0SIra Weiny u64 partition_align_bytes; 239f847502aSIra Weiny 240f847502aSIra Weiny u64 active_volatile_bytes; 241f847502aSIra Weiny u64 active_persistent_bytes; 242f847502aSIra Weiny u64 next_volatile_bytes; 243f847502aSIra Weiny u64 next_persistent_bytes; 244b64955a9SDan Williams 2454112a08dSBen Widawsky resource_size_t component_reg_phys; 246bcc79ea3SDan Williams u64 serial; 2474112a08dSBen Widawsky 2483eddcc93SIra Weiny struct xarray doe_mbs; 2493eddcc93SIra Weiny 2505e2411aeSIra Weiny int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd); 2515161a55cSBen Widawsky }; 2524faf31b4SDan Williams 2534faf31b4SDan Williams enum cxl_opcode { 2544faf31b4SDan Williams CXL_MBOX_OP_INVALID = 0x0000, 2554faf31b4SDan Williams CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID, 2564faf31b4SDan Williams CXL_MBOX_OP_GET_FW_INFO = 0x0200, 2574faf31b4SDan Williams CXL_MBOX_OP_ACTIVATE_FW = 0x0202, 2584faf31b4SDan Williams CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400, 2594faf31b4SDan Williams CXL_MBOX_OP_GET_LOG = 0x0401, 2604faf31b4SDan Williams CXL_MBOX_OP_IDENTIFY = 0x4000, 2614faf31b4SDan Williams CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, 2624faf31b4SDan Williams CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, 2634faf31b4SDan Williams CXL_MBOX_OP_GET_LSA = 0x4102, 2644faf31b4SDan Williams CXL_MBOX_OP_SET_LSA = 0x4103, 2654faf31b4SDan Williams CXL_MBOX_OP_GET_HEALTH_INFO = 0x4200, 2664faf31b4SDan Williams CXL_MBOX_OP_GET_ALERT_CONFIG = 0x4201, 2674faf31b4SDan Williams CXL_MBOX_OP_SET_ALERT_CONFIG = 0x4202, 2684faf31b4SDan Williams CXL_MBOX_OP_GET_SHUTDOWN_STATE = 0x4203, 2694faf31b4SDan Williams CXL_MBOX_OP_SET_SHUTDOWN_STATE = 0x4204, 2704faf31b4SDan Williams CXL_MBOX_OP_GET_POISON = 0x4300, 2714faf31b4SDan Williams CXL_MBOX_OP_INJECT_POISON = 0x4301, 2724faf31b4SDan Williams CXL_MBOX_OP_CLEAR_POISON = 0x4302, 2734faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303, 2744faf31b4SDan Williams CXL_MBOX_OP_SCAN_MEDIA = 0x4304, 2754faf31b4SDan Williams CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305, 27632828115SDave Jiang CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500, 27799746940SDave Jiang CXL_MBOX_OP_SET_PASSPHRASE = 0x4501, 278c4ef680dSDave Jiang CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502, 279*a072f7b7SDave Jiang CXL_MBOX_OP_FREEZE_SECURITY = 0x4504, 2804faf31b4SDan Williams CXL_MBOX_OP_MAX = 0x10000 2814faf31b4SDan Williams }; 2824faf31b4SDan Williams 28349be6dd8SDan Williams #define DEFINE_CXL_CEL_UUID \ 28449be6dd8SDan Williams UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62, \ 28549be6dd8SDan Williams 0x3b, 0x3f, 0x17) 28649be6dd8SDan Williams 28749be6dd8SDan Williams #define DEFINE_CXL_VENDOR_DEBUG_UUID \ 28849be6dd8SDan Williams UUID_INIT(0xe1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19, \ 28949be6dd8SDan Williams 0x40, 0x3d, 0x86) 29049be6dd8SDan Williams 29149be6dd8SDan Williams struct cxl_mbox_get_supported_logs { 29249be6dd8SDan Williams __le16 entries; 29349be6dd8SDan Williams u8 rsvd[6]; 29449be6dd8SDan Williams struct cxl_gsl_entry { 29549be6dd8SDan Williams uuid_t uuid; 29649be6dd8SDan Williams __le32 size; 29749be6dd8SDan Williams } __packed entry[]; 29849be6dd8SDan Williams } __packed; 29949be6dd8SDan Williams 30049be6dd8SDan Williams struct cxl_cel_entry { 30149be6dd8SDan Williams __le16 opcode; 30249be6dd8SDan Williams __le16 effect; 30349be6dd8SDan Williams } __packed; 30449be6dd8SDan Williams 30549be6dd8SDan Williams struct cxl_mbox_get_log { 30649be6dd8SDan Williams uuid_t uuid; 30749be6dd8SDan Williams __le32 offset; 30849be6dd8SDan Williams __le32 length; 30949be6dd8SDan Williams } __packed; 31049be6dd8SDan Williams 31149be6dd8SDan Williams /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ 31249be6dd8SDan Williams struct cxl_mbox_identify { 31349be6dd8SDan Williams char fw_revision[0x10]; 31449be6dd8SDan Williams __le64 total_capacity; 31549be6dd8SDan Williams __le64 volatile_capacity; 31649be6dd8SDan Williams __le64 persistent_capacity; 31749be6dd8SDan Williams __le64 partition_align; 31849be6dd8SDan Williams __le16 info_event_log_size; 31949be6dd8SDan Williams __le16 warning_event_log_size; 32049be6dd8SDan Williams __le16 failure_event_log_size; 32149be6dd8SDan Williams __le16 fatal_event_log_size; 32249be6dd8SDan Williams __le32 lsa_size; 32349be6dd8SDan Williams u8 poison_list_max_mer[3]; 32449be6dd8SDan Williams __le16 inject_poison_limit; 32549be6dd8SDan Williams u8 poison_caps; 32649be6dd8SDan Williams u8 qos_telemetry_caps; 32749be6dd8SDan Williams } __packed; 32849be6dd8SDan Williams 329e7ad1bf6SDan Williams struct cxl_mbox_get_partition_info { 330e7ad1bf6SDan Williams __le64 active_volatile_cap; 331e7ad1bf6SDan Williams __le64 active_persistent_cap; 332e7ad1bf6SDan Williams __le64 next_volatile_cap; 333e7ad1bf6SDan Williams __le64 next_persistent_cap; 334e7ad1bf6SDan Williams } __packed; 335e7ad1bf6SDan Williams 33649be6dd8SDan Williams struct cxl_mbox_get_lsa { 3378a664875SAlison Schofield __le32 offset; 3388a664875SAlison Schofield __le32 length; 33949be6dd8SDan Williams } __packed; 34049be6dd8SDan Williams 34149be6dd8SDan Williams struct cxl_mbox_set_lsa { 3428a664875SAlison Schofield __le32 offset; 3438a664875SAlison Schofield __le32 reserved; 34449be6dd8SDan Williams u8 data[]; 34549be6dd8SDan Williams } __packed; 34649be6dd8SDan Williams 3476179045cSAlison Schofield struct cxl_mbox_set_partition_info { 3486179045cSAlison Schofield __le64 volatile_capacity; 3496179045cSAlison Schofield u8 flags; 3506179045cSAlison Schofield } __packed; 3516179045cSAlison Schofield 3526179045cSAlison Schofield #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) 3536179045cSAlison Schofield 3544faf31b4SDan Williams /** 3554faf31b4SDan Williams * struct cxl_mem_command - Driver representation of a memory device command 3564faf31b4SDan Williams * @info: Command information as it exists for the UAPI 3574faf31b4SDan Williams * @opcode: The actual bits used for the mailbox protocol 3584faf31b4SDan Williams * @flags: Set of flags effecting driver behavior. 3594faf31b4SDan Williams * 3604faf31b4SDan Williams * * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag 3614faf31b4SDan Williams * will be enabled by the driver regardless of what hardware may have 3624faf31b4SDan Williams * advertised. 3634faf31b4SDan Williams * 3644faf31b4SDan Williams * The cxl_mem_command is the driver's internal representation of commands that 3654faf31b4SDan Williams * are supported by the driver. Some of these commands may not be supported by 3664faf31b4SDan Williams * the hardware. The driver will use @info to validate the fields passed in by 3674faf31b4SDan Williams * the user then submit the @opcode to the hardware. 3684faf31b4SDan Williams * 3694faf31b4SDan Williams * See struct cxl_command_info. 3704faf31b4SDan Williams */ 3714faf31b4SDan Williams struct cxl_mem_command { 3724faf31b4SDan Williams struct cxl_command_info info; 3734faf31b4SDan Williams enum cxl_opcode opcode; 3744faf31b4SDan Williams u32 flags; 3754faf31b4SDan Williams #define CXL_CMD_FLAG_NONE 0 3764faf31b4SDan Williams #define CXL_CMD_FLAG_FORCE_ENABLE BIT(0) 3774faf31b4SDan Williams }; 3784faf31b4SDan Williams 37932828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PASS_SET 0x01 38032828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PASS_SET 0x02 38132828115SDave Jiang #define CXL_PMEM_SEC_STATE_LOCKED 0x04 38232828115SDave Jiang #define CXL_PMEM_SEC_STATE_FROZEN 0x08 38332828115SDave Jiang #define CXL_PMEM_SEC_STATE_USER_PLIMIT 0x10 38432828115SDave Jiang #define CXL_PMEM_SEC_STATE_MASTER_PLIMIT 0x20 38532828115SDave Jiang 38699746940SDave Jiang /* set passphrase input payload */ 38799746940SDave Jiang struct cxl_set_pass { 38899746940SDave Jiang u8 type; 38999746940SDave Jiang u8 reserved[31]; 39099746940SDave Jiang /* CXL field using NVDIMM define, same length */ 39199746940SDave Jiang u8 old_pass[NVDIMM_PASSPHRASE_LEN]; 39299746940SDave Jiang u8 new_pass[NVDIMM_PASSPHRASE_LEN]; 39399746940SDave Jiang } __packed; 39499746940SDave Jiang 395c4ef680dSDave Jiang /* disable passphrase input payload */ 396c4ef680dSDave Jiang struct cxl_disable_pass { 397c4ef680dSDave Jiang u8 type; 398c4ef680dSDave Jiang u8 reserved[31]; 399c4ef680dSDave Jiang u8 pass[NVDIMM_PASSPHRASE_LEN]; 400c4ef680dSDave Jiang } __packed; 401c4ef680dSDave Jiang 40299746940SDave Jiang enum { 40399746940SDave Jiang CXL_PMEM_SEC_PASS_MASTER = 0, 40499746940SDave Jiang CXL_PMEM_SEC_PASS_USER, 40599746940SDave Jiang }; 40699746940SDave Jiang 4075e2411aeSIra Weiny int cxl_mbox_send_cmd(struct cxl_dev_state *cxlds, u16 opcode, void *in, 4084faf31b4SDan Williams size_t in_size, void *out, size_t out_size); 4095e2411aeSIra Weiny int cxl_dev_state_identify(struct cxl_dev_state *cxlds); 4102e4ba0ecSDan Williams int cxl_await_media_ready(struct cxl_dev_state *cxlds); 4115e2411aeSIra Weiny int cxl_enumerate_cmds(struct cxl_dev_state *cxlds); 4125e2411aeSIra Weiny int cxl_mem_create_range_info(struct cxl_dev_state *cxlds); 4135e2411aeSIra Weiny struct cxl_dev_state *cxl_dev_state_create(struct device *dev); 4145e2411aeSIra Weiny void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds); 4155e2411aeSIra Weiny void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds); 4169ea4dcf4SDan Williams #ifdef CONFIG_CXL_SUSPEND 4179ea4dcf4SDan Williams void cxl_mem_active_inc(void); 4189ea4dcf4SDan Williams void cxl_mem_active_dec(void); 4199ea4dcf4SDan Williams #else 4209ea4dcf4SDan Williams static inline void cxl_mem_active_inc(void) 4219ea4dcf4SDan Williams { 4229ea4dcf4SDan Williams } 4239ea4dcf4SDan Williams static inline void cxl_mem_active_dec(void) 4249ea4dcf4SDan Williams { 4259ea4dcf4SDan Williams } 4269ea4dcf4SDan Williams #endif 427d17d0540SDan Williams 428d17d0540SDan Williams struct cxl_hdm { 429d17d0540SDan Williams struct cxl_component_regs regs; 430d17d0540SDan Williams unsigned int decoder_count; 431d17d0540SDan Williams unsigned int target_count; 432d17d0540SDan Williams unsigned int interleave_mask; 433d17d0540SDan Williams struct cxl_port *port; 434d17d0540SDan Williams }; 435cc2a4878SDan Williams 436cc2a4878SDan Williams struct seq_file; 437cc2a4878SDan Williams struct dentry *cxl_debugfs_create_dir(const char *dir); 438cc2a4878SDan Williams void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds); 4395161a55cSBen Widawsky #endif /* __CXL_MEM_H__ */ 440