CXL Region Creation / HDM decoder programming
Subsystems (3)
cover CXL Region Creation / HDM decoder programming
CXL region creation
-------------------
An interleave set of devices is known in the Compute Express Link [1] specification as a region. In addition to a region being comprised of devices that can be configured in a variety of orders there are other properties that defines a region. This patch series implements both the interfaces to create and configure a region, as well as the algorithm to program the HDM decoders to enable CXL.mem traffic while obeying those configuration parameters. The functionality is realized via a few drivers which are added and described below. In addition to those drivers, cxl_core grows new functionality to support these drivers.
Some version of this functionality has all be posted previously by me, with the exception of the actual HDM decoder programming. It's probably wise to forget those exist, and take my apology in advance for not addressing feedback you may have already given.
There are two branches I am using as development branches. The branch for port/mem driver [2] is fairly solid. The branch for region creation [3] is less baked.
cxl_port
========
The cxl_port driver is implemented within the cxl_port module. While loading of this module is optional, the other new drivers depend on it. The port driver is responsible for all activities around HDM decoder enumeration and programming. Introduced earlier, the concept of a port is an abstraction over CXL components with an upstream port, every host bridge, switch, and endpoint.
cxl_mem
=======
The cxl_mem driver's main job is to walk up the hierarchy to make the determination if it is CXL.mem routed, meaning, all components above it in the hierarchy are participating in the CXL.mem protocol. It is implemented within the cxl_mem module. As the host bridge ports are added by a platform specific driver, such as cxl_acpi, the scope of the mem driver can be reduced to scan for switches and ask cxl_core to work on enumerating them. With this done, the determination as to whether a device is CXL.mem routed can be done simply by checking if the struct device has a driver bound to it.
cxl_region
==========
Region verification and programming state are owned by the cxl_region driver (implemented in the cxl_region module). It relies on cxl_mem to determine if devices are CXL routed, and cxl_port to actually handle the programming of the HDM decoders. Much of the region driver is an implementation of algorithms described in the CXL Type 3 Memory Device Software Guide [4].
Why RFC?
--------
The code is pretty raw. I haven't spend much time tidying things up. While I think most of the architecture is sound, I don't believe anyone but other developers should use this branch. Where I'd really like most eyes:
- Locking and device lifetimes. As time wore on I definitely took some shortcuts there.
- Region configuration. Should values have a default, should they all be explicit?
- What should/shouldn't be in core. I like how this ended up, but at this point I'm fairly biased (CXL.cache pun).
What's missing
---------------
- CXL 2.0 switch support
- Testing on anything but x1 interleave. While QEMU does support multiple host bridges and root ports, it isn't well tested.
- A full topology lock for programming HDM decoders
- Check that HDM decoder programming addresses are correct (must program higher addresses only)
- Volatile regions
- Connection to libnvdimm/labels (Dan is working on this). This includes many aspects, not the least of which is saving the region into the Label Storage Area so that it can be reestablished on reboot.
Here is an example of output when programming a x1 interleave region:
[ 23.959814][ T645] cxl_core:cxl_add_region:406: cxl region0.0:0: Added region0.0:0 to decoder0.0 [ 23.962972][ T645] cxl_port:cxl_commit_decoder:248: cxl_port port1: decoder1.0 [ 23.962972][ T645] Base 0x0000004c00000000 [ 23.962972][ T645] Size 268435456 [ 23.962972][ T645] IG 256 [ 23.962972][ T645] IW 1 [ 23.962972][ T645] TargetList: 0 -1 -1 -1 -1 -1 -1 -1 [ 23.965529][ T645] cxl_port:cxl_commit_decoder:248: cxl_port port3: decoder3.0 [ 23.965529][ T645] Base 0x0000004c00000000 [ 23.965529][ T645] Size 268435456 [ 23.965529][ T645] IG 256 [ 23.965529][ T645] IW 1 [ 23.965529][ T645] TargetList: -1 -1 -1 -1 -1 -1 -1 -1
If you're wondering how I tested this, I've baked it into my cxlctl app [5] and lib [6]. Eventually this will get absorbed by ndctl/cxl-cli/libcxl [7].
To get the detailed errors, trace-cmd can be utilized as such:
trace-cmd record -e cxl ./cxlctl create-region -n -a -s $((256<<20)) /sys/bus/cxl/devices/decoder0.0
[1]: https://www.computeexpresslink.org/download-the-specification
[2]: https://gitlab.com/bwidawsk/linux/-/tree/cxl_port-v2
[3]: https://gitlab.com/bwidawsk/linux/-/tree/cxl_regions-v3
[4]: https://cdrdv2.intel.com/v1/dl/getContent/643805?wapkw=CXL%20memory%20device%20sw%20guide
[5]: https://gitlab.com/bwidawsk-cxl/cxlctl
[6]: https://gitlab.com/bwidawsk-cxl/cxl_rs
[7]: https://lore.kernel.org/linux-cxl/CAPcyv4joKOhTdaRBJVeoOtqhRjBvdtt9902TS=c39=zWTZXvuw@mail.gmail.com/
Ben Widawsky (27):
cxl: Rename CXL_MEM to CXL_PCI
cxl: Move register block enumeration to core cxl/acpi: Map component registers for Root Ports
cxl: Add helper for new drivers
cxl/core: Convert decoder range to resource
cxl: Introduce endpoint decoders
cxl/port: Introduce a port driver
cxl/acpi: Map single port host bridge component registers cxl/core: Store global list of root ports cxl/acpi: Rescan bus at probe completion cxl/core: Store component register base for memdevs
cxl: Flesh out register names
cxl/core: Introduce API to scan switch ports
cxl: Introduce cxl_mem driver
cxl: Disable switch hierarchies for now cxl/region: Add region creation ABI
cxl/region: Introduce concept of region configuration cxl/region: Introduce a cxl_region driver cxl/acpi: Handle address space allocation cxl/region: Address space allocation
cxl/region: Implement XHB verification cxl/region: HB port config verification cxl/region: Record host bridge target list cxl/mem: Store the endpoint's uport
cxl/region: Gather HDM decoder resources
cxl: Program decoders for regions
dont-merge: My QEMU CFMWS is wrong
.clang-format | 3 + Documentation/ABI/testing/sysfs-bus-cxl | 63 ++ .../driver-api/cxl/memory-devices.rst | 28 + drivers/cxl/Kconfig | 28 +- drivers/cxl/Makefile | 8 +- drivers/cxl/acpi.c | 117 +++- drivers/cxl/core/Makefile | 2 + drivers/cxl/core/bus.c | 346 +++++++++- drivers/cxl/core/core.h | 2 + drivers/cxl/core/memdev.c | 7 +- drivers/cxl/core/pci.c | 99 +++ drivers/cxl/core/region.c | 453 +++++++++++++ drivers/cxl/core/regs.c | 62 +- drivers/cxl/cxl.h | 78 ++- drivers/cxl/cxlmem.h | 8 +- drivers/cxl/mem.c | 161 +++++ drivers/cxl/pci.c | 69 +- drivers/cxl/pci.h | 48 +- drivers/cxl/port.c | 490 ++++++++++++++ drivers/cxl/region.c | 626 ++++++++++++++++++ drivers/cxl/region.h | 57 ++ drivers/cxl/trace.h | 54 ++ tools/testing/cxl/Kbuild | 2 + tools/testing/cxl/mock_acpi.c | 4 +- tools/testing/cxl/test/mem.c | 3 +- 25 files changed, 2688 insertions(+), 130 deletions(-) create mode 100644 drivers/cxl/core/pci.c create mode 100644 drivers/cxl/core/region.c create mode 100644 drivers/cxl/mem.c create mode 100644 drivers/cxl/port.c create mode 100644 drivers/cxl/region.c create mode 100644 drivers/cxl/region.h create mode 100644 drivers/cxl/trace.h
Signature · 1 line
2.33.1
RFC PATCH 1/27 cxl: Rename CXL_MEM to CXL_PCI
With the upcoming introduction of a driver to control the non-PCI aspects of CXL.mem, such as interleave set creation and configuration, there will be an opportunity to disconnection control over CXL device memory and CXL device manageability. CXL device manageability is implemented by the cxl_pci driver. Doing this rename allows the CXL memory driver to be enabled by a new config option independently of CXL device manageability through CXL.io/PCI mechanisms.
--- drivers/cxl/Kconfig | 13 ++++++------- drivers/cxl/Makefile | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/cxl/Kconfig +6 -7
@@ -13,14 +13,13 @@ menuconfig CXL_BUS if CXL_BUS -config CXL_MEM - tristate "CXL.mem: Memory Devices" +config CXL_PCI + tristate "PCI manageability" default CXL_BUS help - The CXL.mem protocol allows a device to act as a provider of - "System RAM" and/or "Persistent Memory" that is fully coherent - as if the memory was attached to the typical CPU memory - controller. + The CXL specification defines a set of interfaces which are controlled + through well known PCI configuration mechanisms. Such access is + referred to CXL.io in the specification. Say 'y/m' to enable a driver that will attach to CXL.mem devices for configuration and management primarily via the mailbox interface. See
@@ -31,7 +30,7 @@ config CXL_MEM config CXL_MEM_RAW_COMMANDS bool "RAW Command Interface for Memory Devices" - depends on CXL_MEM + depends on CXL_PCI help Enable CXL RAW command interface.
drivers/cxl/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_CXL_BUS) += core/ -obj-$(CONFIG_CXL_MEM) += cxl_pci.o +obj-$(CONFIG_CXL_PCI) += cxl_pci.o obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o
Signature · 1 line
2.33.1
RFC PATCH 2/27 cxl: Move register block enumeration to core
In reply to Ben WidawskyCXL drivers or cxl_core itself will require the ability to map component registers in order to map HDM decoder resources amongst other things. Much of the register mapping code has already moved into cxl_core. The code to pull the BAR number and block office remained within cxl_pci because there was no need to move it. Upcoming work will require this functionality to be available outside of cxl_pci.
--- drivers/cxl/core/regs.c | 54 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 4 +++ drivers/cxl/pci.c | 52 --------------------------------------- 3 files changed, 58 insertions(+), 52 deletions(-)
drivers/cxl/core/regs.c +54 -0
@@ -5,6 +5,7 @@#include <linux/slab.h> #include <linux/pci.h> #include <cxlmem.h> +#include <pci.h> /** * DOC: cxl registers
@@ -247,3 +248,56 @@ int cxl_map_device_regs(struct pci_dev *pdev,return 0 ; }EXPORT_SYMBOL_GPL (cxl_map_device_regs); + +static void cxl_decode_regblock (u32 reg_lo,u32 reg_hi, +struct cxl_register_map *map) +{ + map->block_offset = + ((u64 )reg_hi <<32 ) | (reg_lo &CXL_REGLOC_ADDR_MASK ); + map->barno =FIELD_GET (CXL_REGLOC_BIR_MASK , reg_lo); + map->reg_type =FIELD_GET (CXL_REGLOC_RBI_MASK , reg_lo); +} + +/** +* cxl_find_regblock() - Locate register blocks by type +* @pdev: The CXL PCI device to enumerate. +* @type: Register Block Indicator id +* @map: Enumeration output, clobbered on error +* +* Return: 0 if register block enumerated, negative error code otherwise +* +* A CXL DVSEC may additional point one or more register blocks, search +* for them by @type. +*/ +int cxl_find_regblock (struct pci_dev *pdev,enum cxl_regloc_type type, +struct cxl_register_map *map) +{ +u32 regloc_size, regblocks; +int regloc, i; + + regloc =pci_find_dvsec_capability (pdev,PCI_DVSEC_VENDOR_ID_CXL , +PCI_DVSEC_ID_CXL_REGLOC_DVSEC_ID ); +if (!regloc) +return -ENXIO ; + +pci_read_config_dword (pdev, regloc +PCI_DVSEC_HEADER1 , ®loc_size); + regloc_size =FIELD_GET (PCI_DVSEC_HEADER1_LENGTH_MASK , regloc_size); + + regloc +=PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET ; + regblocks = (regloc_size -PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET ) /8 ; + +for (i =0 ; i < regblocks; i++, regloc +=8 ) { +u32 reg_lo, reg_hi; + +pci_read_config_dword (pdev, regloc, ®_lo); +pci_read_config_dword (pdev, regloc +4 , ®_hi); + +cxl_decode_regblock (reg_lo, reg_hi, map); + +if (map->reg_type == type) +return 0 ; + } + +return -ENODEV ; +} +EXPORT_SYMBOL_GPL (cxl_find_regblock);
drivers/cxl/cxl.h +4 -0
@@ -161,6 +161,10 @@ int cxl_map_device_regs(struct pci_dev *pdev,struct cxl_device_regs *regs, struct cxl_register_map *map); +enum cxl_regloc_type ; +int cxl_find_regblock (struct pci_dev *pdev,enum cxl_regloc_type type, +struct cxl_register_map *map); +#define CXL_RESOURCE_NONE ((resource_size_t) -1)#define CXL_TARGET_STRLEN 20
drivers/cxl/pci.c +0 -52
58 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC PATCH 3/27 cxl/acpi: Map component registers for Root Ports
In reply to Ben WidawskyWith the addition of cxl_find_register_block() in cxl_core, it becomes trivial to complete the TODO left for mapping the component registers of root ports. None of the CXL drivers currently use component registers of downstream ports (which is what a CXL 2.0 Root Port is). As such, there should be no functional change.
--- drivers/cxl/acpi.c | 10 ++++++++-- drivers/cxl/pci.h | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/cxl/acpi.c +8 -2
@@ -7,6 +7,7 @@#include <linux/acpi.h> #include <linux/pci.h> #include "cxl.h" +#include "pci.h" static struct acpi_table_header *acpi_cedt;
@@ -206,11 +207,13 @@ static resource_size_t get_chbcr(struct acpi_cedt_chbs *chbs) __mock int match_add_root_ports(struct pci_dev *pdev, void *data) { +resource_size_t creg =CXL_RESOURCE_NONE ;struct cxl_walk_context *ctx = data;struct pci_bus *root_bus = ctx->root;struct cxl_port *port = ctx->port;int type =pci_pcie_type (pdev);struct device *dev = ctx->dev; +struct cxl_register_map map;u32 lnkcap, port_num;int rc;
@@ -224,9 +227,12 @@ __mock int match_add_root_ports(struct pci_dev *pdev, void *data) &lnkcap) != PCIBIOS_SUCCESSFUL)return 0 ; -/* TODO walk DVSEC to find component register base */ + rc =cxl_find_regblock (pdev,CXL_REGLOC_RBI_COMPONENT , &map); +if (!rc) + creg =cxl_reg_block (pdev, &map); + port_num =FIELD_GET (PCI_EXP_LNKCAP_PN , lnkcap); - rc =cxl_add_dport (port, &pdev->dev, port_num,CXL_RESOURCE_NONE ); + rc =cxl_add_dport (port, &pdev->dev, port_num, creg);if (rc) { ctx->error = rc;return rc;
drivers/cxl/pci.h +4 -0
@@ -31,4 +31,8 @@ enum cxl_regloc_type {#define CXL_REGLOC_RBI_MASK GENMASK(15, 8)#define CXL_REGLOC_ADDR_MASK GENMASK(31, 16) +#define cxl_reg_block (pdev, map) \ + ((resource_size_t)(pci_resource_start(pdev, (map)->barno) + \ + (map)->block_offset)) +#endif /* __CXL_PCI_H__ */
Signature · 1 line
2.33.1
RFC PATCH 4/27 cxl: Add helper for new drivers
In reply to Ben WidawskyMany CXL drivers simply want to register and unregister themselves. module_driver already supported this. A simple wrapper around that reduces a decent amount of boilerplate in upcoming patches.
--- drivers/cxl/cxl.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/cxl/cxl.h +3 -0
@@ -317,6 +317,9 @@ int __cxl_driver_register(struct cxl_driver *cxl_drv, struct module *owner,#define cxl_driver_register (x) __cxl_driver_register(x, THIS_MODULE, KBUILD_MODNAME)void cxl_driver_unregister (struct cxl_driver *cxl_drv); +#define module_cxl_driver (__cxl_driver) \ + module_driver(__cxl_driver, cxl_driver_register, cxl_driver_unregister) +#define CXL_DEVICE_NVDIMM_BRIDGE 1#define CXL_DEVICE_NVDIMM 2
Signature · 1 line
2.33.1
RFC PATCH 5/27 cxl/core: Convert decoder range to resource
In reply to Ben WidawskyRegions will use the resource API in order to help manage allocated space. As regions are children of the decoder, it makes sense that the parent host the main resource to be suballocated by the region.
--- drivers/cxl/acpi.c | 12 ++++-------- drivers/cxl/core/bus.c | 4 ++-- drivers/cxl/cxl.h | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-)
drivers/cxl/acpi.c +4 -8
@@ -126,10 +126,9 @@ static void cxl_add_cfmws_decoders(struct device *dev, cxld->flags =cfmws_to_decoder_flags (cfmws->restrictions); cxld->target_type =CXL_DECODER_EXPANDER ; - cxld->range = (struct range ) { - .start = cfmws->base_hpa, - .end = cfmws->base_hpa + cfmws->window_size -1 , - }; + cxld->res = (struct resource )DEFINE_RES_MEM_NAMED (cfmws->base_hpa, + cfmws->window_size, +"cfmws" ); cxld->interleave_ways =CFMWS_INTERLEAVE_WAYS (cfmws); cxld->interleave_granularity =CFMWS_INTERLEAVE_GRANULARITY (cfmws);
@@ -339,10 +338,7 @@ static int add_host_bridge_uport(struct device *match, void *arg) cxld->interleave_ways =1 ; cxld->interleave_granularity =PAGE_SIZE ; cxld->target_type =CXL_DECODER_EXPANDER ; - cxld->range = (struct range ) { - .start =0 , - .end =-1 , - }; + cxld->res = (struct resource )DEFINE_RES_MEM (0 ,0 );device_lock (&port->dev); dport =list_first_entry (&port->dports,typeof (*dport), list);
drivers/cxl/core/bus.c +2 -2
@@ -47,7 +47,7 @@ static ssize_t start_show(struct device *dev, struct device_attribute *attr, {struct cxl_decoder *cxld =to_cxl_decoder (dev); -return sysfs_emit (buf,"%#llx\n" , cxld->range.start); +return sysfs_emit (buf,"%#llx\n" , cxld->res.start); }static DEVICE_ATTR_RO (start);
@@ -56,7 +56,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr, {struct cxl_decoder *cxld =to_cxl_decoder (dev); -return sysfs_emit (buf,"%#llx\n" ,range_len (&cxld->range)); +return sysfs_emit (buf,"%#llx\n" ,resource_size (&cxld->res)); }static DEVICE_ATTR_RO (size);
drivers/cxl/cxl.h +2 -2
@@ -195,7 +195,7 @@ enum cxl_decoder_type {* struct cxl_decoder - CXL address range decode configuration * @dev: this decoder's device * @id: kernel device name id -* @range: address range considered by this decoder +* @res: address space resources considered by this decoder * @interleave_ways: number of cxl_dports in this decode * @interleave_granularity: data stride per dport * @target_type: accelerator vs expander (type2 vs type3) selector
@@ -206,7 +206,7 @@ enum cxl_decoder_type {struct cxl_decoder {struct device dev;int id; -struct range range; +struct resource res;int interleave_ways;int interleave_granularity;enum cxl_decoder_type target_type;
Signature · 1 line
2.33.1
RFC PATCH 6/27 cxl: Introduce endpoint decoders
In reply to Ben WidawskyEndpoints have decoders too. It is useful to share the same infrastructure from cxl_core. Endpoints do not have dports (downstream targets), only the underlying physical medium. As a result, some special casing is needed.
There is no functional change introduced yet as endpoints don't actually enumerate decoders yet.
--- drivers/cxl/core/bus.c | 40 ++++++++++++++++++++++++++++++++-------- drivers/cxl/cxl.h | 3 ++- 2 files changed, 34 insertions(+), 9 deletions(-)
drivers/cxl/core/bus.c +32 -8
@@ -175,6 +175,12 @@ static const struct attribute_group *cxl_decoder_switch_attribute_groups[] = { NULL, }; +static const struct attribute_group *cxl_decoder_endpoint_attribute_groups[] = { + &cxl_decoder_base_attribute_group, + &cxl_base_attribute_group, +NULL , +}; +static void cxl_decoder_release (struct device *dev) {struct cxl_decoder *cxld =to_cxl_decoder (dev);
@@ -184,6 +190,12 @@ static void cxl_decoder_release(struct device *dev)kfree (cxld); } +static const struct device_type cxl_decoder_endpoint_type = { + .name ="cxl_decoder_endpoint" , + .release = cxl_decoder_release, + .groups = cxl_decoder_endpoint_attribute_groups, +}; +static const struct device_type cxl_decoder_switch_type = { .name ="cxl_decoder_switch" , .release = cxl_decoder_release,
@@ -196,6 +208,11 @@ static const struct device_type cxl_decoder_root_type = { .groups = cxl_decoder_root_attribute_groups, }; +static bool is_endpoint_decoder (struct device *dev) +{ +return dev->type == &cxl_decoder_endpoint_type; +} +bool is_root_decoder (struct device *dev) {return dev->type == &cxl_decoder_root_type;
@@ -483,7 +500,8 @@ static int decoder_populate_targets(struct cxl_decoder *cxld,return rc; } -struct cxl_decoder *cxl_decoder_alloc (struct cxl_port *port,int nr_targets) +struct cxl_decoder *cxl_decoder_alloc (struct cxl_port *port, +unsigned int nr_targets) {struct cxl_decoder *cxld, cxld_const_init = { .nr_targets = nr_targets,
@@ -491,7 +509,7 @@ struct cxl_decoder *cxl_decoder_alloc(struct cxl_port *port, int nr_targets)struct device *dev;int rc =0 ; -if (nr_targets >CXL_DECODER_MAX_INTERLEAVE || nr_targets <1 ) +if (nr_targets >CXL_DECODER_MAX_INTERLEAVE )return ERR_PTR (-EINVAL ); cxld =kzalloc (struct_size (cxld, target, nr_targets),GFP_KERNEL );
@@ -510,8 +528,11 @@ struct cxl_decoder *cxl_decoder_alloc(struct cxl_port *port, int nr_targets) dev->parent = &port->dev; dev->bus = &cxl_bus_type; +/* Endpoints don't have a target list */ +if (nr_targets ==0 ) + dev->type = &cxl_decoder_endpoint_type;/* root ports do not have a cxl_port_type parent */ -if (port->dev.parent->type == &cxl_port_type) +else if (port->dev.parent->type == &cxl_port_type) dev->type = &cxl_decoder_switch_type;else dev->type = &cxl_decoder_root_type;
@@ -538,12 +559,15 @@ int cxl_decoder_add(struct cxl_decoder *cxld, int *target_map)if (cxld->interleave_ways <1 )return -EINVAL ; - port =to_cxl_port (cxld->dev.parent); - rc =decoder_populate_targets (cxld, port, target_map); -if (rc) -return rc; - dev = &cxld->dev; + + port =to_cxl_port (cxld->dev.parent); +if (!is_endpoint_decoder (dev)) { + rc =decoder_populate_targets (cxld, port, target_map); +if (rc) +return rc; + } + rc =dev_set_name (dev,"decoder%d.%d" , port->id, cxld->id);if (rc)return rc;
drivers/cxl/cxl.h +2 -1
@@ -293,7 +293,8 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport, int port_id,struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev); -struct cxl_decoder *cxl_decoder_alloc (struct cxl_port *port,int nr_targets); +struct cxl_decoder *cxl_decoder_alloc (struct cxl_port *port, +unsigned int nr_targets);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);int cxl_decoder_autoremove (struct device *host,struct cxl_decoder *cxld);
Signature · 1 line
2.33.1
RFC PATCH 7/27 cxl/port: Introduce a port driver
In reply to Ben WidawskyThe CXL port driver will be responsible for managing the decoder resources contained within the port. It will also provide APIs that other drivers will consume for managing these resources.
This patch has no functional change because no driver is registering new ports and the root ports that are already registered should be skipped.
--- .../driver-api/cxl/memory-devices.rst | 5 + drivers/cxl/Makefile | 2 + drivers/cxl/acpi.c | 1 + drivers/cxl/core/bus.c | 3 + drivers/cxl/core/regs.c | 6 +- drivers/cxl/cxl.h | 30 ++- drivers/cxl/port.c | 241 ++++++++++++++++++ 7 files changed, 279 insertions(+), 9 deletions(-) create mode 100644 drivers/cxl/port.c
Documentation/driver-api/cxl/memory-devices.rst +5 -0
@@ -28,6 +28,11 @@ CXL Memory Device .. kernel-doc:: drivers/cxl/pci.c :internal: +CXL Port +-------- +.. kernel-doc:: drivers/cxl/port.c + :doc: cxl port + CXL Core -------- .. kernel-doc:: drivers/cxl/cxl.h
drivers/cxl/Makefile +2 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_CXL_BUS) += core/ +obj-$(CONFIG_CXL_MEM) += cxl_port.o obj-$(CONFIG_CXL_PCI) += cxl_pci.o obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o
@@ -7,3 +8,4 @@ obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o cxl_pci-y := pci.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o +cxl_port-y := port.o
drivers/cxl/acpi.c +1 -0
@@ -491,3 +491,4 @@ static struct platform_driver cxl_acpi_driver = {module_platform_driver (cxl_acpi_driver);MODULE_LICENSE ("GPL v2" );MODULE_IMPORT_NS (CXL ); +MODULE_SOFTDEP ("pre: cxl_port" );
drivers/cxl/core/bus.c +3 -0
@@ -266,6 +266,7 @@ struct cxl_port *to_cxl_port(struct device *dev)return NULL ; return container_of(dev, struct cxl_port, dev); } +EXPORT_SYMBOL_GPL (to_cxl_port);static void unregister_port (void *_port) {
@@ -632,6 +633,8 @@ static int cxl_device_id(struct device *dev)return CXL_DEVICE_NVDIMM_BRIDGE ;if (dev->type == &cxl_nvdimm_type)return CXL_DEVICE_NVDIMM ; +if (dev->type == &cxl_port_type) +return CXL_DEVICE_PORT ;return 0 ; }
drivers/cxl/core/regs.c +3 -3
@@ -159,9 +159,8 @@ void cxl_probe_device_regs(struct device *dev, void __iomem *base, }EXPORT_SYMBOL_GPL (cxl_probe_device_regs); -static void __iomem *devm_cxl_iomap_block (struct device *dev, -resource_size_t addr, -resource_size_t length) +void __iomem *devm_cxl_iomap_block (struct device *dev,resource_size_t addr, +resource_size_t length) {void __iomem *ret_val;struct resource *res;
@@ -180,6 +179,7 @@ static void __iomem *devm_cxl_iomap_block(struct device *dev,return ret_val; } +EXPORT_SYMBOL_GPL (devm_cxl_iomap_block); int cxl_map_component_regs(struct pci_dev *pdev, struct cxl_component_regs *regs,
drivers/cxl/cxl.h +24 -6
@@ -17,6 +17,9 @@* (port-driver, region-driver, nvdimm object-drivers... etc). */ +/* CXL 2.0 8.2.4 CXL Component Register Layout and Definition */ +#define CXL_COMPONENT_REG_BLOCK_SIZE SZ_64K +/* CXL 2.0 8.2.5 CXL.cache and CXL.mem Registers*/ #define CXL_CM_OFFSET 0x1000#define CXL_CM_CAP_HDR_OFFSET 0x0
@@ -36,11 +39,22 @@#define CXL_HDM_DECODER_CAP_OFFSET 0x0#define CXL_HDM_DECODER_COUNT_MASK GENMASK(3, 0)#define CXL_HDM_DECODER_TARGET_COUNT_MASK GENMASK(7, 4) -#define CXL_HDM_DECODER0_BASE_LOW_OFFSET 0x10 -#define CXL_HDM_DECODER0_BASE_HIGH_OFFSET 0x14 -#define CXL_HDM_DECODER0_SIZE_LOW_OFFSET 0x18 -#define CXL_HDM_DECODER0_SIZE_HIGH_OFFSET 0x1c -#define CXL_HDM_DECODER0_CTRL_OFFSET 0x20 +#define CXL_HDM_DECODER_INTERLEAVE_11_8 BIT(8) +#define CXL_HDM_DECODER_INTERLEAVE_14_12 BIT(9) +#define CXL_HDM_DECODER_CTRL_OFFSET 0x4 +#define CXL_HDM_DECODER_ENABLE BIT(1) +#define CXL_HDM_DECODER0_BASE_LOW_OFFSET (i) (0x20 * (i) + 0x10) +#define CXL_HDM_DECODER0_BASE_HIGH_OFFSET (i) (0x20 * (i) + 0x14) +#define CXL_HDM_DECODER0_SIZE_LOW_OFFSET (i) (0x20 * (i) + 0x18) +#define CXL_HDM_DECODER0_SIZE_HIGH_OFFSET (i) (0x20 * (i) + 0x1c) +#define CXL_HDM_DECODER0_CTRL_OFFSET (i) (0x20 * (i) + 0x20) +#define CXL_HDM_DECODER0_CTRL_IG_MASK GENMASK(3, 0) +#define CXL_HDM_DECODER0_CTRL_IW_MASK GENMASK(7, 4) +#define CXL_HDM_DECODER0_CTRL_COMMIT BIT(9) +#define CXL_HDM_DECODER0_CTRL_COMMITTED BIT(10) +#define CXL_HDM_DECODER0_CTRL_TYPE BIT(12) +#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24) +#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)static inline int cxl_hdm_decoder_count (u32 cap_hdr) {
@@ -164,6 +178,8 @@ int cxl_map_device_regs(struct pci_dev *pdev,enum cxl_regloc_type ;int cxl_find_regblock (struct pci_dev *pdev,enum cxl_regloc_type type,struct cxl_register_map *map); +void __iomem *devm_cxl_iomap_block (struct device *dev,resource_size_t addr, +resource_size_t length);#define CXL_RESOURCE_NONE ((resource_size_t) -1)#define CXL_TARGET_STRLEN 20
@@ -178,7 +194,8 @@ int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type,#define CXL_DECODER_F_TYPE2 BIT(2)#define CXL_DECODER_F_TYPE3 BIT(3)#define CXL_DECODER_F_LOCK BIT(4) -#define CXL_DECODER_F_MASK GENMASK(4, 0) +#define CXL_DECODER_F_EN BIT(5) +#define CXL_DECODER_F_MASK GENMASK(5, 0)enum cxl_decoder_type {CXL_DECODER_ACCELERATOR =2 ,
@@ -323,6 +340,7 @@ void cxl_driver_unregister(struct cxl_driver *cxl_drv);#define CXL_DEVICE_NVDIMM_BRIDGE 1#define CXL_DEVICE_NVDIMM 2 +#define CXL_DEVICE_PORT 3#define MODULE_ALIAS_CXL (type) MODULE_ALIAS("cxl:t" __stringify(type) "*")#define CXL_MODALIAS_FMT "cxl:t%d"
drivers/cxl/port.c new file +241 -0
241 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC PATCH 8/27 cxl/acpi: Map single port host bridge component registers
In reply to Ben WidawskyNow that the port driver exists and is able to do proper decoder enumeration of the component registers, it becomes trivial to use that for host bridge uports. For reasons out of scope, a functional change would be visible if the HDM decoder was programmed by BIOS to values other than the full address range. Similarly if a type2 device was connected to this root port and programmed by BIOS, that can now be acted upon accordingly.
--- drivers/cxl/acpi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/cxl/acpi.c +24 -1
@@ -280,12 +280,14 @@ static int add_host_bridge_uport(struct device *match, void *arg)struct cxl_port *root_port = arg;struct device *host = root_port->dev.parent;struct acpi_device *bridge =to_cxl_host_bridge (host, match); +struct cxl_component_reg_map map;struct acpi_pci_root *pci_root;struct cxl_walk_context ctx;int single_port_map[1 ], rc;struct cxl_decoder *cxld;struct cxl_dport *dport;struct cxl_port *port; +void __iomem *crb;if (!bridge)return 0 ;
@@ -318,10 +320,31 @@ static int add_host_bridge_uport(struct device *match, void *arg)return -ENODEV ;if (ctx.error)return ctx.error; +/* +* If the host bridge has more than 1 root port, it must have registers +* controlling the HDM decoders. Those will be enumerated by the port +* driver. +*/ if (ctx.count >1 )return 0 ; -/* TODO: Scan CHBCR for HDM Decoder resources */ +/* +* If the single ported host bridge has a component register block, +* simply let the port driver handle the decoder enumeration. +* +* Host bridge component registers live in the system's physical address +* space. +*/ + crb =ioremap (dport->component_reg_phys,CXL_COMPONENT_REG_BLOCK_SIZE ); +if (crb) { +cxl_probe_component_regs (&root_port->dev, crb, &map); +iounmap (crb); +if (map.hdm_decoder.valid) { +dev_dbg (host, +"Found single port host bridge with component registers\n" ); +return 0 ; + } + }/* * Per the CXL specification (8.2.5.12 CXL HDM Decoder Capability
Signature · 1 line
2.33.1
RFC PATCH 9/27 cxl/core: Store global list of root ports
In reply to Ben WidawskyCXL root ports (the downstream port to a host bridge) are to be enumerated by a platform specific driver. In the case of ACPI compliant systems, this is like the cxl_acpi driver. Root ports are the first CXL spec defined component that can be "found" by that platform specific driver.
By storing a list of these root ports components in lower levels of the topology (switches and endpoints), have a mechanism to walk up their device hierarchy to find an enumerated root port. This will be necessary for region programming.
--- drivers/cxl/acpi.c | 4 ++-- drivers/cxl/core/bus.c | 34 +++++++++++++++++++++++++++++++++- drivers/cxl/cxl.h | 5 ++++- tools/testing/cxl/mock_acpi.c | 4 ++-- 4 files changed, 41 insertions(+), 6 deletions(-)
drivers/cxl/acpi.c +2 -2
@@ -231,7 +231,7 @@ __mock int match_add_root_ports(struct pci_dev *pdev, void *data) creg =cxl_reg_block (pdev, &map); port_num =FIELD_GET (PCI_EXP_LNKCAP_PN , lnkcap); - rc =cxl_add_dport (port, &pdev->dev, port_num, creg); + rc =cxl_add_dport (port, &pdev->dev, port_num, creg, true);if (rc) { ctx->error = rc;return rc;
@@ -406,7 +406,7 @@ static int add_host_bridge_dport(struct device *match, void *arg)dev_dbg (host,"No CHBS found for Host Bridge: %s\n" ,dev_name (match)); - rc =cxl_add_dport (root_port, match, uid,get_chbcr (chbs)); + rc =cxl_add_dport (root_port, match, uid,get_chbcr (chbs), false);if (rc) {dev_err (host,"failed to add downstream port: %s\n" ,dev_name (match));
drivers/cxl/core/bus.c +33 -1
@@ -25,6 +25,8 @@*/ static DEFINE_IDA (cxl_port_ida); +static LIST_HEAD (cxl_root_ports); +static DECLARE_RWSEM (root_port_sem);static ssize_t devtype_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -268,12 +270,31 @@ struct cxl_port *to_cxl_port(struct device *dev) }EXPORT_SYMBOL_GPL (to_cxl_port); +struct cxl_dport *cxl_get_root_dport (struct device *dev) +{ +struct cxl_dport *ret =NULL ; +struct cxl_dport *dport; + +down_read (&root_port_sem); +list_for_each_entry (dport, &cxl_root_ports, root_port_link) { +if (dport->dport == dev) { + ret = dport; +break ; + } + } + +up_read (&root_port_sem); +return ret; +} +EXPORT_SYMBOL_GPL (cxl_get_root_dport); +static void unregister_port (void *_port) {struct cxl_port *port = _port;struct cxl_dport *dport;device_lock (&port->dev); +down_read (&root_port_sem);list_for_each_entry (dport, &port->dports, list) {char link_name[CXL_TARGET_STRLEN ];
@@ -281,7 +302,10 @@ static void unregister_port(void *_port) dport->port_id) >= CXL_TARGET_STRLEN)continue ;sysfs_remove_link (&port->dev.kobj, link_name); + +list_del_init (&dport->root_port_link); } +up_read (&root_port_sem);device_unlock (&port->dev);device_unregister (&port->dev); }
@@ -431,12 +455,13 @@ static int add_dport(struct cxl_port *port, struct cxl_dport *new)* @dport_dev: firmware or PCI device representing the dport * @port_id: identifier for this dport in a decoder's target list * @component_reg_phys: optional location of CXL component registers +* @root_port: is this a root port (hostbridge downstream) * * Note that all allocations and links are undone by cxl_port deletion * and release. */ int cxl_add_dport (struct cxl_port *port,struct device *dport_dev,int port_id, -resource_size_t component_reg_phys) +resource_size_t component_reg_phys,bool root_port) {char link_name[CXL_TARGET_STRLEN ];struct cxl_dport *dport;
@@ -451,6 +476,7 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id,return -ENOMEM ;INIT_LIST_HEAD (&dport->list); +INIT_LIST_HEAD (&dport->root_port_link); dport->dport =get_device (dport_dev); dport->port_id = port_id; dport->component_reg_phys = component_reg_phys;
@@ -464,6 +490,12 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id,if (rc) goto err; +if (root_port) { +down_write (&root_port_sem); +list_add_tail (&dport->root_port_link, &cxl_root_ports); +up_write (&root_port_sem); + } +return 0 ; err:cxl_dport_release (dport);
drivers/cxl/cxl.h +4 -1
@@ -291,6 +291,7 @@ struct cxl_port {* @component_reg_phys: downstream port component registers * @port: reference to cxl_port that contains this downstream port * @list: node for a cxl_port's list of cxl_dport instances +* @root_port_link: node for global list of root ports */ struct cxl_dport {struct device *dport;
@@ -298,6 +299,7 @@ struct cxl_dport {resource_size_t component_reg_phys;struct cxl_port *port;struct list_head list; +struct list_head root_port_link; };struct cxl_port *to_cxl_port (struct device *dev);
@@ -306,7 +308,8 @@ struct cxl_port *devm_cxl_add_port(struct device *host, struct device *uport, struct cxl_port *parent_port);int cxl_add_dport (struct cxl_port *port,struct device *dport,int port_id, -resource_size_t component_reg_phys); +resource_size_t component_reg_phys,bool root_port); +struct cxl_dport *cxl_get_root_dport (struct device *dev);struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev);
tools/testing/cxl/mock_acpi.c +2 -2
@@ -57,7 +57,7 @@ static int match_add_root_port(struct pci_dev *pdev, void *data)/* TODO walk DVSEC to find component register base */ port_num =FIELD_GET (PCI_EXP_LNKCAP_PN , lnkcap); - rc =cxl_add_dport (port, &pdev->dev, port_num,CXL_RESOURCE_NONE ); + rc =cxl_add_dport (port, &pdev->dev, port_num,CXL_RESOURCE_NONE , true);if (rc) {dev_err (dev,"failed to add dport: %s (%d)\n" ,dev_name (&pdev->dev), rc);
@@ -78,7 +78,7 @@ static int mock_add_root_port(struct platform_device *pdev, void *data)struct device *dev = ctx->dev;int rc; - rc =cxl_add_dport (port, &pdev->dev, pdev->id,CXL_RESOURCE_NONE ); + rc =cxl_add_dport (port, &pdev->dev, pdev->id,CXL_RESOURCE_NONE , true);if (rc) {dev_err (dev,"failed to add dport: %s (%d)\n" ,dev_name (&pdev->dev), rc);
Signature · 1 line
2.33.1
RFC PATCH 10/27 cxl/acpi: Rescan bus at probe completion
In reply to Ben WidawskyEnsure that devices being probed before cxl_acpi has completed will get a second chance.
CXL drivers are brought up through two enumerable, asynchronous mechanism. The leaf nodes in the CXL topology, endpoints, are enumerated via PCI headers. The root node's enumeration is platform specific. The current defacto mechanism for enumerating the root node is through the presence of an ACPI device, ACPI0017.
The primary job of a cxl_mem driver is to determine if CXL.mem traffic can be routed to/from the PCIe device that it is being probed. A prerequisite in this determination is that all CXL components in the path from root to leaf are capable of routing CXL.mem traffic. If the cxl_mem driver is probed before cxl_acpi is complete the driver will be unable to make this determination. To address this, cxl_acpi (or in the future, another platform specific driver) will rescan all devices to make sure the ordering is correct.
--- drivers/cxl/acpi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/cxl/acpi.c +19 -1
@@ -451,6 +451,14 @@ static u32 cedt_instance(struct platform_device *pdev)return U32_MAX ; } +static void bus_rescan (struct work_struct *work) +{ +if (bus_rescan_devices (&cxl_bus_type)) +pr_err ("Failed to rescan CXL bus\n" ); +} + +static DECLARE_WORK(deferred_bus_rescan, bus_rescan); +static int cxl_acpi_probe (struct platform_device *pdev) {int rc;
@@ -484,9 +492,19 @@ static int cxl_acpi_probe(struct platform_device *pdev)if (rc) goto out; -if (IS_ENABLED (CONFIG_CXL_PMEM )) +if (IS_ENABLED (CONFIG_CXL_PMEM )) { rc =device_for_each_child (&root_port->dev, root_port, add_root_nvdimm_bridge); +if (rc) + goto out; + } + +/* +* While ACPI is scanning hostbridge ports, switches and memory devices +* may have been probed. Those devices will need to know whether the +* hostbridge is CXL capable. +*/ +schedule_work (&deferred_bus_rescan); out:acpi_put_table (acpi_cedt);
Signature · 1 line
2.33.1
RFC PATCH 11/27 cxl/core: Store component register base for memdevs
In reply to Ben WidawskyBake component registers into the memdev creation API in order to be able to use them as part of driver probing.
Component register base addresses are obtained through PCI mechanisms. As such it makes most sense for the cxl_pci driver to obtain that address. In order to reuse the port driver for enumerating decoder resources for an endpoint, it is desirable to be able to add the endpoint as a port. Unfortunately, by the time an endpoint driver would run, it no longer has any concept of the underlying PCI device (this is done intentionally to provide separation between drivers).
--- drivers/cxl/core/memdev.c | 5 +++-- drivers/cxl/cxlmem.h | 5 ++++- drivers/cxl/pci.c | 17 ++++++++++++++++- tools/testing/cxl/test/mem.c | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-)
drivers/cxl/core/memdev.c +3 -2
@@ -276,8 +276,8 @@ static const struct file_operations cxl_memdev_fops = { .llseek = noop_llseek, }; -struct cxl_memdev * -devm_cxl_add_memdev (struct cxl_mem *cxlm) +struct cxl_memdev *devm_cxl_add_memdev (struct cxl_mem *cxlm, +resource_size_t component_reg_phys) {struct cxl_memdev *cxlmd;struct device *dev;
@@ -298,6 +298,7 @@ devm_cxl_add_memdev(struct cxl_mem *cxlm)* needed as this is ordered with cdev_add() publishing the device. */ cxlmd->cxlm = cxlm; + cxlmd->creg_base = component_reg_phys; cdev = &cxlmd->cdev; rc =cdev_device_add (cdev, dev);
drivers/cxl/cxlmem.h +4 -1
@@ -35,12 +35,14 @@* @cdev: char dev core object for ioctl operations * @cxlm: pointer to the parent device driver data * @id: id number of this memdev instance. +* @creg_base: register base of component registers */ struct cxl_memdev {struct device dev;struct cdev cdev;struct cxl_mem *cxlm;int id; +resource_size_t creg_base; };static inline struct cxl_memdev *to_cxl_memdev (struct device *dev)
@@ -48,7 +50,8 @@ static inline struct cxl_memdev *to_cxl_memdev(struct device *dev) return container_of(dev, struct cxl_memdev, dev); } -struct cxl_memdev *devm_cxl_add_memdev (struct cxl_mem *cxlm); +struct cxl_memdev *devm_cxl_add_memdev (struct cxl_mem *cxlm, +resource_size_t component_reg_phys);/** * struct cxl_mbox_cmd - A command to be submitted to hardware.
drivers/cxl/pci.c +16 -1
@@ -421,6 +421,7 @@ static int cxl_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,static int cxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) { +resource_size_t creg =CXL_RESOURCE_NONE ;struct cxl_register_map map;struct cxl_memdev *cxlmd;struct cxl_mem *cxlm;
@@ -465,7 +466,21 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; - cxlmd =devm_cxl_add_memdev (cxlm); +/* +* If the component registers can't be found, the cxl_pci driver may +* still be useful for management functions so don't return an error. +* +* XXX: Creating the device is going to kick of the cxl_mem probing. +* That probe requires the component registers. Therefore, the register +* block must always be found first. +*/ + rc =cxl_find_regblock (pdev,CXL_REGLOC_RBI_COMPONENT , &map); +if (rc) +dev_warn (&cxlmd->dev,"No component registers (%d)\n" , rc); +else + creg =cxl_reg_block (pdev, &map); + + cxlmd =devm_cxl_add_memdev (cxlm, creg);if (IS_ERR (cxlmd))return PTR_ERR (cxlmd);
tools/testing/cxl/test/mem.c +2 -1
@@ -227,7 +227,8 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)if (rc)return rc; - cxlmd =devm_cxl_add_memdev (cxlm); +/* TODO: mock component registers, or... */ + cxlmd =devm_cxl_add_memdev (cxlm,CXL_RESOURCE_NONE );if (IS_ERR (cxlmd))return PTR_ERR (cxlmd);
Signature · 1 line
2.33.1
RFC PATCH 12/27 cxl: Flesh out register names
In reply to Ben WidawskyGet a better naming scheme in place for upcoming additions. To solidify the schema, add all the DVSEC identifiers to start with.
---
See:
https://lore.kernel.org/linux-pci/[email protected]/
--- drivers/cxl/core/regs.c | 14 ++++++++------ drivers/cxl/pci.h | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 14 deletions(-)
drivers/cxl/core/regs.c +8 -6
@@ -253,9 +253,11 @@ static void cxl_decode_regblock(u32 reg_lo, u32 reg_hi, struct cxl_register_map *map) { map->block_offset = - ((u64 )reg_hi <<32 ) | (reg_lo &CXL_REGLOC_ADDR_MASK ); - map->barno =FIELD_GET (CXL_REGLOC_BIR_MASK , reg_lo); - map->reg_type =FIELD_GET (CXL_REGLOC_RBI_MASK , reg_lo); + ((u64 )reg_hi <<32 ) | + (reg_lo &DVSEC_REGISTER_LOCATOR_BLOCK_OFFSET_LOW_MASK ); + map->barno =FIELD_GET (DVSEC_REGISTER_LOCATOR_BIR_MASK , reg_lo); + map->reg_type = +FIELD_GET (DVSEC_REGISTER_LOCATOR_BLOCK_IDENTIFIER_MASK , reg_lo); }/**
@@ -276,15 +278,15 @@ int cxl_find_regblock(struct pci_dev *pdev, enum cxl_regloc_type type,int regloc, i; regloc =pci_find_dvsec_capability (pdev,PCI_DVSEC_VENDOR_ID_CXL , -PCI_DVSEC_ID_CXL_REGLOC_DVSEC_ID ); +CXL_DVSEC_REGISTER_LOCATOR );if (!regloc)return -ENXIO ;pci_read_config_dword (pdev, regloc +PCI_DVSEC_HEADER1 , ®loc_size); regloc_size =FIELD_GET (PCI_DVSEC_HEADER1_LENGTH_MASK , regloc_size); - regloc +=PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET ; - regblocks = (regloc_size -PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET ) /8 ; + regloc +=DVSEC_REGISTER_LOCATOR_BLOCK1_OFFSET ; + regblocks = (regloc_size -DVSEC_REGISTER_LOCATOR_BLOCK1_OFFSET ) /8 ;for (i =0 ; i < regblocks; i++, regloc +=8 ) {u32 reg_lo, reg_hi;
drivers/cxl/pci.h +30 -8
@@ -7,17 +7,36 @@/* * See section 8.1 Configuration Space Registers in the CXL 2.0 -* Specification +* Specification. Names are taken straight from the specification with "CXL" and +* "DVSEC" redundancies removed. */ #define PCI_DVSEC_HEADER1_LENGTH_MASK GENMASK(31, 20)#define PCI_DVSEC_VENDOR_ID_CXL 0x1E98 -#define PCI_DVSEC_ID_CXL 0x0 -#define PCI_DVSEC_ID_CXL_REGLOC_DVSEC_ID 0x8 -#define PCI_DVSEC_ID_CXL_REGLOC_BLOCK1_OFFSET 0xC +/* 8.1.3: PCIe DVSEC for CXL Device */ +#define CXL_DVSEC_PCIE_DEVICE 0 -/* BAR Indicator Register (BIR) */ -#define CXL_REGLOC_BIR_MASK GENMASK(2, 0) +/* 8.1.4: Non-CXL Function Map DVSEC */ +#define CXL_DVSEC_FUNCTION_MAP 2 + +/* 8.1.5: CXL 2.0 Extensions DVSEC for Ports */ +#define CXL_DVSEC_PORT_EXTENSIONS 3 + +/* 8.1.6: GPF DVSEC for CXL Port */ +#define CXL_DVSEC_PORT_GPF 4 + +/* 8.1.7: GPF DVSEC for CXL Device */ +#define CXL_DVSEC_DEVICE_GPF 5 + +/* 8.1.8: PCIe DVSEC for Flex Bus Port */ +#define CXL_DVSEC_PCIE_FLEXBUS_PORT 7 + +/* 8.1.9: Register Locator DVSEC */ +#define CXL_DVSEC_REGISTER_LOCATOR 8 +#define DVSEC_REGISTER_LOCATOR_BLOCK1_OFFSET 0xC +#define DVSEC_REGISTER_LOCATOR_BIR_MASK GENMASK(2, 0) +#define DVSEC_REGISTER_LOCATOR_BLOCK_IDENTIFIER_MASK GENMASK(15, 8) +#define DVSEC_REGISTER_LOCATOR_BLOCK_OFFSET_LOW_MASK GENMASK(31, 16)/* Register Block Identifier (RBI) */ enum cxl_regloc_type {
@@ -28,8 +47,11 @@ enum cxl_regloc_type { CXL_REGLOC_RBI_TYPES }; -#define CXL_REGLOC_RBI_MASK GENMASK(15, 8) -#define CXL_REGLOC_ADDR_MASK GENMASK(31, 16) +/* 8.1.10: MLD DVSEC */ +#define CXL_DVSEC_MLD 9 + +/* 14.16.1 CXL Device Test Capability Advertisement */ +#define CXL_DVSEC_PCIE_TEST_CAPABILITY 10#define cxl_reg_block (pdev, map) \ ((resource_size_t)(pci_resource_start(pdev, (map)->barno) + \
Signature · 1 line
2.33.1
RFC PATCH 13/27 cxl/core: Introduce API to scan switch ports
In reply to Ben WidawskyThe CXL drivers encapsulate the components that direct memory traffic in an entity known as a cxl_port. Compute Express Link specifies three such
components: hostbridge (ie. a collection of root ports), switches, and endpoints. There are currently drivers that create these ports for the hostbridges and the endpoints (cxl_acpi and cxl_mem). The new API introduced allows callers to initiate a scan down from the hostbridge and create ports for switches in the CXL topology.
The intended user of this API is for endpoint devices. An endpoint device will need to determine if it is CXL.mem capable, which requires all components in the path from hostbridge to the endpoint to be CXL.mem capable. Once an endpoint device determines it's connected to a CXL capable root port, it can call this API to fill in all the ports in between the hostbridge and itself.
--- .../driver-api/cxl/memory-devices.rst | 6 + drivers/cxl/core/Makefile | 1 + drivers/cxl/core/bus.c | 135 ++++++++++++++++++ drivers/cxl/core/pci.c | 99 +++++++++++++ drivers/cxl/cxl.h | 1 + drivers/cxl/pci.h | 6 + tools/testing/cxl/Kbuild | 1 + 7 files changed, 249 insertions(+) create mode 100644 drivers/cxl/core/pci.c
Documentation/driver-api/cxl/memory-devices.rst +6 -0
@@ -47,6 +47,12 @@ CXL Core .. kernel-doc:: drivers/cxl/core/bus.c :identifiers: +.. kernel-doc:: drivers/cxl/core/pci.c + :doc: cxl pci + +.. kernel-doc:: drivers/cxl/core/pci.c + :identifiers: + .. kernel-doc:: drivers/cxl/core/pmem.c :doc: cxl pmem
drivers/cxl/core/Makefile +1 -0
@@ -7,3 +7,4 @@ cxl_core-y += pmem.o cxl_core-y += regs.o cxl_core-y += memdev.o cxl_core-y += mbox.o +cxl_core-y += pci.o
drivers/cxl/core/bus.c +135 -0
147 lines not on this page · raw message
drivers/cxl/core/pci.c new file +99 -0
99 lines not on this page · raw message
drivers/cxl/cxl.h +1 -0
@@ -306,6 +306,7 @@ struct cxl_port *to_cxl_port(struct device *dev);struct cxl_port *devm_cxl_add_port (struct device *host,struct device *uport,resource_size_t component_reg_phys,struct cxl_port *parent_port); +void cxl_scan_ports (struct cxl_dport *root_port);int cxl_add_dport (struct cxl_port *port,struct device *dport,int port_id,resource_size_t component_reg_phys,bool root_port);
drivers/cxl/pci.h +6 -0
@@ -15,6 +15,8 @@/* 8.1.3: PCIe DVSEC for CXL Device */ #define CXL_DVSEC_PCIE_DEVICE 0 +#define DVSEC_PCIE_DEVICE_CONTROL_OFFSET 0xC +#define DVSEC_PCIE_DEVICE_MEM_ENABLE BIT(2)/* 8.1.4: Non-CXL Function Map DVSEC */ #define CXL_DVSEC_FUNCTION_MAP 2
@@ -57,4 +59,8 @@ enum cxl_regloc_type { ((resource_size_t)(pci_resource_start (pdev, (map)->barno) + \ (map)->block_offset)) +bool is_cxl_switch_usp (struct device *dev); +bool is_cxl_switch_dsp (struct device *dev); +bool is_cxl_mem_enabled (struct pci_dev *pdev); +#endif /* __CXL_PCI_H__ */
tools/testing/cxl/Kbuild +1 -0
@@ -31,6 +31,7 @@ cxl_core-y += $(CXL_CORE_SRC)/pmem.o cxl_core-y += $(CXL_CORE_SRC)/regs.o cxl_core-y += $(CXL_CORE_SRC)/memdev.o cxl_core-y += $(CXL_CORE_SRC)/mbox.o +cxl_core-y += $(CXL_CORE_SRC)/pci.o cxl_core-y += config_check.o cxl_core-y += mock_pmem.o
Signature · 1 line
2.33.1
RFC PATCH 14/27 cxl: Introduce cxl_mem driver
In reply to Ben WidawskyAdd a driver that is capable of determining whether a device is in a CXL.mem routed part of the topology.
This driver allows a higher level driver - such as one controlling CXL regions, which is itself a set of CXL devices - to easily determine if the CXL devices are CXL.mem capable by checking if the driver has bound. CXL memory device services may also be provided by this driver though none are needed as of yet. cxl_mem also plays the part of registering itself as an endpoint port, which is a required step to enumerate the device's HDM decoder resources.
As part of this patch, find_dport_by_dev() is promoted to the cxl_core's set of APIs for use by the new driver.
--- .../driver-api/cxl/memory-devices.rst | 3 + drivers/cxl/Kconfig | 15 ++ drivers/cxl/Makefile | 2 + drivers/cxl/acpi.c | 17 +- drivers/cxl/core/bus.c | 19 +++ drivers/cxl/core/core.h | 1 + drivers/cxl/core/memdev.c | 2 +- drivers/cxl/cxl.h | 3 + drivers/cxl/cxlmem.h | 2 + drivers/cxl/mem.c | 155 ++++++++++++++++++ 10 files changed, 202 insertions(+), 17 deletions(-) create mode 100644 drivers/cxl/mem.c
Documentation/driver-api/cxl/memory-devices.rst +3 -0
@@ -28,6 +28,9 @@ CXL Memory Device .. kernel-doc:: drivers/cxl/pci.c :internal: +.. kernel-doc:: drivers/cxl/mem.c + :doc: cxl mem + CXL Port -------- .. kernel-doc:: drivers/cxl/port.c
drivers/cxl/Kconfig +15 -0
@@ -28,6 +28,21 @@ config CXL_PCI If unsure say 'm'. +config CXL_MEM + tristate "CXL.mem: Memory Devices" + default CXL_BUS + help + The CXL.mem protocol allows a device to act as a provider of + "System RAM" and/or "Persistent Memory" that is fully coherent + as if the memory was attached to the typical CPU memory controller. + This is known as HDM "Host-managed Device Memory". + + Say 'y/m' to enable a driver that will attach to CXL.mem devices for + memory expansion and control of HDM. See Chapter 9.13 in the CXL 2.0 + specification for a detailed description of HDM. + + If unsure say 'm'. + config CXL_MEM_RAW_COMMANDS bool "RAW Command Interface for Memory Devices" depends on CXL_PCI
drivers/cxl/Makefile +2 -0
@@ -2,9 +2,11 @@ obj-$(CONFIG_CXL_BUS) += core/ obj-$(CONFIG_CXL_MEM) += cxl_port.o obj-$(CONFIG_CXL_PCI) += cxl_pci.o +obj-$(CONFIG_CXL_MEM) += cxl_mem.o obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o +cxl_mem-y := mem.o cxl_pci-y := pci.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o
drivers/cxl/acpi.c +1 -16
@@ -243,21 +243,6 @@ __mock int match_add_root_ports(struct pci_dev *pdev, void *data)return 0 ; } -static struct cxl_dport *find_dport_by_dev (struct cxl_port *port,struct device *dev) -{ -struct cxl_dport *dport; - -device_lock (&port->dev); -list_for_each_entry (dport, &port->dports, list) -if (dport->dport == dev) { -device_unlock (&port->dev); -return dport; - } - -device_unlock (&port->dev); -return NULL ; -} - __mock struct acpi_device *to_cxl_host_bridge(struct device *host,struct device *dev) {
@@ -292,7 +277,7 @@ static int add_host_bridge_uport(struct device *match, void *arg)if (!bridge)return 0 ; - dport =find_dport_by_dev (root_port, match); + dport =cxl_find_dport_by_dev (root_port, match);if (!dport) {dev_dbg (host,"host bridge expected and not found\n" );return -ENODEV ;
drivers/cxl/core/bus.c +19 -0
@@ -638,6 +638,23 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id, }EXPORT_SYMBOL_GPL (cxl_add_dport); +struct cxl_dport *cxl_find_dport_by_dev (struct cxl_port *port, +struct device *dev) +{ +struct cxl_dport *dport; + +device_lock (&port->dev); +list_for_each_entry (dport, &port->dports, list) +if (dport->dport == dev) { +device_unlock (&port->dev); +return dport; + } + +device_unlock (&port->dev); +return NULL ; +} +EXPORT_SYMBOL_GPL (cxl_find_dport_by_dev); +static int decoder_populate_targets (struct cxl_decoder *cxld,struct cxl_port *port,int *target_map) {
@@ -802,6 +819,8 @@ static int cxl_device_id(struct device *dev)return CXL_DEVICE_NVDIMM ;if (dev->type == &cxl_port_type)return CXL_DEVICE_PORT ; +if (dev->type == &cxl_memdev_type) +return CXL_DEVICE_MEMORY_EXPANDER ;return 0 ; }
drivers/cxl/core/core.h +1 -0
@@ -6,6 +6,7 @@extern const struct device_type cxl_nvdimm_bridge_type;extern const struct device_type cxl_nvdimm_type; +extern const struct device_type cxl_memdev_type;extern struct attribute_group cxl_base_attribute_group;
drivers/cxl/core/memdev.c +1 -1
@@ -127,7 +127,7 @@ static const struct attribute_group *cxl_memdev_attribute_groups[] = { NULL, }; -static const struct device_type cxl_memdev_type = { +const struct device_type cxl_memdev_type = { .name ="cxl_memdev" , .release = cxl_memdev_release, .devnode = cxl_memdev_devnode,
drivers/cxl/cxl.h +3 -0
@@ -311,6 +311,8 @@ void cxl_scan_ports(struct cxl_dport *root_port);int cxl_add_dport (struct cxl_port *port,struct device *dport,int port_id,resource_size_t component_reg_phys,bool root_port);struct cxl_dport *cxl_get_root_dport (struct device *dev); +struct cxl_dport *cxl_find_dport_by_dev (struct cxl_port *port, +struct device *dev);struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev);
@@ -345,6 +347,7 @@ void cxl_driver_unregister(struct cxl_driver *cxl_drv);#define CXL_DEVICE_NVDIMM_BRIDGE 1#define CXL_DEVICE_NVDIMM 2#define CXL_DEVICE_PORT 3 +#define CXL_DEVICE_MEMORY_EXPANDER 4#define MODULE_ALIAS_CXL (type) MODULE_ALIAS("cxl:t" __stringify(type) "*")#define CXL_MODALIAS_FMT "cxl:t%d"
drivers/cxl/cxlmem.h +2 -0
@@ -36,6 +36,7 @@* @cxlm: pointer to the parent device driver data * @id: id number of this memdev instance. * @creg_base: register base of component registers +* @root_port: Hostbridge's root port connected to this endpoint */ struct cxl_memdev {struct device dev;
@@ -43,6 +44,7 @@ struct cxl_memdev {struct cxl_mem *cxlm;int id;resource_size_t creg_base; +struct cxl_dport *root_port; };static inline struct cxl_memdev *to_cxl_memdev (struct device *dev)
drivers/cxl/mem.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC PATCH 15/27 cxl: Disable switch hierarchies for now
In reply to Ben WidawskySwitches aren't supported by the region driver yet. If a device finds itself under a switch it will not bind a driver so that it cannot be used later for region creation/configuration.
--- drivers/cxl/mem.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/cxl/mem.c +5 -0
@@ -118,6 +118,11 @@ static int cxl_mem_probe(struct device *dev) goto out; } +/* FIXME: Add true switch support */ +dev_err (dev,"Devices behind switches are currently unsupported\n" ); + rc = -ENODEV ; + goto err_out; +/* Walk down from the root port and add all switches */ cxl_scan_ports (ctx.root_port);
Signature · 1 line
2.33.1
RFC PATCH 16/27 cxl/region: Add region creation ABI
In reply to Ben WidawskyRegions are created as a child of the decoder that encompasses an address space with constraints. Regions have a number of attributes that must be configured before the region can be activated.
The ABI is not meant to be secure, but is meant to avoid accidental races. As a result, a buggy process may create a region by name that was allocated by a different process. However, multiple processes which are trying not to race with each other shouldn't need special synchronization to do so.
// Allocate a new region name
region = $(cat /sys/bus/cxl/devices/decoder0.0/create_region)
// Create a new region by name
echo $region > /sys/bus/cxl/devices/decoder0.0/create_region
// Region now exists in sysfs
stat -t /sys/bus/cxl/devices/decoder0.0/$region
// Delete the region, and name
echo $region > /sys/bus/cxl/devices/decoder0.0/delete_region
After creating a region, it will show up in sysfs
/sys/bus/cxl/devices/
├── decoder0.0 -> ../../../devices/platform/ACPI0017:00/root0/decoder0.0 ├── decoder1.0 -> ../../../devices/platform/ACPI0017:00/root0/port1/decoder1.0 ├── decoder2.0 -> ../../../devices/platform/ACPI0017:00/root0/port1/port2/decoder2.0 ├── mem0 -> ../../../devices/pci0000:34/0000:34:00.0/0000:35:00.0/mem0 ├── pmem0 -> ../../../devices/pci0000:34/0000:34:00.0/0000:35:00.0/mem0/pmem0 ├── port1 -> ../../../devices/platform/ACPI0017:00/root0/port1 ├── port2 -> ../../../devices/platform/ACPI0017:00/root0/port1/port2 └── root0 -> ../../../devices/platform/ACPI0017:00/root0
--- Documentation/ABI/testing/sysfs-bus-cxl | 23 +++ .../driver-api/cxl/memory-devices.rst | 11 ++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/bus.c | 84 +++++++++++ drivers/cxl/core/region.c | 139 ++++++++++++++++++ drivers/cxl/cxl.h | 9 ++ drivers/cxl/region.h | 37 +++++ tools/testing/cxl/Kbuild | 1 + 8 files changed, 305 insertions(+) create mode 100644 drivers/cxl/core/region.c create mode 100644 drivers/cxl/region.h
Documentation/ABI/testing/sysfs-bus-cxl +23 -0
@@ -127,3 +127,26 @@ Description: memory (type-3). The 'target_type' attribute indicates the current setting which may dynamically change based on what memory regions are activated in this decode hierarchy. + +What: /sys/bus/cxl/devices/decoderX.Y/create_region +Date: June, 2021 +KernelVersion: v5.16 +Contact: [email protected] +Description: + Creates a new CXL region. Writing a value of the form + "regionX.Y:Z" will create a new uninitialized region that will + be mapped by the CXL decoderX.Y. Reading from this node will + return a newly allocated region name. In order to create a + region (writing) you must use a value returned from reading the + node. Regions must be subsequently configured and bound to a + region driver before they can be used. + +What: /sys/bus/cxl/devices/decoderX.Y/delete_region +Date: June, 2021 +KernelVersion: v5.16 +Contact: [email protected] +Description: + Deletes the named region. A region must be unbound from the + region driver before being deleted. The attributes expects a + region in the form "regionX.Y:Z". The region's name, allocated + by reading create_region, will also be released.
Documentation/driver-api/cxl/memory-devices.rst +11 -0
@@ -65,6 +65,17 @@ CXL Core .. kernel-doc:: drivers/cxl/core/mbox.c :doc: cxl mbox +CXL Regions +----------- +.. kernel-doc:: drivers/cxl/region.h + :identifiers: + +.. kernel-doc:: drivers/cxl/core/region.c + :doc: cxl core region + +.. kernel-doc:: drivers/cxl/core/region.c + :identifiers: + External Interfaces ===================
drivers/cxl/core/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_CXL_BUS) += cxl_core.o ccflags-y += -DDEFAULT_SYMBOL_NAMESPACE=CXL -I$(srctree)/drivers/cxl cxl_core-y := bus.o cxl_core-y += pmem.o +cxl_core-y += region.o cxl_core-y += regs.o cxl_core-y += memdev.o cxl_core-y += mbox.o
drivers/cxl/core/bus.c +84 -0
113 lines not on this page · raw message
drivers/cxl/core/region.c new file +139 -0
139 lines not on this page · raw message
drivers/cxl/cxl.h +9 -0
@@ -217,6 +217,7 @@ enum cxl_decoder_type {* @interleave_granularity: data stride per dport * @target_type: accelerator vs expander (type2 vs type3) selector * @flags: memory type capabilities and locking +* @region_ida: allocator for region ids. * @nr_targets: number of elements in @target * @target: active ordered target list in current decoder configuration */
@@ -228,6 +229,7 @@ struct cxl_decoder {int interleave_granularity;enum cxl_decoder_type target_type;unsigned long flags; +struct ida region_ida;const int nr_targets;struct cxl_dport *target[]; };
@@ -302,6 +304,13 @@ struct cxl_dport {struct list_head root_port_link; }; +bool is_cxl_region (struct device *dev); +struct cxl_region *to_cxl_region (struct device *dev); +struct cxl_region *cxl_alloc_region (struct cxl_decoder *cxld, +int interleave_ways); +int cxl_add_region (struct cxl_decoder *cxld,struct cxl_region *region); +int cxl_delete_region (struct cxl_decoder *cxld,const char *region); +struct cxl_port *to_cxl_port (struct device *dev); struct cxl_port *devm_cxl_add_port(struct device *host, struct device *uport, resource_size_t component_reg_phys,
drivers/cxl/region.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2021 Intel Corporation. */ +#ifndef __CXL_REGION_H__ +#define __CXL_REGION_H__ + +#include <linux/uuid.h> + +#include "cxl.h" + +/** +* struct cxl_region - CXL region +* @dev: This region's device. +* @id: This regions id. Id is globally unique across all regions. +* @list: Node in decoder's region list. +* @res: Address space consumed by this region. +* @size: Size of the region determined from LSA or userspace. +* @uuid: The UUID for this region. +* @eniw: Number of interleave ways this region is configured for. +* @ig: Interleave granularity of region +* @targets: The memory devices comprising the region. +*/ +struct cxl_region { +struct device dev; +int id; +struct list_head list; + +struct { +struct resource *res; +u64 size; +uuid_t uuid; +int eniw; +int ig; +struct cxl_memdev *targets[CXL_DECODER_MAX_INTERLEAVE ]; + }; +}; + +#endif
tools/testing/cxl/Kbuild +1 -0
@@ -32,6 +32,7 @@ cxl_core-y += $(CXL_CORE_SRC)/regs.o cxl_core-y += $(CXL_CORE_SRC)/memdev.o cxl_core-y += $(CXL_CORE_SRC)/mbox.o cxl_core-y += $(CXL_CORE_SRC)/pci.o +cxl_core-y += $(CXL_CORE_SRC)/region.o cxl_core-y += config_check.o cxl_core-y += mock_pmem.o
Signature · 1 line
2.33.1
RFC PATCH 17/27 cxl/region: Introduce concept of region configuration
In reply to Ben WidawskyThe region creation APIs create a vacant region. Configuring the region works in the same way as similar subsystems such as devdax. Sysfs attrs will be provided to allow userspace to configure the region. Finally once all configuration is complete, userspace may activate the region.
Introduced here are the most basic attributes needed to configure a region. Details of these attribute are described in the ABI Documentation.
A example is provided below:
/sys/bus/cxl/devices/region0.0:0
├── interleave_granularity ├── interleave_ways ├── offset ├── size ├── subsystem -> ../../../../../../bus/cxl ├── target0 ├── uevent └── uuid
--- Documentation/ABI/testing/sysfs-bus-cxl | 40 ++++ drivers/cxl/core/region.c | 295 ++++++++++++++++++++++++ 2 files changed, 335 insertions(+)
Documentation/ABI/testing/sysfs-bus-cxl +40 -0
@@ -150,3 +150,43 @@ Description: region driver before being deleted. The attributes expects a region in the form "regionX.Y:Z". The region's name, allocated by reading create_region, will also be released. + +What: /sys/bus/cxl/devices/decoderX.Y/regionX.Y:Z/offset +Date: June, 2021 +KernelVersion: v5.16 +Contact: [email protected] +Description: + (RO) A region resides within an address space that is claimed by + a decoder. Region space allocation is handled by the driver, but + the offset may be read by userspace tooling in order to + determine fragmentation, and available size for new regions. + +What: +/sys/bus/cxl/devices/decoderX.Y/regionX.Y:Z/{interleave,size,uuid,target[0-15]} +Date: June, 2021 +KernelVersion: v5.16 +Contact: [email protected] +Description: + (RW) Configuring regions requires a minimal set of parameters in + order for the subsequent bind operation to succeed. The + following parameters are defined: + + == ======================================================== + interleave_granularity Mandatory. Number of consecutive bytes + each device in the interleave set will claim. The + possible interleave granularity values are determined by + the CXL spec and the participating devices. + interleave_ways Mandatory. Number of devices participating in the + region. Each device will provide 1/interleave of storage + for the region. + size Manadatory. Phsyical address space the region will + consume. + target Mandatory. Memory devices are the backing storage for a + region. There will be N targets based on the number of + interleave ways that the top level decoder is configured + for. Each target must be set with a memdev device ie. + 'mem1'. This attribute only becomes available after + setting the 'interleave' attribute. + uuid Optional. A unique identifier for the region. If none is + selected, the kernel will create one. + == ========================================================
drivers/cxl/core/region.c +295 -0
323 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC PATCH 18/27 cxl/region: Introduce a cxl_region driver
In reply to Ben WidawskyThe cxl_region driver is responsible for managing the HDM decoder programming in the CXL topology. Once a region is created it must be configured and bound to the driver in order to activate it.
The following is a sample of how such controls might work:
region=$(cat /sys/bus/cxl/devices/decoder0.0/create_region) echo $region > /sys/bus/cxl/devices/decoder0.0/create_region echo 2 > /sys/bus/cxl/devices/decoder0.0/region0.0:0/interleave echo $((256<<20)) > /sys/bus/cxl/devices/decoder0.0/region0.0:0/size echo mem0 > /sys/bus/cxl/devices/decoder0.0/region0.0:0/target0 echo region0.0:0 > /sys/bus/cxl/drivers/cxl_region/bind
In order to handle the eventual rise in failure modes of binding a region, a new trace event is created to help track these failures for debug and reconfiguration paths in userspace.
--- .clang-format | 1 + .../driver-api/cxl/memory-devices.rst | 3 + drivers/cxl/Makefile | 2 + drivers/cxl/core/bus.c | 19 +- drivers/cxl/core/core.h | 1 + drivers/cxl/core/region.c | 25 +- drivers/cxl/cxl.h | 5 + drivers/cxl/region.c | 321 ++++++++++++++++++ drivers/cxl/region.h | 4 + drivers/cxl/trace.h | 45 +++ 10 files changed, 422 insertions(+), 4 deletions(-) create mode 100644 drivers/cxl/region.c create mode 100644 drivers/cxl/trace.h
.clang-format +1 -0
@@ -169,6 +169,7 @@ ForEachMacros: - 'for_each_cpu_and' - 'for_each_cpu_not' - 'for_each_cpu_wrap' + - 'for_each_cxl_endpoint' - 'for_each_dapm_widgets' - 'for_each_dev_addr' - 'for_each_dev_scope'
Documentation/driver-api/cxl/memory-devices.rst +3 -0
@@ -67,6 +67,9 @@ CXL Core CXL Regions ----------- +.. kernel-doc:: drivers/cxl/region.c + :doc: cxl region + .. kernel-doc:: drivers/cxl/region.h :identifiers:
drivers/cxl/Makefile +2 -0
@@ -5,9 +5,11 @@ obj-$(CONFIG_CXL_PCI) += cxl_pci.o obj-$(CONFIG_CXL_MEM) += cxl_mem.o obj-$(CONFIG_CXL_ACPI) += cxl_acpi.o obj-$(CONFIG_CXL_PMEM) += cxl_pmem.o +obj-$(CONFIG_CXL_MEM) += cxl_region.o cxl_mem-y := mem.o cxl_pci-y := pci.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o cxl_port-y := port.o +cxl_region-y := region.o
drivers/cxl/core/bus.c +18 -1
@@ -7,6 +7,7 @@#include <linux/slab.h> #include <linux/idr.h> #include <cxlmem.h> +#include <region.h> #include <cxl.h> #include <pci.h> #include "core.h"
@@ -29,6 +30,8 @@ static DEFINE_IDA(cxl_port_ida);static LIST_HEAD (cxl_root_ports);static DECLARE_RWSEM (root_port_sem); +struct cxl_region *to_cxl_region (struct device *dev); +static ssize_t devtype_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -905,6 +908,8 @@ static int cxl_device_id(struct device *dev)return CXL_DEVICE_PORT ;if (dev->type == &cxl_memdev_type)return CXL_DEVICE_MEMORY_EXPANDER ; +if (dev->type == &cxl_region_type) +return CXL_DEVICE_REGION ;return 0 ; }
@@ -921,7 +926,19 @@ static int cxl_bus_match(struct device *dev, struct device_driver *drv)static int cxl_bus_probe (struct device *dev) { -return to_cxl_drv (dev->driver)->probe (dev); +int id =cxl_device_id (dev); + +if (id ==CXL_DEVICE_REGION ) { +/* Regions cannot bind until parameters are set */ +struct cxl_region *region =to_cxl_region (dev); + +if (is_cxl_region_configured (region)) +return to_cxl_drv (dev->driver)->probe (dev); + }else { +return to_cxl_drv (dev->driver)->probe (dev); + } + +return -ENODEV ; }static void cxl_bus_remove (struct device *dev)
drivers/cxl/core/core.h +1 -0
@@ -7,6 +7,7 @@extern const struct device_type cxl_nvdimm_bridge_type;extern const struct device_type cxl_nvdimm_type;extern const struct device_type cxl_memdev_type; +extern const struct device_type cxl_region_type;extern struct attribute_group cxl_base_attribute_group;
drivers/cxl/core/region.c +22 -3
@@ -11,6 +11,8 @@#include <cxlmem.h> #include <cxl.h> +#include "core.h" +/** * DOC: cxl core region *
@@ -25,10 +27,27 @@ static const struct attribute_group region_interleave_group;static bool is_region_active (struct cxl_region *region) { -/* TODO: Regions can't be activated yet. */ -return false; +return region->active; } +/* +* Most sanity checking is left up to region binding. This does the most basic +* check to determine whether or not the core should try probing the driver. +*/ +bool is_cxl_region_configured (const struct cxl_region *region) +{ +/* zero sized regions aren't a thing. */ +if (region->size <=0 ) +return false; + +/* all regions have at least 1 target */ +if (!region->targets[0 ]) +return false; + +return true; +} +EXPORT_SYMBOL_GPL (is_cxl_region_configured); +static void remove_target (struct cxl_region *region,int target) {struct cxl_memdev *cxlmd;
@@ -310,7 +329,7 @@ static const struct attribute_group *region_groups[] = {static void cxl_region_release (struct device *dev); -static const struct device_type cxl_region_type = { +const struct device_type cxl_region_type = { .name ="cxl_region" , .release = cxl_region_release, .groups = region_groups
drivers/cxl/cxl.h +5 -0
@@ -197,6 +197,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr,#define CXL_DECODER_F_EN BIT(5)#define CXL_DECODER_F_MASK GENMASK(5, 0) +#define cxl_is_pmem_t3 (flags) \ + (((flags) & (CXL_DECODER_F_TYPE3 | CXL_DECODER_F_PMEM)) == \ + (CXL_DECODER_F_TYPE3 | CXL_DECODER_F_PMEM)) +enum cxl_decoder_type {CXL_DECODER_ACCELERATOR =2 ,CXL_DECODER_EXPANDER =3 ,
@@ -357,6 +361,7 @@ void cxl_driver_unregister(struct cxl_driver *cxl_drv);#define CXL_DEVICE_NVDIMM 2#define CXL_DEVICE_PORT 3#define CXL_DEVICE_MEMORY_EXPANDER 4 +#define CXL_DEVICE_REGION 5#define MODULE_ALIAS_CXL (type) MODULE_ALIAS("cxl:t" __stringify(type) "*")#define CXL_MODALIAS_FMT "cxl:t%d"
drivers/cxl/region.c new file +321 -0
321 lines not on this page · raw message
drivers/cxl/region.h +4 -0
@@ -12,6 +12,7 @@* @dev: This region's device. * @id: This regions id. Id is globally unique across all regions. * @list: Node in decoder's region list. +* @active: If the region has been activated. * @res: Address space consumed by this region. * @size: Size of the region determined from LSA or userspace. * @uuid: The UUID for this region.
@@ -23,6 +24,7 @@ struct cxl_region {struct device dev;int id;struct list_head list; +bool active;struct {struct resource *res;
@@ -34,4 +36,6 @@ struct cxl_region { }; }; +bool is_cxl_region_configured (const struct cxl_region *region); +#endif
drivers/cxl/trace.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.33.1
RFC PATCH 19/27 cxl/acpi: Handle address space allocation
In reply to Ben WidawskyRegions are carved out of an addresses space which is claimed by top level decoders, and subsequently their children decoders. Regions are created with a size and therefore must fit, with proper alignment, in that address space. The support for doing this fitting is handled by the driver automatically.
As an example, a platform might configure a top level decoder to claim 1TB of address space @ 0x800000000 -> 0x10800000000; it would be possible to create M regions with appropriate alignment to occupy that address space. Each of those regions would have a host physical address somewhere in the range between 32G and 1.3TB, and the location will be determined by the logic added here.
The request_region() usage is not strictly mandatory at this point as the actual handling of the address space is done with genpools. It is highly likely however that the resource/region APIs will become useful in the not too distant future.
All decoders manage a host physical address space while active. Only the root decoder has constraints on location and size. As a result, it makes most sense for the root decoder to be responsible for managing the entire address space, and mid-level decoders and endpoints can ask the root decoder for suballocations.
--- drivers/cxl/acpi.c | 30 ++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 32 insertions(+)
drivers/cxl/acpi.c +30 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2021 Intel Corporation. All rights reserved. */ #include <linux/platform_device.h> +#include <linux/genalloc.h> #include <linux/module.h> #include <linux/device.h> #include <linux/kernel.h>
@@ -75,6 +76,27 @@ static int cxl_acpi_cfmws_verify(struct device *dev,return 0 ; } +/* +* Every decoder while active has an address space that it is decoding. However, +* only the root level decoders have fixed host physical address space ranges. +*/ +static int cxl_create_cfmws_address_space (struct cxl_decoder *cxld, +struct acpi_cedt_cfmws *cfmws) +{ +const int order =ilog2 (SZ_256M * cxld->interleave_ways); +struct device *dev = &cxld->dev; +struct gen_pool *pool; + + pool =devm_gen_pool_create (dev, order,NUMA_NO_NODE ,dev_name (dev)); +if (IS_ERR (pool)) +return PTR_ERR (pool); + + cxld->address_space = pool; + +return gen_pool_add (cxld->address_space, cfmws->base_hpa, + cfmws->window_size,NUMA_NO_NODE ); +} +static void cxl_add_cfmws_decoders (struct device *dev,struct cxl_port *root_port) {
@@ -133,6 +155,14 @@ static void cxl_add_cfmws_decoders(struct device *dev, cxld->interleave_granularity =CFMWS_INTERLEAVE_GRANULARITY (cfmws); + rc =cxl_create_cfmws_address_space (cxld, cfmws); +if (rc) { +dev_err (dev, +"Failed to create CFMWS address space for decoder\n" ); +put_device (&cxld->dev); + goto next; + } + rc =cxl_decoder_add (cxld, target_map);if (rc)put_device (&cxld->dev);
drivers/cxl/cxl.h +2 -0
@@ -222,6 +222,7 @@ enum cxl_decoder_type {* @target_type: accelerator vs expander (type2 vs type3) selector * @flags: memory type capabilities and locking * @region_ida: allocator for region ids. +* @address_space: Used/free address space for regions. * @nr_targets: number of elements in @target * @target: active ordered target list in current decoder configuration */
@@ -234,6 +235,7 @@ struct cxl_decoder {enum cxl_decoder_type target_type;unsigned long flags;struct ida region_ida; +struct gen_pool *address_space;const int nr_targets;struct cxl_dport *target[]; };
Signature · 1 line
2.33.1
RFC PATCH 20/27 cxl/region: Address space allocation
In reply to Ben WidawskyWhen a region is not assigned a host physical address, one is picked by the driver. As the address will determine which CFMWS contains the region, it's usually a better idea to let the driver make this determination.
--- drivers/cxl/region.c | 35 +++++++++++++++++++++++++++++++++-- drivers/cxl/trace.h | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/cxl/region.c +33 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2021 Intel Corporation. All rights reserved. */ #include <linux/platform_device.h> +#include <linux/genalloc.h> #include <linux/device.h> #include <linux/module.h> #include <linux/pci.h>
@@ -55,6 +56,17 @@ static struct cxl_port *get_root_decoder(const struct cxl_memdev *endpoint)return NULL ; } +static void release_cxl_region (void *r) +{ +struct cxl_region *region = (struct cxl_region *)r; +struct cxl_decoder *cxld =cxld_from_region (region); +struct resource *parent_res = &cxld->res; +const struct resource *res = region->res; + +gen_pool_free (cxld->address_space, res->start,resource_size (res)); +__release_region (parent_res, res->start,resource_size (res)); +} +/** * sanitize_region() - Check is region is reasonably configured * @region: The region to check
@@ -104,8 +116,27 @@ static int sanitize_region(const struct cxl_region *region)*/ static int allocate_address_space (struct cxl_region *region) { -/* TODO */ -return 0 ; +struct cxl_decoder *cxld =cxld_from_region (region); +unsigned long start; + + start =gen_pool_alloc (cxld->address_space, region->size); +if (!start) { +trace_allocation_failed (region, +"Couldn't allocate address space" ); +return -ENOMEM ; + } + region->res = +__request_region (&cxld->res, start, region->size, +dev_name (®ion->dev),IORESOURCE_EXCLUSIVE ); + +if (IS_ERR (region->res)) { +trace_allocation_failed (region,"Couldn't obtain region" ); +gen_pool_free (cxld->address_space, start, region->size); +return PTR_ERR (region->res); + } + +return devm_add_action_or_reset (®ion->dev, release_cxl_region, + region); }/**
drivers/cxl/trace.h +3 -0
@@ -35,6 +35,9 @@ DEFINE_EVENT(cxl_region_template, region_activated,DEFINE_EVENT (cxl_region_template, sanitize_failed, TP_PROTO(const struct cxl_region *region, char *status),TP_ARGS (region, status)); +DEFINE_EVENT (cxl_region_template, allocation_failed, + TP_PROTO(const struct cxl_region *region, char *status), +TP_ARGS (region, status));#endif /* if !defined (__CXL_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ) */
Signature · 1 line
2.33.1
RFC PATCH 21/27 cxl/region: Implement XHB verification
In reply to Ben WidawskyCross host bridge verification primarily determines if the requested interleave ordering can be achieved by the root decoder, which isn't as programmable as other decoders.
The algorithm implemented here is based on the CXL Type 3 Memory Device Software Guide, chapter 2.13.14
--- .clang-format | 1 + drivers/cxl/region.c | 81 +++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/trace.h | 3 ++ 3 files changed, 84 insertions(+), 1 deletion(-)
.clang-format +1 -0
@@ -169,6 +169,7 @@ ForEachMacros: - 'for_each_cpu_and' - 'for_each_cpu_not' - 'for_each_cpu_wrap' + - 'for_each_cxl_decoder_target' - 'for_each_cxl_endpoint' - 'for_each_dapm_widgets' - 'for_each_dev_addr'
drivers/cxl/region.c +80 -1
99 lines not on this page · raw message
drivers/cxl/trace.h +3 -0
@@ -38,6 +38,9 @@ DEFINE_EVENT(cxl_region_template, sanitize_failed,DEFINE_EVENT (cxl_region_template, allocation_failed, TP_PROTO(const struct cxl_region *region, char *status),TP_ARGS (region, status)); +DEFINE_EVENT (cxl_region_template, xhb_valid, + TP_PROTO(const struct cxl_region *region, char *status), +TP_ARGS (region, status));#endif /* if !defined (__CXL_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ) */
Signature · 1 line
2.33.1
RFC PATCH 22/27 cxl/region: HB port config verification
In reply to Ben WidawskyHost bridge root port verification determines if the device ordering in an interleave set can be programmed through the host bridges and switches.
The algorithm implemented here is based on the CXL Type 3 Memory Device Software Guide, chapter 2.13.15
--- .clang-format | 1 + drivers/cxl/cxl.h | 3 ++ drivers/cxl/region.c | 90 +++++++++++++++++++++++++++++++++++++++++++- drivers/cxl/trace.h | 3 ++ 4 files changed, 96 insertions(+), 1 deletion(-)
.clang-format +1 -0
@@ -171,6 +171,7 @@ ForEachMacros: - 'for_each_cpu_wrap' - 'for_each_cxl_decoder_target' - 'for_each_cxl_endpoint' + - 'for_each_cxl_endpoint_hb' - 'for_each_dapm_widgets' - 'for_each_dev_addr' - 'for_each_dev_scope'
drivers/cxl/cxl.h +3 -0
@@ -300,6 +300,7 @@ struct cxl_port {* @port: reference to cxl_port that contains this downstream port * @list: node for a cxl_port's list of cxl_dport instances * @root_port_link: node for global list of root ports +* @verify_link: node used for hb root port verification */ struct cxl_dport {struct device *dport;
@@ -308,6 +309,8 @@ struct cxl_dport {struct cxl_port *port;struct list_head list;struct list_head root_port_link; + +struct list_head verify_link; };bool is_cxl_region (struct device *dev);
drivers/cxl/region.c +89 -1
114 lines not on this page · raw message
drivers/cxl/trace.h +3 -0
@@ -41,6 +41,9 @@ DEFINE_EVENT(cxl_region_template, allocation_failed,DEFINE_EVENT (cxl_region_template, xhb_valid, TP_PROTO(const struct cxl_region *region, char *status),TP_ARGS (region, status)); +DEFINE_EVENT (cxl_region_template, hb_rp_valid, + TP_PROTO(const struct cxl_region *region, char *status), +TP_ARGS (region, status));#endif /* if !defined (__CXL_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ) */
Signature · 1 line
2.33.1
RFC PATCH 23/27 cxl/region: Record host bridge target list
In reply to Ben WidawskyPart of host bridge verification in the CXL Type 3 Memory Device Software Guide calculates the host bridge interleave target list (6th step in the flow chart). With host bridge verification already done, it is trivial to store away the configuration information.
TODO: Needs support for switches (7th step in the flow chart).
--- drivers/cxl/region.c | 41 ++++++++++++++++++++++++++++++----------- drivers/cxl/region.h | 12 ++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-)
drivers/cxl/region.c +30 -11
@@ -294,14 +294,17 @@ static int get_num_root_ports(const struct cxl_region *region)* region_hb_rp_config_valid() - determine root port ordering is correct * @cfmws: CFMWS decoder for this @region * @region: Region to validate +* @p: HDM decoder programming state. Populated if non-NULL. * * The algorithm is outlined in 2.13.15 "Verify HB root port configuration * sequence" of the CXL Memory Device SW Guide (Rev1p0). * -* Returns true if the configuration is valid. +* Returns true if the configuration is valid, the configuration state is +* updated for later programming. */ static bool region_hb_rp_config_valid (const struct cxl_region *region, -const struct cxl_decoder *cfmws) +const struct cxl_decoder *cfmws, +struct decoder_programming *p) {const int num_root_ports =get_num_root_ports (region);struct cxl_port *hbs[CXL_DECODER_MAX_INTERLEAVE ];
@@ -309,18 +312,29 @@ static bool region_hb_rp_config_valid(const struct cxl_region *region, hb_count =get_unique_hostbridges (region, hbs); +if (p) + p->hb_count = hb_count; +/* * Are all devices in this region on the same CXL Host Bridge * Root Port? */ -if (num_root_ports ==1 ) +if (num_root_ports ==1 ) { +if (p) { + p->hbs[0 ].rp_target_list[0 ] = region->targets[0 ]->root_port; + p->hbs[0 ].rp_count =1 ; + }return true; + }for (i =0 ; i < hb_count; i++) { +struct cxl_dport *rp, **targets;struct cxl_port *hb = hbs[i]; -struct cxl_dport *rp;int position_mask; -int idx; +int idx, *rp_count; + + targets = &p->hbs[i].rp_target_list[0 ]; + rp_count = &p->hbs[i].rp_count;/* * Calculate the position mask: NumRootPorts = 2^PositionMask
@@ -343,9 +357,12 @@ static bool region_hb_rp_config_valid(const struct cxl_region *region,if (ep->root_port != rp)continue ; -if (port_grouping ==-1 ) { +if (port_grouping ==-1 ) port_grouping = idx & position_mask; -continue ; + +if (p) { + (*rp_count)++; + targets[port_grouping] = ep->root_port; }/*
@@ -379,7 +396,8 @@ static bool cfmws_contains(const struct cxl_region *region, }static bool cfmws_valid (const struct cxl_region *region, -const struct cxl_decoder *cfmws) +const struct cxl_decoder *cfmws, +struct decoder_programming *p) {const struct cxl_memdev *endpoint = region->targets[0 ];
@@ -392,7 +410,7 @@ static bool cfmws_valid(const struct cxl_region *region,if (!region_xhb_config_valid (region, cfmws))return false; -if (!region_hb_rp_config_valid (region, cfmws)) +if (!region_hb_rp_config_valid (region, cfmws, p))return false;if (!cfmws_contains (region, cfmws))
@@ -409,7 +427,7 @@ static int cfmws_match(struct device *dev, void *data)if (!is_root_decoder (dev))return 0 ; -return !!cfmws_valid (region,to_cxl_decoder (dev)); +return !!cfmws_valid (region,to_cxl_decoder (dev),NULL ); }/*
@@ -481,7 +499,8 @@ static int cxl_region_probe(struct device *dev)return -ENXIO ; cfmws =cxld_from_region (region); -if (!cfmws_valid (region, cfmws)) { +if (!cfmws_valid (region, cfmws, + (struct decoder_programming *)®ion->state)) {dev_err (dev,"Picked invalid cfmws\n" );return -ENXIO ; }
drivers/cxl/region.h +12 -0
@@ -19,6 +19,10 @@* @eniw: Number of interleave ways this region is configured for. * @ig: Interleave granularity of region * @targets: The memory devices comprising the region. +* @state: Configuration state for host bridges, switches, and endpoints. +* @state.hbs: Host bridge state. One per hostbridge in the interleave set. +* @state.hbs.rp_count: Count of root ports for this region +* @state.hbs.rp_target_list: Ordered list of downstream root ports. */ struct cxl_region {struct device dev;
@@ -34,6 +38,14 @@ struct cxl_region {int ig;struct cxl_memdev *targets[CXL_DECODER_MAX_INTERLEAVE ]; }; + +struct decoder_programming { +int hb_count; +struct { +int rp_count; +struct cxl_dport *rp_target_list[CXL_DECODER_MAX_INTERLEAVE ]; + } hbs[CXL_DECODER_MAX_INTERLEAVE ]; + } state; };bool is_cxl_region_configured (const struct cxl_region *region);
Signature · 1 line
2.33.1
RFC PATCH 24/27 cxl/mem: Store the endpoint's uport
In reply to Ben WidawskyKeeping track of an endpoint's port is important when attempting to assemble all relevant components in the CXL.mem route from root to endpoint. Without this change, the endpoint's port can be obtained through walks of the hierarchy.
--- drivers/cxl/cxlmem.h | 1 + drivers/cxl/mem.c | 1 + 2 files changed, 2 insertions(+)
drivers/cxl/cxlmem.h +1 -0
@@ -45,6 +45,7 @@ struct cxl_memdev {int id;resource_size_t creg_base;struct cxl_dport *root_port; +struct cxl_port *uport; };static inline struct cxl_memdev *to_cxl_memdev (struct device *dev)
drivers/cxl/mem.c +1 -0
@@ -62,6 +62,7 @@ static int create_endpoint_port(struct device *dev, struct device *host, endpoint =devm_cxl_add_port (host, dev, cxlmd->creg_base, parent);if (IS_ERR (endpoint))return PTR_ERR (endpoint); + cxlmd->uport = endpoint;dev_dbg (host,"add: %s\n" ,dev_name (&endpoint->dev));return 0 ;
Signature · 1 line
2.33.1
RFC PATCH 25/27 cxl/region: Gather HDM decoder resources
In reply to Ben WidawskyPrepare for HDM decoder programming by iterating through all components and obtaining a cxl_decoder for each.
Programming a CXL region to accept memory transactions over a set of devices requires programming HDM decoders for every component that is part of the hierarchy enabling the region (host bridges, switches, and endpoints). For this to be possible, each of these components must have an available HDM decoder, which is a limited hardware resource.
--- drivers/cxl/core/bus.c | 8 ++++++ drivers/cxl/cxl.h | 3 ++ drivers/cxl/port.c | 53 +++++++++++++++++++++++++++++++++++ drivers/cxl/region.c | 63 +++++++++++++++++++++++++++++++++++++++--- drivers/cxl/region.h | 4 +++ 5 files changed, 127 insertions(+), 4 deletions(-)
drivers/cxl/core/bus.c +8 -0
@@ -301,6 +301,14 @@ static bool is_endpoint_decoder(struct device *dev)return dev->type == &cxl_decoder_endpoint_type; } +bool is_cxl_decoder (struct device *dev) +{ +return dev->type == &cxl_decoder_switch_type || + dev->type == &cxl_decoder_endpoint_type || + dev->type == &cxl_decoder_root_type; +} +EXPORT_SYMBOL_GPL (is_cxl_decoder); +bool is_root_decoder (struct device *dev) {return dev->type == &cxl_decoder_root_type;
drivers/cxl/cxl.h +3 -0
@@ -331,11 +331,14 @@ int cxl_add_dport(struct cxl_port *port, struct device *dport, int port_id,struct cxl_dport *cxl_get_root_dport (struct device *dev);struct cxl_dport *cxl_find_dport_by_dev (struct cxl_port *port,struct device *dev); +struct cxl_decoder *cxl_pop_decoder (struct cxl_port *port); +void cxl_push_decoder (struct cxl_decoder *cxld);struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev);struct cxl_decoder *cxl_decoder_alloc (struct cxl_port *port,unsigned int nr_targets); +bool is_cxl_decoder (struct device *dev);int cxl_decoder_add (struct cxl_decoder *cxld,int *target_map);int cxl_decoder_autoremove (struct device *host,struct cxl_decoder *cxld);
drivers/cxl/port.c +53 -0
59 lines not on this page · raw message
drivers/cxl/region.c +59 -4
85 lines not on this page · raw message
drivers/cxl/region.h +4 -0
@@ -23,6 +23,8 @@* @state.hbs: Host bridge state. One per hostbridge in the interleave set. * @state.hbs.rp_count: Count of root ports for this region * @state.hbs.rp_target_list: Ordered list of downstream root ports. +* @state.hbs.cxld: an available decoder to set up the programming. +* @state.ep_cxld: available decoders for endpoint programming. */ struct cxl_region {struct device dev;
@@ -44,7 +46,9 @@ struct cxl_region {struct {int rp_count;struct cxl_dport *rp_target_list[CXL_DECODER_MAX_INTERLEAVE ]; +struct cxl_decoder *cxld; } hbs[CXL_DECODER_MAX_INTERLEAVE ]; +struct cxl_decoder *ep_cxld[CXL_DECODER_MAX_INTERLEAVE ]; } state; };
Signature · 1 line
2.33.1
RFC PATCH 26/27 cxl: Program decoders for regions
In reply to Ben WidawskyDo the HDM decoder programming for all endpoints and host bridges in a region. Switches are currently unimplemented.
--- drivers/cxl/cxl.h | 3 + drivers/cxl/port.c | 196 +++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/region.c | 33 +++++++- 3 files changed, 231 insertions(+), 1 deletion(-)
drivers/cxl/cxl.h +3 -0
@@ -52,6 +52,7 @@#define CXL_HDM_DECODER0_CTRL_IW_MASK GENMASK(7, 4)#define CXL_HDM_DECODER0_CTRL_COMMIT BIT(9)#define CXL_HDM_DECODER0_CTRL_COMMITTED BIT(10) +#define CXL_HDM_DECODER0_CTRL_COMMIT_ERROR BIT(11)#define CXL_HDM_DECODER0_CTRL_TYPE BIT(12)#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24)#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)
@@ -333,6 +334,8 @@ struct cxl_dport *cxl_find_dport_by_dev(struct cxl_port *port, struct device *dev);struct cxl_decoder *cxl_pop_decoder (struct cxl_port *port);void cxl_push_decoder (struct cxl_decoder *cxld); +int cxl_commit_decoder (struct cxl_decoder *cxld); +void cxl_disable_decoder (struct cxl_decoder *cxld);struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev);
drivers/cxl/port.c +196 -0
202 lines not on this page · raw message
drivers/cxl/region.c +32 -1
@@ -524,7 +524,38 @@ static int gather_hdm_decoders(const struct cxl_region *region, struct decoder_pstatic int bind_region (const struct cxl_region *region) { -/* TODO: */ +const struct decoder_programming *p = ®ion->state; +int i, rc; + +for (i =0 ; i < p->hb_count; i++) { +struct cxl_decoder *cxld = p->hbs[i].cxld; +int j; + + cxld->res = (struct resource )DEFINE_RES_MEM ( + region->res->start, region->size *region_ways (region)); + cxld->interleave_granularity = region->ig; + cxld->interleave_ways = p->hbs[i].rp_count; +for (j =0 ; j < p->hbs[i].rp_count; j++) + cxld->target[j] = p->hbs[i].rp_target_list[j]; + + rc =cxl_commit_decoder (cxld); +if (rc) +return rc; + } + +for (i =0 ; i <region_ways (region); i++) { +struct cxl_decoder *cxld = p->ep_cxld[i]; + + cxld->res = (struct resource )DEFINE_RES_MEM ( + region->res->start, region->size *region_ways (region)); + cxld->interleave_granularity = region->ig; + cxld->interleave_ways =region_ways (region); + + rc =cxl_commit_decoder (cxld); +if (rc) +return rc; + } +return 0 ; }
Signature · 1 line
2.33.1
RFC PATCH v2 26/27 cxl: Program decoders for regions
Do the HDM decoder programming for all endpoints and host bridges in a region. Switches are currently unimplemented.
---
v2: Fix size of regions for decoder programming. This could not be hit with x1 interleave.
--- drivers/cxl/cxl.h | 3 + drivers/cxl/port.c | 196 +++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/region.c | 33 +++++++- 3 files changed, 231 insertions(+), 1 deletion(-)
drivers/cxl/cxl.h +3 -0
@@ -52,6 +52,7 @@#define CXL_HDM_DECODER0_CTRL_IW_MASK GENMASK(7, 4)#define CXL_HDM_DECODER0_CTRL_COMMIT BIT(9)#define CXL_HDM_DECODER0_CTRL_COMMITTED BIT(10) +#define CXL_HDM_DECODER0_CTRL_COMMIT_ERROR BIT(11)#define CXL_HDM_DECODER0_CTRL_TYPE BIT(12)#define CXL_HDM_DECODER0_TL_LOW (i) (0x20 * (i) + 0x24)#define CXL_HDM_DECODER0_TL_HIGH (i) (0x20 * (i) + 0x28)
@@ -333,6 +334,8 @@ struct cxl_dport *cxl_find_dport_by_dev(struct cxl_port *port, struct device *dev);struct cxl_decoder *cxl_pop_decoder (struct cxl_port *port);void cxl_push_decoder (struct cxl_decoder *cxld); +int cxl_commit_decoder (struct cxl_decoder *cxld); +void cxl_disable_decoder (struct cxl_decoder *cxld);struct cxl_decoder *to_cxl_decoder (struct device *dev);bool is_root_decoder (struct device *dev);
drivers/cxl/port.c +196 -0
202 lines not on this page · raw message
drivers/cxl/region.c +32 -1
@@ -524,7 +524,38 @@ static int gather_hdm_decoders(const struct cxl_region *region, struct decoder_pstatic int bind_region (const struct cxl_region *region) { -/* TODO: */ +const struct decoder_programming *p = ®ion->state; +int i, rc; + +for (i =0 ; i < p->hb_count; i++) { +struct cxl_decoder *cxld = p->hbs[i].cxld; +int j; + + cxld->res = (struct resource )DEFINE_RES_MEM (region->res->start, + region->size); + cxld->interleave_granularity = region->ig; + cxld->interleave_ways = p->hbs[i].rp_count; +for (j =0 ; j < p->hbs[i].rp_count; j++) + cxld->target[j] = p->hbs[i].rp_target_list[j]; + + rc =cxl_commit_decoder (cxld); +if (rc) +return rc; + } + +for (i =0 ; i <region_ways (region); i++) { +struct cxl_decoder *cxld = p->ep_cxld[i]; + + cxld->res = (struct resource )DEFINE_RES_MEM (region->res->start, + region->size); + cxld->interleave_granularity = region->ig; + cxld->interleave_ways =region_ways (region); + + rc =cxl_commit_decoder (cxld); +if (rc) +return rc; + } +return 0 ; }
base-commit: 9c82a53a4eefc929d179458f122945a1c5081e12
prerequisite-patch-id: b5cc879e3b75e9f22e9bf281a2f67b2c5d1da34c
prerequisite-patch-id: 12ec7d5df6148b7208db1d57a75807b044ad9e6d
prerequisite-patch-id: 280943dd25acb6408ed6b56fa391bc4948d6c5fb
prerequisite-patch-id: 8ec2940548244e84741a9b6cdbb5b1d1d1e61348
prerequisite-patch-id: eb8895105872d0a4139a5ffa17a0b794a3ba52be
prerequisite-patch-id: 178e95ac80584844a5698b7b399940c3acee1926
prerequisite-patch-id: 762ab2be632eaf582bec9f5dded66d20513f4639
prerequisite-patch-id: 4fd39e0b11492f7662b436022235f88ed93320e2
prerequisite-patch-id: 764e4b641a6fef57a9236423ff7083f1d57c1db0
prerequisite-patch-id: 2034acd5533b9f58a96cba4ca74779b84e287619
prerequisite-patch-id: affbd3320ef50625cb5a330ee26a149aa9ab262c
Signature · 1 line
2.33.1
RFC PATCH 27/27 dont-merge: My QEMU CFMWS is wrong
In reply to Ben WidawskyIt seems to only be me... Use this at your own risk.
--- drivers/cxl/region.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/cxl/region.c +2 -0
@@ -404,8 +404,10 @@ static bool cfmws_valid(const struct cxl_region *region,if (!qtg_match (cfmws, endpoint))return false; +#if 0 if (!cxl_is_pmem_t3 (cfmws->flags))return false; +#endif if (!region_xhb_config_valid (region, cfmws))return false;
Signature · 1 line
2.33.1
Re: [RFC PATCH 27/27] dont-merge: My QEMU CFMWS is wrong
Quoted 2 lines · Ben Widawsky
It seems to only be me... Use this at your own risk.
---
I wasn't building the right QEMU SHA. This patch shouldn't be needed.
Quoted 21 lines
drivers/cxl/region.c | 2 ++ 1 file changed, 2 insertions(+)drivers/cxl/region.c +2
-0@@ -404,8 +404,10 @@ static bool cfmws_valid(const struct cxl_region *region,if (!qtg_match (cfmws, endpoint))return false; +#if 0 if (!cxl_is_pmem_t3 (cfmws->flags))return false; +#endif if (!region_xhb_config_valid (region, cfmws))return false;Signature · 1 line
2.33.1
Quoted 1 line · Ben Widawsky
CXL region creation
[snip]
One thing I left out. Several patches in the region verification and programming are broken up into discrete steps. This was because this is how they were developed and I believe it makes them easier to review. My preference is to keep them broken out like this so the history reflects the development of this fairly complex part of CXL driver development, however I do suspect review feedback will suggest I squash several of the last patches. Ultimately I won't put up a fight here.
Thanks.
Ben
Just a heads up for anyone planning to review this soon. I have a v2 coming soon with enough changes that I think I'll do a resend. In other words, probably worth ignoring this series for now.
Thanks.
Ben
Quoted 172 lines · Ben Widawsky
CXL region creation
-------------------
An interleave set of devices is known in the Compute Express Link [1] specification as a region. In addition to a region being comprised of devices that can be configured in a variety of orders there are other properties that defines a region. This patch series implements both the interfaces to create and configure a region, as well as the algorithm to program the HDM decoders to enable CXL.mem traffic while obeying those configuration parameters. The functionality is realized via a few drivers which are added and described below. In addition to those drivers,cxl_coregrows new functionality to support these drivers.Some version of this functionality has all be posted previously by me, with the exception of the actual HDM decoder programming. It's probably wise to forget those exist, and take my apology in advance for not addressing feedback you may have already given.
There are two branches I am using as development branches. The branch for port/mem driver [2] is fairly solid. The branch for region creation [3] is less baked.
cxl_port
========The
cxl_portdriver is implemented within thecxl_portmodule. While loading of this module is optional, the other new drivers depend on it. The port driver is responsible for all activities around HDM decoder enumeration and programming. Introduced earlier, the concept of a port is an abstraction over CXL components with an upstream port, every host bridge, switch, and endpoint.
cxl_mem
=======The
cxl_memdriver's main job is to walk up the hierarchy to make the determination if it is CXL.mem routed, meaning, all components above it in the hierarchy are participating in the CXL.mem protocol. It is implemented within thecxl_memmodule. As the host bridge ports are added by a platform specific driver, such ascxl_acpi, the scope of the mem driver can be reduced to scan for switches and askcxl_coreto work on enumerating them. With this done, the determination as to whether a device is CXL.mem routed can be done simply by checking if the struct device has a driver bound to it.
cxl_region
==========Region verification and programming state are owned by the
cxl_regiondriver (implemented in thecxl_regionmodule). It relies oncxl_memto determine if devices are CXL routed, andcxl_portto actually handle the programming of the HDM decoders. Much of the region driver is an implementation of algorithms described in the CXL Type 3 Memory Device Software Guide [4].Why RFC?
--------
The code is pretty raw. I haven't spend much time tidying things up. While I think most of the architecture is sound, I don't believe anyone but other developers should use this branch. Where I'd really like most eyes:
- Locking and device lifetimes. As time wore on I definitely took some shortcuts there.
- Region configuration. Should values have a default, should they all be explicit?
- What should/shouldn't be in core. I like how this ended up, but at this point I'm fairly biased (CXL.cache pun).What's missing
---------------
- CXL 2.0 switch support
- Testing on anything but x1 interleave. While QEMU does support multiple host bridges and root ports, it isn't well tested.
- A full topology lock for programming HDM decoders
- Check that HDM decoder programming addresses are correct (must program higher addresses only)
- Volatile regions
- Connection to libnvdimm/labels (Dan is working on this). This includes many aspects, not the least of which is saving the region into the Label Storage Area so that it can be reestablished on reboot.Here is an example of output when programming a x1 interleave region:
[ 23.959814][ T645] cxl_core:cxl_add_region:406: cxl region0.0:0: Added region0.0:0 to decoder0.0 [ 23.962972][ T645] cxl_port:cxl_commit_decoder:248: cxl_port port1: decoder1.0 [ 23.962972][ T645] Base 0x0000004c00000000 [ 23.962972][ T645] Size 268435456 [ 23.962972][ T645] IG 256 [ 23.962972][ T645] IW 1 [ 23.962972][ T645] TargetList: 0 -1 -1 -1 -1 -1 -1 -1 [ 23.965529][ T645] cxl_port:cxl_commit_decoder:248: cxl_port port3: decoder3.0 [ 23.965529][ T645] Base 0x0000004c00000000 [ 23.965529][ T645] Size 268435456 [ 23.965529][ T645] IG 256 [ 23.965529][ T645] IW 1 [ 23.965529][ T645] TargetList: -1 -1 -1 -1 -1 -1 -1 -1If you're wondering how I tested this, I've baked it into my cxlctl app [5] and lib [6]. Eventually this will get absorbed by ndctl/cxl-cli/libcxl [7].
To get the detailed errors, trace-cmd can be utilized as such:
trace-cmd record -e cxl ./cxlctl create-region -n -a -s $((256<<20))/sys/bus/cxl/devices/decoder0.0[1]: https://www.computeexpresslink.org/download-the-specification
[2]: https://gitlab.com/bwidawsk/linux/-/tree/cxl_port-v2
[3]: https://gitlab.com/bwidawsk/linux/-/tree/cxl_regions-v3
[4]: https://cdrdv2.intel.com/v1/dl/getContent/643805?wapkw=CXL%20memory%20device%20sw%20guide
[5]: https://gitlab.com/bwidawsk-cxl/cxlctl
[6]: https://gitlab.com/bwidawsk-cxl/cxl_rs
[7]: https://lore.kernel.org/linux-cxl/CAPcyv4joKOhTdaRBJVeoOtqhRjBvdtt9902TS=c39=zWTZXvuw@mail.gmail.com/Ben Widawsky (27):
cxl: RenameCXL_MEMtoCXL_PCI
cxl: Move register block enumeration to core cxl/acpi: Map component registers for Root Ports
cxl: Add helper for new drivers
cxl/core: Convert decoder range to resource
cxl: Introduce endpoint decoders
cxl/port: Introduce a port driver
cxl/acpi: Map single port host bridge component registers cxl/core: Store global list of root ports cxl/acpi: Rescan bus at probe completion cxl/core: Store component register base for memdevs
cxl: Flesh out register names
cxl/core: Introduce API to scan switch ports
cxl: Introducecxl_memdriver
cxl: Disable switch hierarchies for now cxl/region: Add region creation ABI
cxl/region: Introduce concept of region configuration cxl/region: Introduce acxl_regiondriver cxl/acpi: Handle address space allocation cxl/region: Address space allocation
cxl/region: Implement XHB verification cxl/region: HB port config verification cxl/region: Record host bridge target list cxl/mem: Store the endpoint's uport
cxl/region: Gather HDM decoder resources
cxl: Program decoders for regions
dont-merge: My QEMU CFMWS is wrong.clang-format | 3 + Documentation/ABI/testing/sysfs-bus-cxl | 63 ++ .../driver-api/cxl/memory-devices.rst | 28 + drivers/cxl/Kconfig | 28 +- drivers/cxl/Makefile | 8 +- drivers/cxl/acpi.c | 117 +++- drivers/cxl/core/Makefile | 2 + drivers/cxl/core/bus.c | 346 +++++++++- drivers/cxl/core/core.h | 2 + drivers/cxl/core/memdev.c | 7 +- drivers/cxl/core/pci.c | 99 +++ drivers/cxl/core/region.c | 453 +++++++++++++ drivers/cxl/core/regs.c | 62 +- drivers/cxl/cxl.h | 78 ++- drivers/cxl/cxlmem.h | 8 +- drivers/cxl/mem.c | 161 +++++ drivers/cxl/pci.c | 69 +- drivers/cxl/pci.h | 48 +- drivers/cxl/port.c | 490 ++++++++++++++ drivers/cxl/region.c | 626 ++++++++++++++++++ drivers/cxl/region.h | 57 ++ drivers/cxl/trace.h | 54 ++ tools/testing/cxl/Kbuild | 2 + tools/testing/cxl/mock_acpi.c | 4 +- tools/testing/cxl/test/mem.c | 3 +- 25 files changed, 2688 insertions(+), 130 deletions(-) create mode 100644 drivers/cxl/core/pci.c create mode 100644 drivers/cxl/core/region.c create mode 100644 drivers/cxl/mem.c create mode 100644 drivers/cxl/port.c create mode 100644 drivers/cxl/region.c create mode 100644 drivers/cxl/region.h create mode 100644 drivers/cxl/trace.hSignature · 1 line
2.33.1