mirror of
https://github.com/torvalds/linux.git
synced 2024-11-27 06:31:52 +00:00
e62f81bbd2
New Changes: - Refactor to a common struct for DRAM and general media CXL events - Add abstract distance calculation support for CXL - Add CXL maturity map documentation to detail current state of CXL enabling - Add warning on mixed CXL VH and RCH/RCD hierachy to inform unsupported config - Replace ENXIO with EBUSY for inject poison limit reached via debugfs - Replace ENXIO with EBUSY for inject poison cxl-test support - XOR math fixup for DPA to SPA translation. Current math works for MODULO arithmetic where HPA==SPA, however not for XOR decode. - Move pci config read in cxl_dvsec_rr_decode() to avoid unnecessary acess Fixes: - Add a fix to address race condition in CXL memory hotplug notifier - Add missing MODULE_DESCRIPTION() for CXL modules - Fix incorrect vendor debug UUID define -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE5DAy15EJMCV1R6v9YGjFFmlTOEoFAmahJiMACgkQYGjFFmlT OEq8URAArcnzmH9yLvgE2pFOtaKg34vIGDWZGC4R1LpTnFEea04FuJslmxEKNgWo DJgPt9VZ66ump/oIvzcbvgLl/yMCTbnSxt5U6J8G5EmpO50PvxOTeWnEgAYVa0NH Diuzk/aF4GA94T3w+iAOzYx2N36kF+ezsY3/kqSORT7MC+DipSSUaPUiJcjr6FC6 /ZIwkhhRi51ONJ8IgaXD+oEU9kxx7WUEyZoQZrJ9bv8/fGbeEfqy04pz2xDKHmLD rlQjm3l9um67VMsCvZ62Ce14HXqM213jZ3l0FmYjO4GbdXd2+0ZmIRNAb5vvTG9n 5cY8vNsL6fND9FKkxlcRSdzI/O/vV+gcU+jzJxiul0p5fWHh/gaYjVH7fFq3dYc+ vYE5lr97BfyA61bdmylIc2xwDH4yNKVQLZZPVTz5XTxfzBjYCjLPb5vGQKfg/nrB N66wjCIWLfCH6DqusUXem1c6BSrrjob8MwXpg00eBE0AA4ihieiy5fxuApnv9mI2 f809AXRV1k24s5upStZ9iGZSEILBBqiw/KwDyWfRvxjNz36Z1Q2eiXBwbHrVQHBa PFtRPPFsZ9+ouIG/8otFaLwDQdITRdA0+drG8lmJ+gs8239Z3eIMMS0+CYdLDbva S8vo4POOQSS+cVUjLkC9zIxwPaXq96TLIkCtiLI9xUx5eIzv4K0= =HaEG -----END PGP SIGNATURE----- Merge tag 'cxl-for-6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl Pull CXL updates from Dave Jiang: "Core: - A CXL maturity map has been added to the documentation to detail the current state of CXL enabling. It provides the status of the current state of various CXL features to inform current and future contributors of where things are and which areas need contribution. - A notifier handler has been added in order for a newly created CXL memory region to trigger the abstract distance metrics calculation. This should bring parity for CXL memory to the same level vs hotplugged DRAM for NUMA abstract distance calculation. The abstract distance reflects relative performance used for memory tiering handling. - An addition for XOR math has been added to address the CXL DPA to SPA translation. CXL address translation did not support address interleave math with XOR prior to this change. Fixes: - Fix to address race condition in the CXL memory hotplug notifier - Add missing MODULE_DESCRIPTION() for CXL modules - Fix incorrect vendor debug UUID define Misc: - A warning has been added to inform users of an unsupported configuration when mixing CXL VH and RCH/RCD hierarchies - The ENXIO error code has been replaced with EBUSY for inject poison limit reached via debugfs and cxl-test support - Moving the PCI config read in cxl_dvsec_rr_decode() to avoid unnecessary PCI config reads - A refactor to a common struct for DRAM and general media CXL events" * tag 'cxl-for-6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl: cxl/core/pci: Move reading of control register to immediately before usage cxl: Remove defunct code calculating host bridge target positions cxl/region: Verify target positions using the ordered target list cxl: Restore XOR'd position bits during address translation cxl/core: Fold cxl_trace_hpa() into cxl_dpa_to_hpa() cxl/test: Replace ENXIO with EBUSY for inject poison limit reached cxl/memdev: Replace ENXIO with EBUSY for inject poison limit reached cxl/acpi: Warn on mixed CXL VH and RCH/RCD Hierarchy cxl/core: Fix incorrect vendor debug UUID define Documentation: CXL Maturity Map cxl/region: Simplify cxl_region_nid() cxl/region: Support to calculate memory tier abstract distance cxl/region: Fix a race condition in memory hotplug notifier cxl: add missing MODULE_DESCRIPTION() macros cxl/events: Use a common struct for DRAM and General Media events
265 lines
7.0 KiB
C
265 lines
7.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Copyright(c) 2022 Intel Corporation. All rights reserved. */
|
|
#include <linux/debugfs.h>
|
|
#include <linux/device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/pci.h>
|
|
|
|
#include "cxlmem.h"
|
|
#include "cxlpci.h"
|
|
|
|
/**
|
|
* DOC: cxl mem
|
|
*
|
|
* CXL memory endpoint devices and switches are CXL capable devices that are
|
|
* participating in CXL.mem protocol. Their functionality builds on top of the
|
|
* CXL.io protocol that allows enumerating and configuring components via
|
|
* standard PCI mechanisms.
|
|
*
|
|
* The cxl_mem driver owns kicking off the enumeration of this CXL.mem
|
|
* capability. With the detection of a CXL capable endpoint, the driver will
|
|
* walk up to find the platform specific port it is connected to, and determine
|
|
* if there are intervening switches in the path. If there are switches, a
|
|
* secondary action is to enumerate those (implemented in cxl_core). Finally the
|
|
* cxl_mem driver adds the device it is bound to as a CXL endpoint-port for use
|
|
* in higher level operations.
|
|
*/
|
|
|
|
static void enable_suspend(void *data)
|
|
{
|
|
cxl_mem_active_dec();
|
|
}
|
|
|
|
static void remove_debugfs(void *dentry)
|
|
{
|
|
debugfs_remove_recursive(dentry);
|
|
}
|
|
|
|
static int cxl_mem_dpa_show(struct seq_file *file, void *data)
|
|
{
|
|
struct device *dev = file->private;
|
|
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
|
|
|
|
cxl_dpa_debug(file, cxlmd->cxlds);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd,
|
|
struct cxl_dport *parent_dport)
|
|
{
|
|
struct cxl_port *parent_port = parent_dport->port;
|
|
struct cxl_port *endpoint, *iter, *down;
|
|
int rc;
|
|
|
|
/*
|
|
* Now that the path to the root is established record all the
|
|
* intervening ports in the chain.
|
|
*/
|
|
for (iter = parent_port, down = NULL; !is_cxl_root(iter);
|
|
down = iter, iter = to_cxl_port(iter->dev.parent)) {
|
|
struct cxl_ep *ep;
|
|
|
|
ep = cxl_ep_load(iter, cxlmd);
|
|
ep->next = down;
|
|
}
|
|
|
|
/* Note: endpoint port component registers are derived from @cxlds */
|
|
endpoint = devm_cxl_add_port(host, &cxlmd->dev, CXL_RESOURCE_NONE,
|
|
parent_dport);
|
|
if (IS_ERR(endpoint))
|
|
return PTR_ERR(endpoint);
|
|
|
|
rc = cxl_endpoint_autoremove(cxlmd, endpoint);
|
|
if (rc)
|
|
return rc;
|
|
|
|
if (!endpoint->dev.driver) {
|
|
dev_err(&cxlmd->dev, "%s failed probe\n",
|
|
dev_name(&endpoint->dev));
|
|
return -ENXIO;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int cxl_debugfs_poison_inject(void *data, u64 dpa)
|
|
{
|
|
struct cxl_memdev *cxlmd = data;
|
|
|
|
return cxl_inject_poison(cxlmd, dpa);
|
|
}
|
|
|
|
DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_inject_fops, NULL,
|
|
cxl_debugfs_poison_inject, "%llx\n");
|
|
|
|
static int cxl_debugfs_poison_clear(void *data, u64 dpa)
|
|
{
|
|
struct cxl_memdev *cxlmd = data;
|
|
|
|
return cxl_clear_poison(cxlmd, dpa);
|
|
}
|
|
|
|
DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_clear_fops, NULL,
|
|
cxl_debugfs_poison_clear, "%llx\n");
|
|
|
|
static int cxl_mem_probe(struct device *dev)
|
|
{
|
|
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
|
|
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
|
|
struct cxl_dev_state *cxlds = cxlmd->cxlds;
|
|
struct device *endpoint_parent;
|
|
struct cxl_port *parent_port;
|
|
struct cxl_dport *dport;
|
|
struct dentry *dentry;
|
|
int rc;
|
|
|
|
if (!cxlds->media_ready)
|
|
return -EBUSY;
|
|
|
|
/*
|
|
* Someone is trying to reattach this device after it lost its port
|
|
* connection (an endpoint port previously registered by this memdev was
|
|
* disabled). This racy check is ok because if the port is still gone,
|
|
* no harm done, and if the port hierarchy comes back it will re-trigger
|
|
* this probe. Port rescan and memdev detach work share the same
|
|
* single-threaded workqueue.
|
|
*/
|
|
if (work_pending(&cxlmd->detach_work))
|
|
return -EBUSY;
|
|
|
|
dentry = cxl_debugfs_create_dir(dev_name(dev));
|
|
debugfs_create_devm_seqfile(dev, "dpamem", dentry, cxl_mem_dpa_show);
|
|
|
|
if (test_bit(CXL_POISON_ENABLED_INJECT, mds->poison.enabled_cmds))
|
|
debugfs_create_file("inject_poison", 0200, dentry, cxlmd,
|
|
&cxl_poison_inject_fops);
|
|
if (test_bit(CXL_POISON_ENABLED_CLEAR, mds->poison.enabled_cmds))
|
|
debugfs_create_file("clear_poison", 0200, dentry, cxlmd,
|
|
&cxl_poison_clear_fops);
|
|
|
|
rc = devm_add_action_or_reset(dev, remove_debugfs, dentry);
|
|
if (rc)
|
|
return rc;
|
|
|
|
rc = devm_cxl_enumerate_ports(cxlmd);
|
|
if (rc)
|
|
return rc;
|
|
|
|
parent_port = cxl_mem_find_port(cxlmd, &dport);
|
|
if (!parent_port) {
|
|
dev_err(dev, "CXL port topology not found\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
if (resource_size(&cxlds->pmem_res) && IS_ENABLED(CONFIG_CXL_PMEM)) {
|
|
rc = devm_cxl_add_nvdimm(parent_port, cxlmd);
|
|
if (rc) {
|
|
if (rc == -ENODEV)
|
|
dev_info(dev, "PMEM disabled by platform\n");
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
if (dport->rch)
|
|
endpoint_parent = parent_port->uport_dev;
|
|
else
|
|
endpoint_parent = &parent_port->dev;
|
|
|
|
cxl_setup_parent_dport(dev, dport);
|
|
|
|
device_lock(endpoint_parent);
|
|
if (!endpoint_parent->driver) {
|
|
dev_err(dev, "CXL port topology %s not enabled\n",
|
|
dev_name(endpoint_parent));
|
|
rc = -ENXIO;
|
|
goto unlock;
|
|
}
|
|
|
|
rc = devm_cxl_add_endpoint(endpoint_parent, cxlmd, dport);
|
|
unlock:
|
|
device_unlock(endpoint_parent);
|
|
put_device(&parent_port->dev);
|
|
if (rc)
|
|
return rc;
|
|
|
|
/*
|
|
* The kernel may be operating out of CXL memory on this device,
|
|
* there is no spec defined way to determine whether this device
|
|
* preserves contents over suspend, and there is no simple way
|
|
* to arrange for the suspend image to avoid CXL memory which
|
|
* would setup a circular dependency between PCI resume and save
|
|
* state restoration.
|
|
*
|
|
* TODO: support suspend when all the regions this device is
|
|
* hosting are locked and covered by the system address map,
|
|
* i.e. platform firmware owns restoring the HDM configuration
|
|
* that it locked.
|
|
*/
|
|
cxl_mem_active_inc();
|
|
return devm_add_action_or_reset(dev, enable_suspend, NULL);
|
|
}
|
|
|
|
static ssize_t trigger_poison_list_store(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t len)
|
|
{
|
|
bool trigger;
|
|
int rc;
|
|
|
|
if (kstrtobool(buf, &trigger) || !trigger)
|
|
return -EINVAL;
|
|
|
|
rc = cxl_trigger_poison_list(to_cxl_memdev(dev));
|
|
|
|
return rc ? rc : len;
|
|
}
|
|
static DEVICE_ATTR_WO(trigger_poison_list);
|
|
|
|
static umode_t cxl_mem_visible(struct kobject *kobj, struct attribute *a, int n)
|
|
{
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
|
|
struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds);
|
|
|
|
if (a == &dev_attr_trigger_poison_list.attr)
|
|
if (!test_bit(CXL_POISON_ENABLED_LIST,
|
|
mds->poison.enabled_cmds))
|
|
return 0;
|
|
|
|
return a->mode;
|
|
}
|
|
|
|
static struct attribute *cxl_mem_attrs[] = {
|
|
&dev_attr_trigger_poison_list.attr,
|
|
NULL
|
|
};
|
|
|
|
static struct attribute_group cxl_mem_group = {
|
|
.attrs = cxl_mem_attrs,
|
|
.is_visible = cxl_mem_visible,
|
|
};
|
|
|
|
__ATTRIBUTE_GROUPS(cxl_mem);
|
|
|
|
static struct cxl_driver cxl_mem_driver = {
|
|
.name = "cxl_mem",
|
|
.probe = cxl_mem_probe,
|
|
.id = CXL_DEVICE_MEMORY_EXPANDER,
|
|
.drv = {
|
|
.dev_groups = cxl_mem_groups,
|
|
},
|
|
};
|
|
|
|
module_cxl_driver(cxl_mem_driver);
|
|
|
|
MODULE_DESCRIPTION("CXL: Memory Expansion");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_IMPORT_NS(CXL);
|
|
MODULE_ALIAS_CXL(CXL_DEVICE_MEMORY_EXPANDER);
|
|
/*
|
|
* create_endpoint() wants to validate port driver attach immediately after
|
|
* endpoint registration.
|
|
*/
|
|
MODULE_SOFTDEP("pre: cxl_port");
|