2021-05-13 22:21:49 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/* Copyright(c) 2020-2021 Intel Corporation. */
|
|
|
|
#ifndef __CXL_MEM_H__
|
|
|
|
#define __CXL_MEM_H__
|
2021-09-08 22:12:32 -07:00
|
|
|
#include <uapi/linux/cxl_mem.h>
|
2024-09-05 15:35:46 -07:00
|
|
|
#include <linux/pci.h>
|
2021-06-15 16:36:31 -07:00
|
|
|
#include <linux/cdev.h>
|
2023-01-17 21:53:36 -08:00
|
|
|
#include <linux/uuid.h>
|
2023-12-21 15:04:11 -07:00
|
|
|
#include <linux/node.h>
|
2024-09-05 15:35:45 -07:00
|
|
|
#include <cxl/event.h>
|
2024-09-05 15:35:46 -07:00
|
|
|
#include <cxl/mailbox.h>
|
2021-06-15 16:36:31 -07:00
|
|
|
#include "cxl.h"
|
2021-05-13 22:21:49 -07:00
|
|
|
|
|
|
|
/* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
|
|
|
|
#define CXLMDEV_STATUS_OFFSET 0x0
|
|
|
|
#define CXLMDEV_DEV_FATAL BIT(0)
|
|
|
|
#define CXLMDEV_FW_HALT BIT(1)
|
|
|
|
#define CXLMDEV_STATUS_MEDIA_STATUS_MASK GENMASK(3, 2)
|
|
|
|
#define CXLMDEV_MS_NOT_READY 0
|
|
|
|
#define CXLMDEV_MS_READY 1
|
|
|
|
#define CXLMDEV_MS_ERROR 2
|
|
|
|
#define CXLMDEV_MS_DISABLED 3
|
|
|
|
#define CXLMDEV_READY(status) \
|
|
|
|
(FIELD_GET(CXLMDEV_STATUS_MEDIA_STATUS_MASK, status) == \
|
|
|
|
CXLMDEV_MS_READY)
|
|
|
|
#define CXLMDEV_MBOX_IF_READY BIT(4)
|
|
|
|
#define CXLMDEV_RESET_NEEDED_MASK GENMASK(7, 5)
|
|
|
|
#define CXLMDEV_RESET_NEEDED_NOT 0
|
|
|
|
#define CXLMDEV_RESET_NEEDED_COLD 1
|
|
|
|
#define CXLMDEV_RESET_NEEDED_WARM 2
|
|
|
|
#define CXLMDEV_RESET_NEEDED_HOT 3
|
|
|
|
#define CXLMDEV_RESET_NEEDED_CXL 4
|
|
|
|
#define CXLMDEV_RESET_NEEDED(status) \
|
|
|
|
(FIELD_GET(CXLMDEV_RESET_NEEDED_MASK, status) != \
|
|
|
|
CXLMDEV_RESET_NEEDED_NOT)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct cxl_memdev - CXL bus object representing a Type-3 Memory Device
|
|
|
|
* @dev: driver core device object
|
|
|
|
* @cdev: char dev core object for ioctl operations
|
2021-11-02 13:29:01 -07:00
|
|
|
* @cxlds: The device state backing this device
|
2022-02-04 07:18:31 -08:00
|
|
|
* @detach_work: active memdev lost a port in its ancestry
|
cxl/pmem: Refactor nvdimm device registration, delete the workqueue
The three objects 'struct cxl_nvdimm_bridge', 'struct cxl_nvdimm', and
'struct cxl_pmem_region' manage CXL persistent memory resources. The
bridge represents base platform resources, the nvdimm represents one or
more endpoints, and the region is a collection of nvdimms that
contribute to an assembled address range.
Their relationship is such that a region is torn down if any component
endpoints are removed. All regions and endpoints are torn down if the
foundational bridge device goes down.
A workqueue was deployed to manage these interdependencies, but it is
difficult to reason about, and fragile. A recent attempt to take the CXL
root device lock in the cxl_mem driver was reported by lockdep as
colliding with the flush_work() in the cxl_pmem flows.
Instead of the workqueue, arrange for all pmem/nvdimm devices to be torn
down immediately and hierarchically. A similar change is made to both
the 'cxl_nvdimm' and 'cxl_pmem_region' objects. For bisect-ability both
changes are made in the same patch which unfortunately makes the patch
bigger than desired.
Arrange for cxl_memdev and cxl_region to register a cxl_nvdimm and
cxl_pmem_region as a devres release action of the bridge device.
Additionally, include a devres release action of the cxl_memdev or
cxl_region device that triggers the bridge's release action if an endpoint
exits before the bridge. I.e. this allows either unplugging the bridge,
or unplugging and endpoint to result in the same cleanup actions.
To keep the patch smaller the cleanup of the now defunct workqueue
infrastructure is saved for a follow-on patch.
Tested-by: Robert Richter <rrichter@amd.com>
Link: https://lore.kernel.org/r/166993041773.1882361.16444301376147207609.stgit@dwillia2-xfh.jf.intel.com
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2022-12-01 13:33:37 -08:00
|
|
|
* @cxl_nvb: coordinate removal of @cxl_nvd if present
|
|
|
|
* @cxl_nvd: optional bridge to an nvdimm if the device supports pmem
|
2023-06-14 18:30:43 -07:00
|
|
|
* @endpoint: connection to the CXL port topology for this memory device
|
2021-05-13 22:21:49 -07:00
|
|
|
* @id: id number of this memdev instance.
|
2023-02-10 17:29:09 -08:00
|
|
|
* @depth: endpoint port depth
|
2025-05-21 13:47:41 +01:00
|
|
|
* @scrub_cycle: current scrub cycle set for this device
|
|
|
|
* @scrub_region_id: id number of a backed region (if any) for which current scrub cycle set
|
2025-05-21 13:47:44 +01:00
|
|
|
* @err_rec_array: List of xarrarys to store the memdev error records to
|
|
|
|
* check attributes for a memory repair operation are from
|
|
|
|
* current boot.
|
2021-05-13 22:21:49 -07:00
|
|
|
*/
|
|
|
|
struct cxl_memdev {
|
|
|
|
struct device dev;
|
|
|
|
struct cdev cdev;
|
2021-11-02 13:29:01 -07:00
|
|
|
struct cxl_dev_state *cxlds;
|
2022-02-04 07:18:31 -08:00
|
|
|
struct work_struct detach_work;
|
cxl/pmem: Refactor nvdimm device registration, delete the workqueue
The three objects 'struct cxl_nvdimm_bridge', 'struct cxl_nvdimm', and
'struct cxl_pmem_region' manage CXL persistent memory resources. The
bridge represents base platform resources, the nvdimm represents one or
more endpoints, and the region is a collection of nvdimms that
contribute to an assembled address range.
Their relationship is such that a region is torn down if any component
endpoints are removed. All regions and endpoints are torn down if the
foundational bridge device goes down.
A workqueue was deployed to manage these interdependencies, but it is
difficult to reason about, and fragile. A recent attempt to take the CXL
root device lock in the cxl_mem driver was reported by lockdep as
colliding with the flush_work() in the cxl_pmem flows.
Instead of the workqueue, arrange for all pmem/nvdimm devices to be torn
down immediately and hierarchically. A similar change is made to both
the 'cxl_nvdimm' and 'cxl_pmem_region' objects. For bisect-ability both
changes are made in the same patch which unfortunately makes the patch
bigger than desired.
Arrange for cxl_memdev and cxl_region to register a cxl_nvdimm and
cxl_pmem_region as a devres release action of the bridge device.
Additionally, include a devres release action of the cxl_memdev or
cxl_region device that triggers the bridge's release action if an endpoint
exits before the bridge. I.e. this allows either unplugging the bridge,
or unplugging and endpoint to result in the same cleanup actions.
To keep the patch smaller the cleanup of the now defunct workqueue
infrastructure is saved for a follow-on patch.
Tested-by: Robert Richter <rrichter@amd.com>
Link: https://lore.kernel.org/r/166993041773.1882361.16444301376147207609.stgit@dwillia2-xfh.jf.intel.com
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2022-12-01 13:33:37 -08:00
|
|
|
struct cxl_nvdimm_bridge *cxl_nvb;
|
|
|
|
struct cxl_nvdimm *cxl_nvd;
|
2023-06-14 18:30:43 -07:00
|
|
|
struct cxl_port *endpoint;
|
2021-05-13 22:21:49 -07:00
|
|
|
int id;
|
2023-02-10 17:29:09 -08:00
|
|
|
int depth;
|
2025-05-21 13:47:41 +01:00
|
|
|
u8 scrub_cycle;
|
|
|
|
int scrub_region_id;
|
2025-05-21 13:47:44 +01:00
|
|
|
void *err_rec_array;
|
2021-05-13 22:21:49 -07:00
|
|
|
};
|
|
|
|
|
2021-08-02 10:30:05 -07:00
|
|
|
static inline struct cxl_memdev *to_cxl_memdev(struct device *dev)
|
|
|
|
{
|
|
|
|
return container_of(dev, struct cxl_memdev, dev);
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:19:12 -07:00
|
|
|
static inline struct cxl_port *cxled_to_port(struct cxl_endpoint_decoder *cxled)
|
|
|
|
{
|
|
|
|
return to_cxl_port(cxled->cxld.dev.parent);
|
|
|
|
}
|
|
|
|
|
2022-06-07 10:56:10 -07:00
|
|
|
static inline struct cxl_port *cxlrd_to_port(struct cxl_root_decoder *cxlrd)
|
|
|
|
{
|
|
|
|
return to_cxl_port(cxlrd->cxlsd.cxld.dev.parent);
|
|
|
|
}
|
|
|
|
|
2022-07-21 17:19:12 -07:00
|
|
|
static inline struct cxl_memdev *
|
|
|
|
cxled_to_memdev(struct cxl_endpoint_decoder *cxled)
|
|
|
|
{
|
|
|
|
struct cxl_port *port = to_cxl_port(cxled->cxld.dev.parent);
|
|
|
|
|
2023-06-22 15:55:01 -05:00
|
|
|
return to_cxl_memdev(port->uport_dev);
|
2022-07-21 17:19:12 -07:00
|
|
|
}
|
|
|
|
|
2023-01-11 12:30:17 +01:00
|
|
|
bool is_cxl_memdev(const struct device *dev);
|
2022-02-04 07:18:31 -08:00
|
|
|
static inline bool is_cxl_endpoint(struct cxl_port *port)
|
|
|
|
{
|
2023-06-22 15:55:01 -05:00
|
|
|
return is_cxl_memdev(port->uport_dev);
|
2022-02-04 07:18:31 -08:00
|
|
|
}
|
|
|
|
|
2023-10-04 16:04:49 -07:00
|
|
|
struct cxl_memdev *devm_cxl_add_memdev(struct device *host,
|
|
|
|
struct cxl_dev_state *cxlds);
|
2023-10-04 16:49:36 -07:00
|
|
|
int devm_cxl_sanitize_setup_notifier(struct device *host,
|
|
|
|
struct cxl_memdev *cxlmd);
|
2023-06-25 17:16:51 -07:00
|
|
|
struct cxl_memdev_state;
|
2023-10-04 16:04:49 -07:00
|
|
|
int devm_cxl_setup_fw_upload(struct device *host, struct cxl_memdev_state *mds);
|
2023-02-10 01:06:45 -08:00
|
|
|
int devm_cxl_dpa_reserve(struct cxl_endpoint_decoder *cxled,
|
|
|
|
resource_size_t base, resource_size_t len,
|
|
|
|
resource_size_t skipped);
|
2021-08-02 10:30:05 -07:00
|
|
|
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
#define CXL_NR_PARTITIONS_MAX 2
|
|
|
|
|
|
|
|
struct cxl_dpa_info {
|
|
|
|
u64 size;
|
|
|
|
struct cxl_dpa_part_info {
|
|
|
|
struct range range;
|
|
|
|
enum cxl_partition_mode mode;
|
|
|
|
} part[CXL_NR_PARTITIONS_MAX];
|
|
|
|
int nr_partitions;
|
|
|
|
};
|
|
|
|
|
|
|
|
int cxl_dpa_setup(struct cxl_dev_state *cxlds, const struct cxl_dpa_info *info);
|
|
|
|
|
2022-12-01 13:34:10 -08:00
|
|
|
static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port,
|
|
|
|
struct cxl_memdev *cxlmd)
|
|
|
|
{
|
|
|
|
if (!port)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return xa_load(&port->endpoints, (unsigned long)&cxlmd->dev);
|
|
|
|
}
|
|
|
|
|
2022-04-03 19:12:15 -07:00
|
|
|
/*
|
2023-03-06 20:26:55 -08:00
|
|
|
* Per CXL 3.0 Section 8.2.8.4.5.1
|
2022-04-03 19:12:15 -07:00
|
|
|
*/
|
|
|
|
#define CMD_CMD_RC_TABLE \
|
|
|
|
C(SUCCESS, 0, NULL), \
|
|
|
|
C(BACKGROUND, -ENXIO, "background cmd started successfully"), \
|
|
|
|
C(INPUT, -ENXIO, "cmd input was invalid"), \
|
|
|
|
C(UNSUPPORTED, -ENXIO, "cmd is not supported"), \
|
|
|
|
C(INTERNAL, -ENXIO, "internal device error"), \
|
|
|
|
C(RETRY, -ENXIO, "temporary error, retry once"), \
|
|
|
|
C(BUSY, -ENXIO, "ongoing background operation"), \
|
|
|
|
C(MEDIADISABLED, -ENXIO, "media access is disabled"), \
|
|
|
|
C(FWINPROGRESS, -ENXIO, "one FW package can be transferred at a time"), \
|
|
|
|
C(FWOOO, -ENXIO, "FW package content was transferred out of order"), \
|
|
|
|
C(FWAUTH, -ENXIO, "FW package authentication failed"), \
|
|
|
|
C(FWSLOT, -ENXIO, "FW slot is not supported for requested operation"), \
|
|
|
|
C(FWROLLBACK, -ENXIO, "rolled back to the previous active FW"), \
|
|
|
|
C(FWRESET, -ENXIO, "FW failed to activate, needs cold reset"), \
|
|
|
|
C(HANDLE, -ENXIO, "one or more Event Record Handles were invalid"), \
|
2023-04-18 10:39:06 -07:00
|
|
|
C(PADDR, -EFAULT, "physical address specified is invalid"), \
|
2024-07-06 18:53:43 -07:00
|
|
|
C(POISONLMT, -EBUSY, "poison injection limit has been reached"), \
|
2022-04-03 19:12:15 -07:00
|
|
|
C(MEDIAFAILURE, -ENXIO, "permanent issue with the media"), \
|
|
|
|
C(ABORT, -ENXIO, "background cmd was aborted by device"), \
|
|
|
|
C(SECURITY, -ENXIO, "not valid in the current security state"), \
|
|
|
|
C(PASSPHRASE, -ENXIO, "phrase doesn't match current set passphrase"), \
|
|
|
|
C(MBUNSUPPORTED, -ENXIO, "unsupported on the mailbox it was issued on"),\
|
2023-03-06 20:26:55 -08:00
|
|
|
C(PAYLOADLEN, -ENXIO, "invalid payload length"), \
|
|
|
|
C(LOG, -ENXIO, "invalid or unsupported log page"), \
|
|
|
|
C(INTERRUPTED, -ENXIO, "asynchronous event occured"), \
|
|
|
|
C(FEATUREVERSION, -ENXIO, "unsupported feature version"), \
|
|
|
|
C(FEATURESELVALUE, -ENXIO, "unsupported feature selection value"), \
|
|
|
|
C(FEATURETRANSFERIP, -ENXIO, "feature transfer in progress"), \
|
|
|
|
C(FEATURETRANSFEROOO, -ENXIO, "feature transfer out of order"), \
|
|
|
|
C(RESOURCEEXHAUSTED, -ENXIO, "resources are exhausted"), \
|
|
|
|
C(EXTLIST, -ENXIO, "invalid Extent List"), \
|
2022-04-03 19:12:15 -07:00
|
|
|
|
|
|
|
#undef C
|
|
|
|
#define C(a, b, c) CXL_MBOX_CMD_RC_##a
|
|
|
|
enum { CMD_CMD_RC_TABLE };
|
|
|
|
#undef C
|
|
|
|
#define C(a, b, c) { b, c }
|
|
|
|
struct cxl_mbox_cmd_rc {
|
|
|
|
int err;
|
|
|
|
const char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const
|
|
|
|
struct cxl_mbox_cmd_rc cxl_mbox_cmd_rctable[] ={ CMD_CMD_RC_TABLE };
|
|
|
|
#undef C
|
|
|
|
|
|
|
|
static inline const char *cxl_mbox_cmd_rc2str(struct cxl_mbox_cmd *mbox_cmd)
|
|
|
|
{
|
|
|
|
return cxl_mbox_cmd_rctable[mbox_cmd->return_code].desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int cxl_mbox_cmd_rc2errno(struct cxl_mbox_cmd *mbox_cmd)
|
|
|
|
{
|
|
|
|
return cxl_mbox_cmd_rctable[mbox_cmd->return_code].err;
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:12:21 -07:00
|
|
|
/*
|
|
|
|
* CXL 2.0 - Memory capacity multiplier
|
|
|
|
* See Section 8.2.9.5
|
|
|
|
*
|
|
|
|
* Volatile, Persistent, and Partition capacities are specified to be in
|
|
|
|
* multiples of 256MB - define a multiplier to convert to/from bytes.
|
|
|
|
*/
|
|
|
|
#define CXL_CAPACITY_MULTIPLIER SZ_256M
|
|
|
|
|
2023-06-14 18:29:51 -07:00
|
|
|
/*
|
2023-01-17 21:53:37 -08:00
|
|
|
* Event Interrupt Policy
|
|
|
|
*
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.4; Table 8-52
|
|
|
|
*/
|
|
|
|
enum cxl_event_int_mode {
|
|
|
|
CXL_INT_NONE = 0x00,
|
|
|
|
CXL_INT_MSI_MSIX = 0x01,
|
|
|
|
CXL_INT_FW = 0x02
|
|
|
|
};
|
|
|
|
struct cxl_event_interrupt_policy {
|
|
|
|
u8 info_settings;
|
|
|
|
u8 warn_settings;
|
|
|
|
u8 failure_settings;
|
|
|
|
u8 fatal_settings;
|
|
|
|
} __packed;
|
|
|
|
|
2023-01-17 21:53:36 -08:00
|
|
|
/**
|
|
|
|
* struct cxl_event_state - Event log driver state
|
|
|
|
*
|
2023-06-14 18:29:51 -07:00
|
|
|
* @buf: Buffer to receive event data
|
|
|
|
* @log_lock: Serialize event_buf and log use
|
2022-02-01 15:48:56 -08:00
|
|
|
*/
|
2023-01-17 21:53:36 -08:00
|
|
|
struct cxl_event_state {
|
|
|
|
struct cxl_get_event_payload *buf;
|
|
|
|
struct mutex log_lock;
|
2022-02-01 15:48:56 -08:00
|
|
|
};
|
|
|
|
|
2023-04-18 10:39:03 -07:00
|
|
|
/* Device enabled poison commands */
|
|
|
|
enum poison_cmd_enabled_bits {
|
|
|
|
CXL_POISON_ENABLED_LIST,
|
|
|
|
CXL_POISON_ENABLED_INJECT,
|
|
|
|
CXL_POISON_ENABLED_CLEAR,
|
|
|
|
CXL_POISON_ENABLED_SCAN_CAPS,
|
|
|
|
CXL_POISON_ENABLED_SCAN_MEDIA,
|
|
|
|
CXL_POISON_ENABLED_SCAN_RESULTS,
|
|
|
|
CXL_POISON_ENABLED_MAX
|
|
|
|
};
|
|
|
|
|
2023-07-25 22:19:40 -07:00
|
|
|
/* Device enabled security commands */
|
|
|
|
enum security_cmd_enabled_bits {
|
|
|
|
CXL_SEC_ENABLED_SANITIZE,
|
|
|
|
CXL_SEC_ENABLED_SECURE_ERASE,
|
|
|
|
CXL_SEC_ENABLED_GET_SECURITY_STATE,
|
|
|
|
CXL_SEC_ENABLED_SET_PASSPHRASE,
|
|
|
|
CXL_SEC_ENABLED_DISABLE_PASSPHRASE,
|
|
|
|
CXL_SEC_ENABLED_UNLOCK,
|
|
|
|
CXL_SEC_ENABLED_FREEZE_SECURITY,
|
|
|
|
CXL_SEC_ENABLED_PASSPHRASE_SECURE_ERASE,
|
|
|
|
CXL_SEC_ENABLED_MAX
|
|
|
|
};
|
|
|
|
|
2023-04-18 10:39:03 -07:00
|
|
|
/**
|
|
|
|
* struct cxl_poison_state - Driver poison state info
|
|
|
|
*
|
|
|
|
* @max_errors: Maximum media error records held in device cache
|
|
|
|
* @enabled_cmds: All poison commands enabled in the CEL
|
|
|
|
* @list_out: The poison list payload returned by device
|
2025-07-11 16:49:26 -07:00
|
|
|
* @mutex: Protect reads of the poison list
|
2023-04-18 10:39:03 -07:00
|
|
|
*
|
|
|
|
* Reads of the poison list are synchronized to ensure that a reader
|
|
|
|
* does not get an incomplete list because their request overlapped
|
|
|
|
* (was interrupted or preceded by) another read request of the same
|
|
|
|
* DPA range. CXL Spec 3.0 Section 8.2.9.8.4.1
|
|
|
|
*/
|
|
|
|
struct cxl_poison_state {
|
|
|
|
u32 max_errors;
|
|
|
|
DECLARE_BITMAP(enabled_cmds, CXL_POISON_ENABLED_MAX);
|
|
|
|
struct cxl_mbox_poison_out *list_out;
|
2025-07-11 16:49:26 -07:00
|
|
|
struct mutex mutex; /* Protect reads of poison list */
|
2023-04-18 10:39:03 -07:00
|
|
|
};
|
|
|
|
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 11:17:40 -06:00
|
|
|
/*
|
|
|
|
* Get FW Info
|
|
|
|
* CXL rev 3.0 section 8.2.9.3.1; Table 8-56
|
|
|
|
*/
|
|
|
|
struct cxl_mbox_get_fw_info {
|
|
|
|
u8 num_slots;
|
|
|
|
u8 slot_info;
|
|
|
|
u8 activation_cap;
|
|
|
|
u8 reserved[13];
|
|
|
|
char slot_1_revision[16];
|
|
|
|
char slot_2_revision[16];
|
|
|
|
char slot_3_revision[16];
|
|
|
|
char slot_4_revision[16];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define CXL_FW_INFO_SLOT_INFO_CUR_MASK GENMASK(2, 0)
|
|
|
|
#define CXL_FW_INFO_SLOT_INFO_NEXT_MASK GENMASK(5, 3)
|
|
|
|
#define CXL_FW_INFO_SLOT_INFO_NEXT_SHIFT 3
|
|
|
|
#define CXL_FW_INFO_ACTIVATION_CAP_HAS_LIVE_ACTIVATE BIT(0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer FW Input Payload
|
|
|
|
* CXL rev 3.0 section 8.2.9.3.2; Table 8-57
|
|
|
|
*/
|
|
|
|
struct cxl_mbox_transfer_fw {
|
|
|
|
u8 action;
|
|
|
|
u8 slot;
|
|
|
|
u8 reserved[2];
|
|
|
|
__le32 offset;
|
|
|
|
u8 reserved2[0x78];
|
|
|
|
u8 data[];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define CXL_FW_TRANSFER_ACTION_FULL 0x0
|
|
|
|
#define CXL_FW_TRANSFER_ACTION_INITIATE 0x1
|
|
|
|
#define CXL_FW_TRANSFER_ACTION_CONTINUE 0x2
|
|
|
|
#define CXL_FW_TRANSFER_ACTION_END 0x3
|
|
|
|
#define CXL_FW_TRANSFER_ACTION_ABORT 0x4
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CXL rev 3.0 section 8.2.9.3.2 mandates 128-byte alignment for FW packages
|
|
|
|
* and for each part transferred in a Transfer FW command.
|
|
|
|
*/
|
|
|
|
#define CXL_FW_TRANSFER_ALIGNMENT 128
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Activate FW Input Payload
|
|
|
|
* CXL rev 3.0 section 8.2.9.3.3; Table 8-58
|
|
|
|
*/
|
|
|
|
struct cxl_mbox_activate_fw {
|
|
|
|
u8 action;
|
|
|
|
u8 slot;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define CXL_FW_ACTIVATE_ONLINE 0x0
|
|
|
|
#define CXL_FW_ACTIVATE_OFFLINE 0x1
|
|
|
|
|
|
|
|
/* FW state bits */
|
|
|
|
#define CXL_FW_STATE_BITS 32
|
2023-07-03 17:17:45 +03:00
|
|
|
#define CXL_FW_CANCEL 0
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 11:17:40 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct cxl_fw_state - Firmware upload / activation state
|
|
|
|
*
|
|
|
|
* @state: fw_uploader state bitmask
|
|
|
|
* @oneshot: whether the fw upload fits in a single transfer
|
|
|
|
* @num_slots: Number of FW slots available
|
|
|
|
* @cur_slot: Slot number currently active
|
|
|
|
* @next_slot: Slot number for the new firmware
|
|
|
|
*/
|
|
|
|
struct cxl_fw_state {
|
|
|
|
DECLARE_BITMAP(state, CXL_FW_STATE_BITS);
|
|
|
|
bool oneshot;
|
|
|
|
int num_slots;
|
|
|
|
int cur_slot;
|
|
|
|
int next_slot;
|
|
|
|
};
|
|
|
|
|
2023-06-12 11:10:33 -07:00
|
|
|
/**
|
|
|
|
* struct cxl_security_state - Device security state
|
|
|
|
*
|
|
|
|
* @state: state of last security operation
|
2023-07-25 22:19:40 -07:00
|
|
|
* @enabled_cmds: All security commands enabled in the CEL
|
2023-06-12 11:10:34 -07:00
|
|
|
* @poll_tmo_secs: polling timeout
|
2023-10-04 18:35:01 -07:00
|
|
|
* @sanitize_active: sanitize completion pending
|
2023-06-12 11:10:34 -07:00
|
|
|
* @poll_dwork: polling work item
|
2023-06-12 11:10:35 -07:00
|
|
|
* @sanitize_node: sanitation sysfs file to notify
|
2023-06-12 11:10:33 -07:00
|
|
|
*/
|
|
|
|
struct cxl_security_state {
|
|
|
|
unsigned long state;
|
2023-07-25 22:19:40 -07:00
|
|
|
DECLARE_BITMAP(enabled_cmds, CXL_SEC_ENABLED_MAX);
|
2023-06-12 11:10:34 -07:00
|
|
|
int poll_tmo_secs;
|
2023-10-04 18:35:01 -07:00
|
|
|
bool sanitize_active;
|
2023-06-12 11:10:34 -07:00
|
|
|
struct delayed_work poll_dwork;
|
2023-06-12 11:10:35 -07:00
|
|
|
struct kernfs_node *sanitize_node;
|
2023-06-12 11:10:33 -07:00
|
|
|
};
|
|
|
|
|
2023-06-14 18:30:07 -07:00
|
|
|
/*
|
|
|
|
* enum cxl_devtype - delineate type-2 from a generic type-3 device
|
|
|
|
* @CXL_DEVTYPE_DEVMEM - Vendor specific CXL Type-2 device implementing HDM-D or
|
|
|
|
* HDM-DB, no requirement that this device implements a
|
|
|
|
* mailbox, or other memory-device-standard manageability
|
|
|
|
* flows.
|
|
|
|
* @CXL_DEVTYPE_CLASSMEM - Common class definition of a CXL Type-3 device with
|
|
|
|
* HDM-H and class-mandatory memory device registers
|
|
|
|
*/
|
|
|
|
enum cxl_devtype {
|
|
|
|
CXL_DEVTYPE_DEVMEM,
|
|
|
|
CXL_DEVTYPE_CLASSMEM,
|
|
|
|
};
|
|
|
|
|
2023-12-21 15:04:11 -07:00
|
|
|
/**
|
|
|
|
* struct cxl_dpa_perf - DPA performance property entry
|
2024-06-14 04:47:55 -04:00
|
|
|
* @dpa_range: range for DPA address
|
|
|
|
* @coord: QoS performance data (i.e. latency, bandwidth)
|
2024-09-03 17:11:50 -07:00
|
|
|
* @cdat_coord: raw QoS performance data from CDAT
|
2024-06-14 04:47:55 -04:00
|
|
|
* @qos_class: QoS Class cookies
|
2023-12-21 15:04:11 -07:00
|
|
|
*/
|
|
|
|
struct cxl_dpa_perf {
|
|
|
|
struct range dpa_range;
|
2024-04-03 08:47:15 -07:00
|
|
|
struct access_coordinate coord[ACCESS_COORDINATE_MAX];
|
2024-09-03 17:11:50 -07:00
|
|
|
struct access_coordinate cdat_coord[ACCESS_COORDINATE_MAX];
|
2023-12-21 15:04:11 -07:00
|
|
|
int qos_class;
|
|
|
|
};
|
|
|
|
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
/**
|
|
|
|
* struct cxl_dpa_partition - DPA partition descriptor
|
|
|
|
* @res: shortcut to the partition in the DPA resource tree (cxlds->dpa_res)
|
|
|
|
* @perf: performance attributes of the partition from CDAT
|
|
|
|
* @mode: operation mode for the DPA capacity, e.g. ram, pmem, dynamic...
|
|
|
|
*/
|
|
|
|
struct cxl_dpa_partition {
|
|
|
|
struct resource res;
|
|
|
|
struct cxl_dpa_perf perf;
|
|
|
|
enum cxl_partition_mode mode;
|
|
|
|
};
|
|
|
|
|
2021-05-13 22:21:49 -07:00
|
|
|
/**
|
2021-11-02 13:29:01 -07:00
|
|
|
* struct cxl_dev_state - The driver device state
|
|
|
|
*
|
|
|
|
* cxl_dev_state represents the CXL driver/device state. It provides an
|
|
|
|
* interface to mailbox commands as well as some cached data about the device.
|
|
|
|
* Currently only memory devices are represented.
|
|
|
|
*
|
|
|
|
* @dev: The device associated with this CXL state
|
2022-11-29 10:48:59 -07:00
|
|
|
* @cxlmd: The device representing the CXL.mem capabilities of @dev
|
2023-10-18 19:16:59 +02:00
|
|
|
* @reg_map: component and ras register mapping parameters
|
cxl/mem: Introduce 'struct cxl_regs' for "composable" CXL devices
CXL MMIO register blocks are organized by device type and capabilities.
There are Component registers, Device registers (yes, an ambiguous
name), and Memory Device registers (a specific extension of Device
registers).
It is possible for a given device instance (endpoint or port) to
implement register sets from multiple of the above categories.
The driver code that enumerates and maps the registers is type specific
so it is useful to have a dedicated type and helpers for each block
type.
At the same time, once the registers are mapped the origin type does not
matter. It is overly pedantic to reference the register block type in
code that is using the registers.
In preparation for the endpoint driver to incorporate Component registers
into its MMIO operations reorganize the registers to allow typed
enumeration + mapping, but anonymous usage. With the end state of
'struct cxl_regs' to be:
struct cxl_regs {
union {
struct {
CXL_DEVICE_REGS();
};
struct cxl_device_regs device_regs;
};
union {
struct {
CXL_COMPONENT_REGS();
};
struct cxl_component_regs component_regs;
};
};
With this arrangement the driver can share component init code with
ports, but when using the registers it can directly reference the
component register block type by name without the 'component_regs'
prefix.
So, map + enumerate can be shared across drivers of different CXL
classes e.g.:
void cxl_setup_device_regs(struct device *dev, void __iomem *base,
struct cxl_device_regs *regs);
void cxl_setup_component_regs(struct device *dev, void __iomem *base,
struct cxl_component_regs *regs);
...while inline usage in the driver need not indicate where the
registers came from:
readl(cxlm->regs.mbox + MBOX_OFFSET);
readl(cxlm->regs.hdm + HDM_OFFSET);
...instead of:
readl(cxlm->regs.device_regs.mbox + MBOX_OFFSET);
readl(cxlm->regs.component_regs.hdm + HDM_OFFSET);
This complexity of the definition in .h yields improvement in code
readability in .c while maintaining type-safety for organization of
setup code. It prepares the implementation to maintain organization in
the face of CXL devices that compose register interfaces consisting of
multiple types.
Given that this new container is named 'regs' rename the common register
base pointer @base, and fixup the kernel-doc for the missing @cxlmd
description.
Reviewed-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/162096971451.1865304.13540251513463515153.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-05-13 22:21:54 -07:00
|
|
|
* @regs: Parsed register blocks
|
2022-02-01 14:06:32 -08:00
|
|
|
* @cxl_dvsec: Offset to the PCIe device DVSEC
|
2022-12-01 13:34:16 -08:00
|
|
|
* @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
|
2023-05-18 16:38:20 -07:00
|
|
|
* @media_ready: Indicate whether the device media is usable
|
2023-06-14 18:30:02 -07:00
|
|
|
* @dpa_res: Overall DPA resource tree for the device
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
* @part: DPA partition array
|
|
|
|
* @nr_partitions: Number of DPA partitions
|
2023-06-14 18:30:02 -07:00
|
|
|
* @serial: PCIe Device Serial Number
|
2023-06-14 18:30:07 -07:00
|
|
|
* @type: Generic Memory Class device or Vendor Specific Memory device
|
2024-09-05 15:35:46 -07:00
|
|
|
* @cxl_mbox: CXL mailbox context
|
2025-02-20 12:42:40 -07:00
|
|
|
* @cxlfs: CXL features context
|
2023-06-14 18:30:02 -07:00
|
|
|
*/
|
|
|
|
struct cxl_dev_state {
|
|
|
|
struct device *dev;
|
|
|
|
struct cxl_memdev *cxlmd;
|
2023-10-18 19:16:59 +02:00
|
|
|
struct cxl_register_map reg_map;
|
2023-06-14 18:30:02 -07:00
|
|
|
struct cxl_regs regs;
|
|
|
|
int cxl_dvsec;
|
|
|
|
bool rcd;
|
|
|
|
bool media_ready;
|
|
|
|
struct resource dpa_res;
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
struct cxl_dpa_partition part[CXL_NR_PARTITIONS_MAX];
|
|
|
|
unsigned int nr_partitions;
|
2023-06-14 18:30:02 -07:00
|
|
|
u64 serial;
|
2023-06-14 18:30:07 -07:00
|
|
|
enum cxl_devtype type;
|
2024-09-05 15:35:46 -07:00
|
|
|
struct cxl_mailbox cxl_mbox;
|
2025-02-20 12:42:40 -07:00
|
|
|
#ifdef CONFIG_CXL_FEATURES
|
|
|
|
struct cxl_features_state *cxlfs;
|
|
|
|
#endif
|
2023-06-14 18:30:02 -07:00
|
|
|
};
|
|
|
|
|
2025-02-03 20:24:35 -08:00
|
|
|
static inline resource_size_t cxl_pmem_size(struct cxl_dev_state *cxlds)
|
cxl: Introduce to_{ram,pmem}_{res,perf}() helpers
In preparation for consolidating all DPA partition information into an
array of DPA metadata, introduce helpers that hide the layout of the
current data. I.e. make the eventual replacement of ->ram_res,
->pmem_res, ->ram_perf, and ->pmem_perf with a new DPA metadata array a
no-op for code paths that consume that information, and reduce the noise
of follow-on patches.
The end goal is to consolidate all DPA information in 'struct
cxl_dev_state', but for now the helpers just make it appear that all DPA
metadata is relative to @cxlds.
As the conversion to generic partition metadata walking is completed,
these helpers will naturally be eliminated, or reduced in scope.
Cc: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305238.668823.16553986866633608541.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:12 -08:00
|
|
|
{
|
2025-02-03 20:24:35 -08:00
|
|
|
/*
|
|
|
|
* Static PMEM may be at partition index 0 when there is no static RAM
|
|
|
|
* capacity.
|
|
|
|
*/
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
for (int i = 0; i < cxlds->nr_partitions; i++)
|
|
|
|
if (cxlds->part[i].mode == CXL_PARTMODE_PMEM)
|
2025-02-03 20:24:35 -08:00
|
|
|
return resource_size(&cxlds->part[i].res);
|
|
|
|
return 0;
|
cxl: Introduce to_{ram,pmem}_{res,perf}() helpers
In preparation for consolidating all DPA partition information into an
array of DPA metadata, introduce helpers that hide the layout of the
current data. I.e. make the eventual replacement of ->ram_res,
->pmem_res, ->ram_perf, and ->pmem_perf with a new DPA metadata array a
no-op for code paths that consume that information, and reduce the noise
of follow-on patches.
The end goal is to consolidate all DPA information in 'struct
cxl_dev_state', but for now the helpers just make it appear that all DPA
metadata is relative to @cxlds.
As the conversion to generic partition metadata walking is completed,
these helpers will naturally be eliminated, or reduced in scope.
Cc: Alejandro Lucero <alucerop@amd.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Fan Ni <fan.ni@samsung.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305238.668823.16553986866633608541.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:12 -08:00
|
|
|
}
|
|
|
|
|
2024-09-05 15:35:46 -07:00
|
|
|
static inline struct cxl_dev_state *mbox_to_cxlds(struct cxl_mailbox *cxl_mbox)
|
|
|
|
{
|
|
|
|
return dev_get_drvdata(cxl_mbox->host);
|
|
|
|
}
|
|
|
|
|
2023-06-14 18:30:02 -07:00
|
|
|
/**
|
|
|
|
* struct cxl_memdev_state - Generic Type-3 Memory Device Class driver data
|
|
|
|
*
|
|
|
|
* CXL 8.1.12.1 PCI Header - Class Code Register Memory Device defines
|
|
|
|
* common memory device functionality like the presence of a mailbox and
|
|
|
|
* the functionality related to that like Identify Memory Device and Get
|
|
|
|
* Partition Info
|
|
|
|
* @cxlds: Core driver state common across Type-2 and Type-3 devices
|
2021-05-20 13:47:45 -06:00
|
|
|
* @lsa_size: Size of Label Storage Area
|
|
|
|
* (CXL 2.0 8.2.9.5.1.1 Identify Memory Device)
|
2021-05-13 22:21:49 -07:00
|
|
|
* @firmware_version: Firmware version for the memory device.
|
2021-09-13 15:24:32 -07:00
|
|
|
* @total_bytes: sum of all possible capacities
|
|
|
|
* @volatile_only_bytes: hard volatile capacity
|
|
|
|
* @persistent_only_bytes: hard persistent capacity
|
|
|
|
* @partition_align_bytes: alignment size for partition-able capacity
|
|
|
|
* @active_volatile_bytes: sum of hard + soft volatile
|
|
|
|
* @active_persistent_bytes: sum of hard + soft persistent
|
2023-02-16 11:24:26 -08:00
|
|
|
* @event: event log driver state
|
2023-04-18 10:39:03 -07:00
|
|
|
* @poison: poison driver state info
|
2023-07-25 22:19:39 -07:00
|
|
|
* @security: security driver state info
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 11:17:40 -06:00
|
|
|
* @fw: firmware upload / activation state
|
2025-02-26 09:21:21 -07:00
|
|
|
* @mce_notifier: MCE notifier
|
2021-09-13 15:24:32 -07:00
|
|
|
*
|
2023-06-14 18:30:02 -07:00
|
|
|
* See CXL 3.0 8.2.9.8.2 Capacity Configuration and Label Storage for
|
2021-09-13 15:24:32 -07:00
|
|
|
* details on capacity parameters.
|
2021-05-13 22:21:49 -07:00
|
|
|
*/
|
2023-06-14 18:30:02 -07:00
|
|
|
struct cxl_memdev_state {
|
|
|
|
struct cxl_dev_state cxlds;
|
2021-05-20 13:47:45 -06:00
|
|
|
size_t lsa_size;
|
2021-05-13 22:21:49 -07:00
|
|
|
char firmware_version[0x10];
|
2021-06-17 15:16:18 -07:00
|
|
|
u64 total_bytes;
|
|
|
|
u64 volatile_only_bytes;
|
|
|
|
u64 persistent_only_bytes;
|
|
|
|
u64 partition_align_bytes;
|
2021-08-10 11:57:59 -07:00
|
|
|
u64 active_volatile_bytes;
|
|
|
|
u64 active_persistent_bytes;
|
2023-12-21 15:04:11 -07:00
|
|
|
|
2023-01-17 21:53:36 -08:00
|
|
|
struct cxl_event_state event;
|
2023-04-18 10:39:03 -07:00
|
|
|
struct cxl_poison_state poison;
|
2023-06-12 11:10:33 -07:00
|
|
|
struct cxl_security_state security;
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 11:17:40 -06:00
|
|
|
struct cxl_fw_state fw;
|
2025-02-26 09:21:21 -07:00
|
|
|
struct notifier_block mce_notifier;
|
2021-05-13 22:21:49 -07:00
|
|
|
};
|
2021-09-08 22:12:32 -07:00
|
|
|
|
2023-06-14 18:30:02 -07:00
|
|
|
static inline struct cxl_memdev_state *
|
|
|
|
to_cxl_memdev_state(struct cxl_dev_state *cxlds)
|
|
|
|
{
|
2023-06-14 18:30:07 -07:00
|
|
|
if (cxlds->type != CXL_DEVTYPE_CLASSMEM)
|
|
|
|
return NULL;
|
2023-06-14 18:30:02 -07:00
|
|
|
return container_of(cxlds, struct cxl_memdev_state, cxlds);
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:12:32 -07:00
|
|
|
enum cxl_opcode {
|
|
|
|
CXL_MBOX_OP_INVALID = 0x0000,
|
|
|
|
CXL_MBOX_OP_RAW = CXL_MBOX_OP_INVALID,
|
2023-01-17 21:53:36 -08:00
|
|
|
CXL_MBOX_OP_GET_EVENT_RECORD = 0x0100,
|
|
|
|
CXL_MBOX_OP_CLEAR_EVENT_RECORD = 0x0101,
|
2023-01-17 21:53:37 -08:00
|
|
|
CXL_MBOX_OP_GET_EVT_INT_POLICY = 0x0102,
|
|
|
|
CXL_MBOX_OP_SET_EVT_INT_POLICY = 0x0103,
|
2021-09-08 22:12:32 -07:00
|
|
|
CXL_MBOX_OP_GET_FW_INFO = 0x0200,
|
cxl: add a firmware update mechanism using the sysfs firmware loader
The sysfs based firmware loader mechanism was created to easily allow
userspace to upload firmware images to FPGA cards. This also happens to
be pretty suitable to create a user-initiated but kernel-controlled
firmware update mechanism for CXL devices, using the CXL specified
mailbox commands.
Since firmware update commands can be long-running, and can be processed
in the background by the endpoint device, it is desirable to have the
ability to chunk the firmware transfer down to smaller pieces, so that
one operation does not monopolize the mailbox, locking out any other
long running background commands entirely - e.g. security commands like
'sanitize' or poison scanning operations.
The firmware loader mechanism allows a natural way to perform this
chunking, as after each mailbox command, that is restricted to the
maximum mailbox payload size, the cxl memdev driver relinquishes control
back to the fw_loader system and awaits the next chunk of data to
transfer. This opens opportunities for other background commands to
access the mailbox and send their own slices of background commands.
Add the necessary helpers and state tracking to be able to perform the
'Get FW Info', 'Transfer FW', and 'Activate FW' mailbox commands as
described in the CXL spec. Wire these up to the firmware loader
callbacks, and register with that system to create the memX/firmware/
sysfs ABI.
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
Cc: Russ Weight <russell.h.weight@intel.com>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Ben Widawsky <bwidawsk@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
Link: https://lore.kernel.org/r/20230602-vv-fw_update-v4-1-c6265bd7343b@intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-06-14 11:17:40 -06:00
|
|
|
CXL_MBOX_OP_TRANSFER_FW = 0x0201,
|
2021-09-08 22:12:32 -07:00
|
|
|
CXL_MBOX_OP_ACTIVATE_FW = 0x0202,
|
2023-08-29 08:20:14 -07:00
|
|
|
CXL_MBOX_OP_GET_TIMESTAMP = 0x0300,
|
2023-01-30 15:13:27 +00:00
|
|
|
CXL_MBOX_OP_SET_TIMESTAMP = 0x0301,
|
2021-09-08 22:12:32 -07:00
|
|
|
CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400,
|
|
|
|
CXL_MBOX_OP_GET_LOG = 0x0401,
|
2024-03-13 12:42:17 +05:30
|
|
|
CXL_MBOX_OP_GET_LOG_CAPS = 0x0402,
|
2024-03-13 12:42:18 +05:30
|
|
|
CXL_MBOX_OP_CLEAR_LOG = 0x0403,
|
2024-03-13 12:42:17 +05:30
|
|
|
CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405,
|
2025-02-20 12:42:39 -07:00
|
|
|
CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500,
|
|
|
|
CXL_MBOX_OP_GET_FEATURE = 0x0501,
|
|
|
|
CXL_MBOX_OP_SET_FEATURE = 0x0502,
|
2025-05-21 13:47:43 +01:00
|
|
|
CXL_MBOX_OP_DO_MAINTENANCE = 0x0600,
|
2021-09-08 22:12:32 -07:00
|
|
|
CXL_MBOX_OP_IDENTIFY = 0x4000,
|
|
|
|
CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100,
|
|
|
|
CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101,
|
|
|
|
CXL_MBOX_OP_GET_LSA = 0x4102,
|
|
|
|
CXL_MBOX_OP_SET_LSA = 0x4103,
|
|
|
|
CXL_MBOX_OP_GET_HEALTH_INFO = 0x4200,
|
|
|
|
CXL_MBOX_OP_GET_ALERT_CONFIG = 0x4201,
|
|
|
|
CXL_MBOX_OP_SET_ALERT_CONFIG = 0x4202,
|
|
|
|
CXL_MBOX_OP_GET_SHUTDOWN_STATE = 0x4203,
|
|
|
|
CXL_MBOX_OP_SET_SHUTDOWN_STATE = 0x4204,
|
|
|
|
CXL_MBOX_OP_GET_POISON = 0x4300,
|
|
|
|
CXL_MBOX_OP_INJECT_POISON = 0x4301,
|
|
|
|
CXL_MBOX_OP_CLEAR_POISON = 0x4302,
|
|
|
|
CXL_MBOX_OP_GET_SCAN_MEDIA_CAPS = 0x4303,
|
|
|
|
CXL_MBOX_OP_SCAN_MEDIA = 0x4304,
|
|
|
|
CXL_MBOX_OP_GET_SCAN_MEDIA = 0x4305,
|
2023-06-12 11:10:34 -07:00
|
|
|
CXL_MBOX_OP_SANITIZE = 0x4400,
|
2023-06-12 11:10:37 -07:00
|
|
|
CXL_MBOX_OP_SECURE_ERASE = 0x4401,
|
2022-11-30 12:21:36 -07:00
|
|
|
CXL_MBOX_OP_GET_SECURITY_STATE = 0x4500,
|
2022-11-30 12:21:47 -07:00
|
|
|
CXL_MBOX_OP_SET_PASSPHRASE = 0x4501,
|
2022-11-30 12:21:58 -07:00
|
|
|
CXL_MBOX_OP_DISABLE_PASSPHRASE = 0x4502,
|
2022-11-30 12:22:21 -07:00
|
|
|
CXL_MBOX_OP_UNLOCK = 0x4503,
|
2022-11-30 12:22:10 -07:00
|
|
|
CXL_MBOX_OP_FREEZE_SECURITY = 0x4504,
|
2022-11-30 12:22:32 -07:00
|
|
|
CXL_MBOX_OP_PASSPHRASE_SECURE_ERASE = 0x4505,
|
2021-09-08 22:12:32 -07:00
|
|
|
CXL_MBOX_OP_MAX = 0x10000
|
|
|
|
};
|
|
|
|
|
2021-09-08 22:13:15 -07:00
|
|
|
#define DEFINE_CXL_CEL_UUID \
|
|
|
|
UUID_INIT(0xda9c0b5, 0xbf41, 0x4b78, 0x8f, 0x79, 0x96, 0xb1, 0x62, \
|
|
|
|
0x3b, 0x3f, 0x17)
|
|
|
|
|
|
|
|
#define DEFINE_CXL_VENDOR_DEBUG_UUID \
|
2024-07-10 10:31:12 +08:00
|
|
|
UUID_INIT(0x5e1819d9, 0x11a9, 0x400c, 0x81, 0x1f, 0xd6, 0x07, 0x19, \
|
2021-09-08 22:13:15 -07:00
|
|
|
0x40, 0x3d, 0x86)
|
|
|
|
|
|
|
|
struct cxl_mbox_get_supported_logs {
|
|
|
|
__le16 entries;
|
|
|
|
u8 rsvd[6];
|
|
|
|
struct cxl_gsl_entry {
|
|
|
|
uuid_t uuid;
|
|
|
|
__le32 size;
|
|
|
|
} __packed entry[];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct cxl_cel_entry {
|
|
|
|
__le16 opcode;
|
|
|
|
__le16 effect;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct cxl_mbox_get_log {
|
|
|
|
uuid_t uuid;
|
|
|
|
__le32 offset;
|
|
|
|
__le32 length;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/* See CXL 2.0 Table 175 Identify Memory Device Output Payload */
|
|
|
|
struct cxl_mbox_identify {
|
|
|
|
char fw_revision[0x10];
|
|
|
|
__le64 total_capacity;
|
|
|
|
__le64 volatile_capacity;
|
|
|
|
__le64 persistent_capacity;
|
|
|
|
__le64 partition_align;
|
|
|
|
__le16 info_event_log_size;
|
|
|
|
__le16 warning_event_log_size;
|
|
|
|
__le16 failure_event_log_size;
|
|
|
|
__le16 fatal_event_log_size;
|
|
|
|
__le32 lsa_size;
|
|
|
|
u8 poison_list_max_mer[3];
|
|
|
|
__le16 inject_poison_limit;
|
|
|
|
u8 poison_caps;
|
|
|
|
u8 qos_telemetry_caps;
|
|
|
|
} __packed;
|
|
|
|
|
2023-01-17 21:53:36 -08:00
|
|
|
/*
|
2023-12-20 16:17:30 -08:00
|
|
|
* General Media Event Record UUID
|
|
|
|
* CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
|
2023-01-17 21:53:36 -08:00
|
|
|
*/
|
2023-12-20 16:17:30 -08:00
|
|
|
#define CXL_EVENT_GEN_MEDIA_UUID \
|
|
|
|
UUID_INIT(0xfbcd0a77, 0xc260, 0x417f, 0x85, 0xa9, 0x08, 0x8b, 0x16, \
|
|
|
|
0x21, 0xeb, 0xa6)
|
2023-01-17 21:53:36 -08:00
|
|
|
|
2023-12-20 16:17:30 -08:00
|
|
|
/*
|
|
|
|
* DRAM Event Record UUID
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
|
|
|
|
*/
|
|
|
|
#define CXL_EVENT_DRAM_UUID \
|
|
|
|
UUID_INIT(0x601dcbb3, 0x9c06, 0x4eab, 0xb8, 0xaf, 0x4e, 0x9b, 0xfb, \
|
|
|
|
0x5c, 0x96, 0x24)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory Module Event Record UUID
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
|
|
|
|
*/
|
|
|
|
#define CXL_EVENT_MEM_MODULE_UUID \
|
|
|
|
UUID_INIT(0xfe927475, 0xdd59, 0x4339, 0xa5, 0x86, 0x79, 0xba, 0xb1, \
|
|
|
|
0x13, 0xb7, 0x74)
|
2023-01-17 21:53:36 -08:00
|
|
|
|
cxl/events: Trace Memory Sparing Event Record
CXL rev 3.2 section 8.2.10.2.1.4 Table 8-60 defines the Memory Sparing
Event Record.
Determine if the event read is memory sparing record and if so trace the
record.
Memory device shall produce a memory sparing event record
1. After completion of a PPR maintenance operation if the memory sparing
event record enable bit is set (Field: sPPR/hPPR Operation Mode in
Table 8-128/Table 8-131).
2. In response to a query request by the host (see section 8.2.10.7.1.4)
to determine the availability of sparing resources.
The device shall report the resource availability by producing the Memory
Sparing Event Record (see Table 8-60) in which the channel, rank, nibble
mask, bank group, bank, row, column, sub-channel fields are a copy of the
values specified in the request. If the controller does not support
reporting whether a resource is available, and a perform maintenance
operation for memory sparing is issued with query resources set to 1, the
controller shall return invalid input.
Example trace log for produce memory sparing event record on completion
of a soft PPR operation,
cxl_memory_sparing: memdev=mem1 host=0000:0f:00.0 serial=3
log=Informational : time=55045163029
uuid=e71f3a40-2d29-4092-8a39-4d1c966c7c65 len=128 flags='0x1' handle=1
related_handle=0 maint_op_class=2 maint_op_sub_class=1
ld_id=0 head_id=0 : flags='' result=0
validity_flags='CHANNEL|RANK|NIBBLE|BANK GROUP|BANK|ROW|COLUMN'
spare resource avail=1 channel=2 rank=5 nibble_mask=a59c bank_group=2
bank=4 row=13 column=23 sub_channel=0
comp_id=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
comp_id_pldm_valid_flags='' pldm_entity_id=0x00 pldm_resource_id=0x00
Note: For memory sparing event record, fields 'maintenance operation
class' and 'maintenance operation subclass' are defined twice, first
in the common event record (Table 8-55) and second in the memory
sparing event record (Table 8-60). Thus those in the sparing event
record coded as reserved, to be removed when the spec is updated.
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Link: https://patch.msgid.link/20250717101817.2104-5-shiju.jose@huawei.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-07-17 11:18:17 +01:00
|
|
|
/*
|
|
|
|
* Memory Sparing Event Record UUID
|
|
|
|
* CXL rev 3.2 section 8.2.10.2.1.4: Table 8-60
|
|
|
|
*/
|
|
|
|
#define CXL_EVENT_MEM_SPARING_UUID \
|
|
|
|
UUID_INIT(0xe71f3a40, 0x2d29, 0x4092, 0x8a, 0x39, 0x4d, 0x1c, 0x96, \
|
|
|
|
0x6c, 0x7c, 0x65)
|
|
|
|
|
2023-01-17 21:53:36 -08:00
|
|
|
/*
|
|
|
|
* Get Event Records output payload
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.2; Table 8-50
|
|
|
|
*/
|
|
|
|
#define CXL_GET_EVENT_FLAG_OVERFLOW BIT(0)
|
|
|
|
#define CXL_GET_EVENT_FLAG_MORE_RECORDS BIT(1)
|
|
|
|
struct cxl_get_event_payload {
|
|
|
|
u8 flags;
|
|
|
|
u8 reserved1;
|
|
|
|
__le16 overflow_err_count;
|
|
|
|
__le64 first_overflow_timestamp;
|
|
|
|
__le64 last_overflow_timestamp;
|
|
|
|
__le16 record_count;
|
|
|
|
u8 reserved2[10];
|
|
|
|
struct cxl_event_record_raw records[];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.2; Table 8-49
|
|
|
|
*/
|
|
|
|
enum cxl_event_log_type {
|
|
|
|
CXL_EVENT_TYPE_INFO = 0x00,
|
|
|
|
CXL_EVENT_TYPE_WARN,
|
|
|
|
CXL_EVENT_TYPE_FAIL,
|
|
|
|
CXL_EVENT_TYPE_FATAL,
|
|
|
|
CXL_EVENT_TYPE_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear Event Records input payload
|
|
|
|
* CXL rev 3.0 section 8.2.9.2.3; Table 8-51
|
|
|
|
*/
|
|
|
|
struct cxl_mbox_clear_event_payload {
|
|
|
|
u8 event_log; /* enum cxl_event_log_type */
|
|
|
|
u8 clear_flags;
|
|
|
|
u8 nr_recs;
|
|
|
|
u8 reserved[3];
|
|
|
|
__le16 handles[];
|
|
|
|
} __packed;
|
|
|
|
#define CXL_CLEAR_EVENT_MAX_HANDLES U8_MAX
|
|
|
|
|
2022-05-23 23:26:11 -07:00
|
|
|
struct cxl_mbox_get_partition_info {
|
|
|
|
__le64 active_volatile_cap;
|
|
|
|
__le64 active_persistent_cap;
|
|
|
|
__le64 next_volatile_cap;
|
|
|
|
__le64 next_persistent_cap;
|
|
|
|
} __packed;
|
|
|
|
|
2021-09-08 22:13:15 -07:00
|
|
|
struct cxl_mbox_get_lsa {
|
2022-02-25 14:14:56 -08:00
|
|
|
__le32 offset;
|
|
|
|
__le32 length;
|
2021-09-08 22:13:15 -07:00
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct cxl_mbox_set_lsa {
|
2022-02-25 14:14:56 -08:00
|
|
|
__le32 offset;
|
|
|
|
__le32 reserved;
|
2021-09-08 22:13:15 -07:00
|
|
|
u8 data[];
|
|
|
|
} __packed;
|
|
|
|
|
2022-03-30 18:27:18 -07:00
|
|
|
struct cxl_mbox_set_partition_info {
|
|
|
|
__le64 volatile_capacity;
|
|
|
|
u8 flags;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
#define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0)
|
|
|
|
|
2025-02-20 14:02:34 -08:00
|
|
|
/* Get Health Info Output Payload CXL 3.2 Spec 8.2.10.9.3.1 Table 8-148 */
|
|
|
|
struct cxl_mbox_get_health_info_out {
|
|
|
|
u8 health_status;
|
|
|
|
u8 media_status;
|
|
|
|
u8 additional_status;
|
|
|
|
u8 life_used;
|
|
|
|
__le16 device_temperature;
|
|
|
|
__le32 dirty_shutdown_cnt;
|
|
|
|
__le32 corrected_volatile_error_cnt;
|
|
|
|
__le32 corrected_persistent_error_cnt;
|
|
|
|
} __packed;
|
|
|
|
|
2025-01-24 15:35:33 -08:00
|
|
|
/* Set Shutdown State Input Payload CXL 3.2 Spec 8.2.10.9.3.5 Table 8-152 */
|
|
|
|
struct cxl_mbox_set_shutdown_state_in {
|
|
|
|
u8 state;
|
|
|
|
} __packed;
|
|
|
|
|
2023-01-30 15:13:27 +00:00
|
|
|
/* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
|
|
|
|
struct cxl_mbox_set_timestamp_in {
|
|
|
|
__le64 timestamp;
|
|
|
|
|
|
|
|
} __packed;
|
|
|
|
|
2023-04-18 10:39:04 -07:00
|
|
|
/* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */
|
|
|
|
struct cxl_mbox_poison_in {
|
|
|
|
__le64 offset;
|
|
|
|
__le64 length;
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
struct cxl_mbox_poison_out {
|
|
|
|
u8 flags;
|
|
|
|
u8 rsvd1;
|
|
|
|
__le64 overflow_ts;
|
|
|
|
__le16 count;
|
|
|
|
u8 rsvd2[20];
|
|
|
|
struct cxl_poison_record {
|
|
|
|
__le64 address;
|
|
|
|
__le32 length;
|
|
|
|
__le32 rsvd;
|
|
|
|
} __packed record[];
|
|
|
|
} __packed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get Poison List address field encodes the starting
|
|
|
|
* address of poison, and the source of the poison.
|
|
|
|
*/
|
|
|
|
#define CXL_POISON_START_MASK GENMASK_ULL(63, 6)
|
|
|
|
#define CXL_POISON_SOURCE_MASK GENMASK(2, 0)
|
|
|
|
|
|
|
|
/* Get Poison List record length is in units of 64 bytes */
|
|
|
|
#define CXL_POISON_LEN_MULT 64
|
|
|
|
|
|
|
|
/* Kernel defined maximum for a list of poison errors */
|
|
|
|
#define CXL_POISON_LIST_MAX 1024
|
|
|
|
|
|
|
|
/* Get Poison List: Payload out flags */
|
|
|
|
#define CXL_POISON_FLAG_MORE BIT(0)
|
|
|
|
#define CXL_POISON_FLAG_OVERFLOW BIT(1)
|
|
|
|
#define CXL_POISON_FLAG_SCANNING BIT(2)
|
|
|
|
|
|
|
|
/* Get Poison List: Poison Source */
|
|
|
|
#define CXL_POISON_SOURCE_UNKNOWN 0
|
|
|
|
#define CXL_POISON_SOURCE_EXTERNAL 1
|
|
|
|
#define CXL_POISON_SOURCE_INTERNAL 2
|
|
|
|
#define CXL_POISON_SOURCE_INJECTED 3
|
|
|
|
#define CXL_POISON_SOURCE_VENDOR 7
|
|
|
|
|
cxl/memdev: Add support for the Inject Poison mailbox command
CXL devices optionally support the INJECT POISON mailbox command. Add
memdev driver support for the mailbox command.
Per the CXL Specification (3.0 8.2.9.8.4.2), after receiving a valid
inject poison request, the device will return poison when the address
is accessed through the CXL.mem driver. Injecting poison adds the address
to the device's Poison List and the error source is set to Injected.
In addition, the device adds a poison creation event to its internal
Informational Event log, updates the Event Status register, and if
configured, interrupts the host.
Also, per the CXL Specification, it is not an error to inject poison
into an address that already has poison present and no error is
returned from the device.
If the address is not contained in the device's dpa resource, or is
not 64 byte aligned, return -EINVAL without issuing the mbox command.
Poison injection is intended for debug only and will be exposed to
userspace through debugfs. Restrict compilation to CONFIG_DEBUG_FS.
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/241c64115e6bd2effed9c7a20b08b3908dd7be8f.1681874357.git.alison.schofield@intel.com
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-04-18 20:26:25 -07:00
|
|
|
/* Inject & Clear Poison CXL 3.0 Spec 8.2.9.8.4.2/3 */
|
|
|
|
struct cxl_mbox_inject_poison {
|
|
|
|
__le64 address;
|
|
|
|
};
|
|
|
|
|
2023-04-18 20:26:26 -07:00
|
|
|
/* Clear Poison CXL 3.0 Spec 8.2.9.8.4.3 */
|
|
|
|
struct cxl_mbox_clear_poison {
|
|
|
|
__le64 address;
|
|
|
|
u8 write_data[CXL_POISON_LEN_MULT];
|
|
|
|
} __packed;
|
|
|
|
|
2021-09-08 22:12:32 -07:00
|
|
|
/**
|
|
|
|
* struct cxl_mem_command - Driver representation of a memory device command
|
|
|
|
* @info: Command information as it exists for the UAPI
|
|
|
|
* @opcode: The actual bits used for the mailbox protocol
|
|
|
|
* @flags: Set of flags effecting driver behavior.
|
|
|
|
*
|
|
|
|
* * %CXL_CMD_FLAG_FORCE_ENABLE: In cases of error, commands with this flag
|
|
|
|
* will be enabled by the driver regardless of what hardware may have
|
|
|
|
* advertised.
|
|
|
|
*
|
|
|
|
* The cxl_mem_command is the driver's internal representation of commands that
|
|
|
|
* are supported by the driver. Some of these commands may not be supported by
|
|
|
|
* the hardware. The driver will use @info to validate the fields passed in by
|
|
|
|
* the user then submit the @opcode to the hardware.
|
|
|
|
*
|
|
|
|
* See struct cxl_command_info.
|
|
|
|
*/
|
|
|
|
struct cxl_mem_command {
|
|
|
|
struct cxl_command_info info;
|
|
|
|
enum cxl_opcode opcode;
|
|
|
|
u32 flags;
|
|
|
|
#define CXL_CMD_FLAG_FORCE_ENABLE BIT(0)
|
|
|
|
};
|
|
|
|
|
2022-11-30 12:21:36 -07:00
|
|
|
#define CXL_PMEM_SEC_STATE_USER_PASS_SET 0x01
|
|
|
|
#define CXL_PMEM_SEC_STATE_MASTER_PASS_SET 0x02
|
|
|
|
#define CXL_PMEM_SEC_STATE_LOCKED 0x04
|
|
|
|
#define CXL_PMEM_SEC_STATE_FROZEN 0x08
|
|
|
|
#define CXL_PMEM_SEC_STATE_USER_PLIMIT 0x10
|
|
|
|
#define CXL_PMEM_SEC_STATE_MASTER_PLIMIT 0x20
|
|
|
|
|
2022-11-30 12:21:47 -07:00
|
|
|
/* set passphrase input payload */
|
|
|
|
struct cxl_set_pass {
|
|
|
|
u8 type;
|
|
|
|
u8 reserved[31];
|
|
|
|
/* CXL field using NVDIMM define, same length */
|
|
|
|
u8 old_pass[NVDIMM_PASSPHRASE_LEN];
|
|
|
|
u8 new_pass[NVDIMM_PASSPHRASE_LEN];
|
|
|
|
} __packed;
|
|
|
|
|
2022-11-30 12:21:58 -07:00
|
|
|
/* disable passphrase input payload */
|
|
|
|
struct cxl_disable_pass {
|
|
|
|
u8 type;
|
|
|
|
u8 reserved[31];
|
|
|
|
u8 pass[NVDIMM_PASSPHRASE_LEN];
|
|
|
|
} __packed;
|
|
|
|
|
2022-11-30 12:22:32 -07:00
|
|
|
/* passphrase secure erase payload */
|
|
|
|
struct cxl_pass_erase {
|
|
|
|
u8 type;
|
|
|
|
u8 reserved[31];
|
|
|
|
u8 pass[NVDIMM_PASSPHRASE_LEN];
|
|
|
|
} __packed;
|
|
|
|
|
2022-11-30 12:21:47 -07:00
|
|
|
enum {
|
|
|
|
CXL_PMEM_SEC_PASS_MASTER = 0,
|
|
|
|
CXL_PMEM_SEC_PASS_USER,
|
|
|
|
};
|
|
|
|
|
2024-09-05 15:35:47 -07:00
|
|
|
int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox,
|
2022-12-05 20:22:33 -08:00
|
|
|
struct cxl_mbox_cmd *cmd);
|
2023-06-14 18:30:02 -07:00
|
|
|
int cxl_dev_state_identify(struct cxl_memdev_state *mds);
|
2022-05-18 16:34:43 -07:00
|
|
|
int cxl_await_media_ready(struct cxl_dev_state *cxlds);
|
2023-06-14 18:30:02 -07:00
|
|
|
int cxl_enumerate_cmds(struct cxl_memdev_state *mds);
|
cxl: Introduce 'struct cxl_dpa_partition' and 'struct cxl_range_info'
The pending efforts to add CXL Accelerator (type-2) device [1], and
Dynamic Capacity (DCD) support [2], tripped on the
no-longer-fit-for-purpose design in the CXL subsystem for tracking
device-physical-address (DPA) metadata. Trip hazards include:
- CXL Memory Devices need to consider a PMEM partition, but Accelerator
devices with CXL.mem likely do not in the common case.
- CXL Memory Devices enumerate DPA through Memory Device mailbox
commands like Partition Info, Accelerators devices do not.
- CXL Memory Devices that support DCD support more than 2 partitions.
Some of the driver algorithms are awkward to expand to > 2 partition
cases.
- DPA performance data is a general capability that can be shared with
accelerators, so tracking it in 'struct cxl_memdev_state' is no longer
suitable.
- Hardcoded assumptions around the PMEM partition always being index-1
if RAM is zero-sized or PMEM is zero sized.
- 'enum cxl_decoder_mode' is sometimes a partition id and sometimes a
memory property, it should be phased in favor of a partition id and
the memory property comes from the partition info.
Towards cleaning up those issues and allowing a smoother landing for the
aforementioned pending efforts, introduce a 'struct cxl_dpa_partition'
array to 'struct cxl_dev_state', and 'struct cxl_range_info' as a shared
way for Memory Devices and Accelerators to initialize the DPA information
in 'struct cxl_dev_state'.
For now, split a new cxl_dpa_setup() from cxl_mem_create_range_info() to
get the new data structure initialized, and cleanup some qos_class init.
Follow on patches will go further to use the new data structure to
cleanup algorithms that are better suited to loop over all possible
partitions.
cxl_dpa_setup() follows the locking expectations of mutating the device
DPA map, and is suitable for Accelerator drivers to use. Accelerators
likely only have one hardcoded 'ram' partition to convey to the
cxl_core.
Link: http://lore.kernel.org/20241230214445.27602-1-alejandro.lucero-palau@amd.com [1]
Link: http://lore.kernel.org/20241210-dcd-type2-upstream-v8-0-812852504400@intel.com [2]
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alejandro Lucero <alucerop@amd.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Tested-by: Alejandro Lucero <alucerop@amd.com>
Link: https://patch.msgid.link/173864305827.668823.13978794102080021276.stgit@dwillia2-xfh.jf.intel.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2025-02-03 20:24:18 -08:00
|
|
|
int cxl_mem_dpa_fetch(struct cxl_memdev_state *mds, struct cxl_dpa_info *info);
|
2023-06-14 18:30:02 -07:00
|
|
|
struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev);
|
|
|
|
void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,
|
|
|
|
unsigned long *cmds);
|
|
|
|
void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds,
|
|
|
|
unsigned long *cmds);
|
|
|
|
void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status);
|
2023-12-20 16:17:36 -08:00
|
|
|
void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
|
|
|
|
enum cxl_event_log_type type,
|
|
|
|
enum cxl_event_type event_type,
|
|
|
|
const uuid_t *uuid, union cxl_event *evt);
|
2025-02-20 14:02:34 -08:00
|
|
|
int cxl_get_dirty_count(struct cxl_memdev_state *mds, u32 *count);
|
2025-02-20 14:02:33 -08:00
|
|
|
int cxl_arm_dirty_shutdown(struct cxl_memdev_state *mds);
|
2023-06-14 18:30:02 -07:00
|
|
|
int cxl_set_timestamp(struct cxl_memdev_state *mds);
|
|
|
|
int cxl_poison_state_init(struct cxl_memdev_state *mds);
|
2023-04-18 10:39:04 -07:00
|
|
|
int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
|
|
|
|
struct cxl_region *cxlr);
|
2023-04-18 10:39:06 -07:00
|
|
|
int cxl_trigger_poison_list(struct cxl_memdev *cxlmd);
|
cxl/memdev: Add support for the Inject Poison mailbox command
CXL devices optionally support the INJECT POISON mailbox command. Add
memdev driver support for the mailbox command.
Per the CXL Specification (3.0 8.2.9.8.4.2), after receiving a valid
inject poison request, the device will return poison when the address
is accessed through the CXL.mem driver. Injecting poison adds the address
to the device's Poison List and the error source is set to Injected.
In addition, the device adds a poison creation event to its internal
Informational Event log, updates the Event Status register, and if
configured, interrupts the host.
Also, per the CXL Specification, it is not an error to inject poison
into an address that already has poison present and no error is
returned from the device.
If the address is not contained in the device's dpa resource, or is
not 64 byte aligned, return -EINVAL without issuing the mbox command.
Poison injection is intended for debug only and will be exposed to
userspace through debugfs. Restrict compilation to CONFIG_DEBUG_FS.
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/241c64115e6bd2effed9c7a20b08b3908dd7be8f.1681874357.git.alison.schofield@intel.com
Tested-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2023-04-18 20:26:25 -07:00
|
|
|
int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa);
|
2023-04-18 20:26:26 -07:00
|
|
|
int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa);
|
2023-01-30 15:13:27 +00:00
|
|
|
|
2025-05-21 13:47:41 +01:00
|
|
|
#ifdef CONFIG_CXL_EDAC_MEM_FEATURES
|
|
|
|
int devm_cxl_memdev_edac_register(struct cxl_memdev *cxlmd);
|
|
|
|
int devm_cxl_region_edac_register(struct cxl_region *cxlr);
|
2025-05-21 13:47:44 +01:00
|
|
|
int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd, union cxl_event *evt);
|
|
|
|
int cxl_store_rec_dram(struct cxl_memdev *cxlmd, union cxl_event *evt);
|
|
|
|
void devm_cxl_memdev_edac_release(struct cxl_memdev *cxlmd);
|
2025-05-21 13:47:41 +01:00
|
|
|
#else
|
|
|
|
static inline int devm_cxl_memdev_edac_register(struct cxl_memdev *cxlmd)
|
|
|
|
{ return 0; }
|
|
|
|
static inline int devm_cxl_region_edac_register(struct cxl_region *cxlr)
|
|
|
|
{ return 0; }
|
2025-05-21 13:47:44 +01:00
|
|
|
static inline int cxl_store_rec_gen_media(struct cxl_memdev *cxlmd,
|
|
|
|
union cxl_event *evt)
|
|
|
|
{ return 0; }
|
|
|
|
static inline int cxl_store_rec_dram(struct cxl_memdev *cxlmd,
|
|
|
|
union cxl_event *evt)
|
|
|
|
{ return 0; }
|
|
|
|
static inline void devm_cxl_memdev_edac_release(struct cxl_memdev *cxlmd)
|
|
|
|
{ return; }
|
2025-05-21 13:47:41 +01:00
|
|
|
#endif
|
|
|
|
|
2022-04-22 15:58:11 -07:00
|
|
|
#ifdef CONFIG_CXL_SUSPEND
|
|
|
|
void cxl_mem_active_inc(void);
|
|
|
|
void cxl_mem_active_dec(void);
|
|
|
|
#else
|
|
|
|
static inline void cxl_mem_active_inc(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
static inline void cxl_mem_active_dec(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-01 12:24:30 -08:00
|
|
|
|
2023-10-04 18:35:01 -07:00
|
|
|
int cxl_mem_sanitize(struct cxl_memdev *cxlmd, u16 cmd);
|
2023-06-12 11:10:35 -07:00
|
|
|
|
cxl/region: check interleave capability
Since interleave capability is not verified, if the interleave
capability of a target does not match the region need, committing decoder
should have failed at the device end.
In order to checkout this error as quickly as possible, driver needs
to check the interleave capability of target during attaching it to
region.
Per CXL specification r3.1(8.2.4.20.1 CXL HDM Decoder Capability Register),
bits 11 and 12 indicate the capability to establish interleaving in 3, 6,
12 and 16 ways. If these bits are not set, the target cannot be attached to
a region utilizing such interleave ways.
Additionally, bits 8 and 9 represent the capability of the bits used for
interleaving in the address, Linux tracks this in the cxl_port
interleave_mask.
Per CXL specification r3.1(8.2.4.20.13 Decoder Protection):
eIW means encoded Interleave Ways.
eIG means encoded Interleave Granularity.
in HPA:
if eIW is 0 or 8 (interleave ways: 1, 3), all the bits of HPA are used,
the interleave bits are none, the following check is ignored.
if eIW is less than 8 (interleave ways: 2, 4, 8, 16), the interleave bits
start at bit position eIG + 8 and end at eIG + eIW + 8 - 1.
if eIW is greater than 8 (interleave ways: 6, 12), the interleave bits
start at bit position eIG + 8 and end at eIG + eIW - 1.
if the interleave mask is insufficient to cover the required interleave
bits, the target cannot be attached to the region.
Fixes: 384e624bb211 ("cxl/region: Attach endpoint decoders")
Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://patch.msgid.link/20240614084755.59503-2-yaoxt.fnst@fujitsu.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2024-06-14 04:47:54 -04:00
|
|
|
/**
|
|
|
|
* struct cxl_hdm - HDM Decoder registers and cached / decoded capabilities
|
|
|
|
* @regs: mapped registers, see devm_cxl_setup_hdm()
|
|
|
|
* @decoder_count: number of decoders for this port
|
|
|
|
* @target_count: for switch decoders, max downstream port targets
|
|
|
|
* @interleave_mask: interleave granularity capability, see check_interleave_cap()
|
|
|
|
* @iw_cap_mask: bitmask of supported interleave ways, see check_interleave_cap()
|
|
|
|
* @port: mapped cxl_port, see devm_cxl_setup_hdm()
|
|
|
|
*/
|
2022-02-01 12:24:30 -08:00
|
|
|
struct cxl_hdm {
|
|
|
|
struct cxl_component_regs regs;
|
|
|
|
unsigned int decoder_count;
|
|
|
|
unsigned int target_count;
|
|
|
|
unsigned int interleave_mask;
|
cxl/region: check interleave capability
Since interleave capability is not verified, if the interleave
capability of a target does not match the region need, committing decoder
should have failed at the device end.
In order to checkout this error as quickly as possible, driver needs
to check the interleave capability of target during attaching it to
region.
Per CXL specification r3.1(8.2.4.20.1 CXL HDM Decoder Capability Register),
bits 11 and 12 indicate the capability to establish interleaving in 3, 6,
12 and 16 ways. If these bits are not set, the target cannot be attached to
a region utilizing such interleave ways.
Additionally, bits 8 and 9 represent the capability of the bits used for
interleaving in the address, Linux tracks this in the cxl_port
interleave_mask.
Per CXL specification r3.1(8.2.4.20.13 Decoder Protection):
eIW means encoded Interleave Ways.
eIG means encoded Interleave Granularity.
in HPA:
if eIW is 0 or 8 (interleave ways: 1, 3), all the bits of HPA are used,
the interleave bits are none, the following check is ignored.
if eIW is less than 8 (interleave ways: 2, 4, 8, 16), the interleave bits
start at bit position eIG + 8 and end at eIG + eIW + 8 - 1.
if eIW is greater than 8 (interleave ways: 6, 12), the interleave bits
start at bit position eIG + 8 and end at eIG + eIW - 1.
if the interleave mask is insufficient to cover the required interleave
bits, the target cannot be attached to the region.
Fixes: 384e624bb211 ("cxl/region: Attach endpoint decoders")
Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://patch.msgid.link/20240614084755.59503-2-yaoxt.fnst@fujitsu.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
2024-06-14 04:47:54 -04:00
|
|
|
unsigned long iw_cap_mask;
|
2022-02-01 12:24:30 -08:00
|
|
|
struct cxl_port *port;
|
|
|
|
};
|
2022-05-26 12:15:25 -07:00
|
|
|
|
|
|
|
struct seq_file;
|
|
|
|
struct dentry *cxl_debugfs_create_dir(const char *dir);
|
|
|
|
void cxl_dpa_debug(struct seq_file *file, struct cxl_dev_state *cxlds);
|
2021-05-13 22:21:49 -07:00
|
|
|
#endif /* __CXL_MEM_H__ */
|