cxl/pci: Add support for RCH RAS error handling
v10 cover cxl/pci: Add support for RCH RAS error handling
This patchset enables CXL RCH error handling. This is necessary because RCH downstream port protocol error handling is implemented uniquely and not currently supported. These patches address the following:
* Discovery and mapping of RCH downstream port AER registers.
* AER portdrv changes to support CXL RCH protocol errors.
* Interrupt setup specific to RCH mode: enabling RCEC internal errors and disabling root port interrupts.
* Logging RCH downstream port AER and RAS errors.
Changes in v10:
- Updated cxl_setup_comp_regs() in patch#1 to include cxl_register_map::reg_type default value initialization.
Changes in v9:
- Added: cxl/regs: Prepare for multiple users of register mappings,
- Updated use of cxl_map_component_regs() and cxl_map_device_regs
Changes in V8:
- Rebased onto: commit
0c0df63177e3 ("Merge branch 'for-6.5/cxl-rch-eh' into for-6.5/cxl") - cxl/port: Pre-initialize component register mappings
- Added patch to pre-initialize component register mappings.
- cxl/pci: Remove Component Register base address from
- Separated removal of Component Register base address in struct cxl_dev_state to not break functionality.
- cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
- Implemented a less strict check in devm_cxl_setup_hdm(), be tolerant if HDM decoder registers are not implemented.
- cxl/pci: Map RCH downstream AER registers for logging protocol errors
- Fixed uninitialized access of map->dev in cxl_dport_map_regs().
- PCI/AER: Forward RCH downstream port-detected errors to the CXL.mem dev handler
- Fix typo in patch description.
- cxl/pci: Update CXL error logging to use RAS register address
- Fix typo in patch description.
Changes in V7:
- cxl: Updates for CXL Test to work with RCH
- Removed Robert's DSO.
- cxl/core/regs: Add @dev to cxl_register_map
- Corrected typo in patch description.
- PCI/AER: Unmask RCEC internal errors to enable RCH downstream port error handling.
- Changed int variable to bool.
- cxl/pci: Map RCH downstream AER registers for logging protocol errors
- Corrected patch description.
- cxl/pci: Add RCH downstream port AER register discovery
- Reverted empty line removal.
- cxl/port: Store the port's Component Register mappings in struct cxl_port
- Update to use structure initialization in cxl_setup_comp_regs().
- Remove first patch (already in the tree) and added patch 27/27.
- Was a one-off error caused when merging branches during internal review.
Changes in V6:
- Added patch for cxl test fixes: 'cxl: Update CXl Test to Work with RCH'. Patch from Dan.
- Simplified: 'cxl/rch: Prepare for caching the MMIO mapped PCIe AER capability'. Patch from Dan.
- Added patch: 'cxl: Rename 'uport' to 'uport_dev''
- Updated patch: 'cxl: Rename member @dport of struct cxl_dport to
@dport_dev'
- Updated *map assignment to use structure init in 'cxl/core/regs: Add
@dev to cxl_register_map'. Also fixed whitespace.
- Removed extra whitespace in 'cxl/core/regs: Add @dev to
cxl_register_map'
- Updated patch subject: 'cxl/acpi: Move add_host_bridge_uport() after
cxl_get_chbs()' - Changes to work with CXL test. 'cxl/acpi: Directly bind the CEDT detected CHBCR to the Host Bridge's port'
- 'cxl/pci: Early setup RCH dport component registers from RCRB'
- Removed parameter from cxl_rcrb_get_comp_regs().
- Changed return value to EPROBE_DEFER for retry during ACPI initialization.
- Changed map to us struct initialization.
- Remove ENODEV check in 'cxl/port: Store the downstream port's Component Register mappings in struct cxl_dport'
- 'cxl/port: Remove Component Register base address from struct cxl_dport'
- Moved earlier with same removal for cxl_port.
- cxl/pci: Add RCH downstream port AER register discovery
- Flattened {request,release}_mem_region() and ioremap() into cxl_rcrb_to_aer().
- Add check if OS is assigned AER handling before discovering AER.
- Added CXL namespace import to cxl_core (drivers/cxl/core/port.c). Needed for using pci_print_aer(). In 'PCI/AER: Refactor cper_print_aer() for use by CXL driver module'.
- cxl/pci: Map RCH downstream AER registers for logging protocol errors
- Changed dport device used in devm_cxl_iomap_block() call to be port->dev.
- Removed ENODEV check.
- cxl/pci: Disable root port interrupts in RCH mode
- Removed unnecessary 'rch' check.
- Moved cxl_disable_rch_root_ints() into core/pci.c.
- Added OSC AER assignment check before accessing AER registers.
- cxl/pci: Update CXL error logging to use RAS register address
- Renamed function handlers.
- cxl/pci: Add RCH downstream port error logging
- Moved RCD check to caller.
- Added put_dev() after call to cxl_pci_find_port().
Changes in V5:
- Split 'cxl/rch: Prepare for logging RCH downstream port protocol errors' patch into 2 patches.
- Added:
cxl/core/regs: Rename phys_addr in cxl_map_component_regs() cxl/mem: Prepare for early RCH dport component register setup
- Correct comments CXL3.0 to CXL 3.0.
- changed cxl_port_get_comp_map() to static.
Changes in V4:
- Made port RAS register discovery common and called from
__devm_cxl_add_dport().
- Changed RCH AER register discovery to be called from
__devm_cxl_add_dport().
- Changed RAS and RCH AER register mapping to be called from
__devm_cxl_add_dport(). - Changed component register mapping to support all CXL component mapping, cxl_map_component_regs().
- Added cxl_regs to 'struct cxl_dport' for providing RCH downstream port mapped registers USED in error handler.
- PCI/AER:
- Improved description of PCIEAER_CXL option in Kconfig.
- Renamed function to pci_aer_unmask_internal_errors(), added pcie_aer_is_native() check.
- Improved comments and added spec refs.
- Renamed functions to cxl_rch_handle_error*().
- Modified cxl_rch_handle_error_iter() to only call the handler callbacks, this also simplifies refcounting of the pdev.
- Refactored handle_error_source(), created pci_aer_handle_error().
- Changed printk messages to pci_*() variants.
- Added check for pcie_aer_is_native() to the RCEC.
- Introduced function cxl_rch_enable_rcec().
- Updated patch description ("PCI/AER: Forward RCH downstream port-detected errors to the CXL.mem dev handler").
Changes in V3:
- Correct base commit in cover sheet.
- Change hardcoded return 0 to NULL in regs.c.
- Remove calls to pci_disable_pcie_error_reporting(pdev) and
pci_enable_pcie_error_reporting(pdev) in mem.c;
- Move RCEC interrupt unmask to PCIe port AER driver's probe.
- Fixes missing PCIEAER and PCIEPORTBUS config option error.
- Rename cxl_rcrb_setup() to cxl_setup_rcrb() in mem.c.
- Update cper_mem_err_unpack() patch subject and description.
Changes in V2:
- Refactor RCH initialization into cxl_mem driver.
- Includes RCH RAS and AER register discovery and mapping.
- Add RCEC protocol error interrupt forwarding to CXL endpoint handler.
- Change AER and RAS logging to use existing trace routines.
- Enable RCEC AER internal errors.
Robert Richter (9):
cxl/port: Pre-initialize component register mappings cxl/regs: Prepare for multiple users of register mappings cxl/pci: Store the endpoint's Component Register mappings in struct
cxl_dev_state
cxl/hdm: Use stored Component Register mappings to map HDM decoder
capability
cxl/pci: Remove Component Register base address from struct
cxl_dev_state
cxl/port: Remove Component Register base address from struct cxl_port PCI/AER: Forward RCH downstream port-detected errors to the CXL.mem
dev handler
PCI/AER: Unmask RCEC internal errors to enable RCH downstream port
error handling
cxl/core/regs: Rename phys_addr in cxl_map_component_regs()
Terry Bowman (6):
cxl/pci: Add RCH downstream port AER register discovery PCI/AER: Refactor cper_print_aer() for use by CXL driver module cxl/pci: Update CXL error logging to use RAS register address cxl/pci: Map RCH downstream AER registers for logging protocol errors cxl/pci: Add RCH downstream port error logging
cxl/pci: Disable root port interrupts in RCH mode
base-commit: 0c0df63177e37ae826d803280eb2c5b6b6a7a9a4
drivers/cxl/core/core.h | 7 ++ drivers/cxl/core/hdm.c | 64 +++++++------ drivers/cxl/core/mbox.c | 2 + drivers/cxl/core/pci.c | 174 ++++++++++++++++++++++++++++++++--- drivers/cxl/core/port.c | 60 ++++++++++-- drivers/cxl/core/regs.c | 46 ++++++++- drivers/cxl/cxl.h | 16 +++- drivers/cxl/cxlmem.h | 4 +- drivers/cxl/mem.c | 4 +- drivers/cxl/pci.c | 13 ++- drivers/pci/pcie/Kconfig | 12 +++ drivers/pci/pcie/aer.c | 162 ++++++++++++++++++++++++++++++-- include/linux/aer.h | 2 +- tools/testing/cxl/test/mem.c | 1 - 14 files changed, 491 insertions(+), 76 deletions(-)
Signature · 1 line
2.34.1
PATCH v10 1/15 cxl/port: Pre-initialize component register mappings
From: Robert Richter <[email protected]>
The component registers of a component may not exist and cxl_setup_comp_regs() will fail for that reason. In another case, Software may not use and set those registers up. cxl_setup_comp_regs() is then called with a base address of CXL_RESOURCE_NONE. Both are valid cases, but the function returns without initializing the register map.
Now, a missing component register block is not necessarily a reason to fail (feature is optional or its existence checked later). Change cxl_setup_comp_regs() to also use components with the component register block missing. Thus, always initialize struct cxl_register_map with valid values, set @dev and make @resource CXL_RESOURCE_NONE.
The change is in preparation of follow-on patches.
--- drivers/cxl/core/port.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/cxl/core/port.c +7 -5
@@ -693,16 +693,18 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev,static int cxl_setup_comp_regs (struct device *dev,struct cxl_register_map *map,resource_size_t component_reg_phys) { -if (component_reg_phys ==CXL_RESOURCE_NONE ) -return 0 ; - *map = (struct cxl_register_map ) { .dev = dev, - .reg_type =CXL_REGLOC_RBI_COMPONENT , + .reg_type =CXL_REGLOC_RBI_EMPTY , .resource = component_reg_phys, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , }; +if (component_reg_phys ==CXL_RESOURCE_NONE ) +return 0 ; + + map->reg_type =CXL_REGLOC_RBI_COMPONENT ; + map->max_size =CXL_COMPONENT_REG_BLOCK_SIZE ; +return cxl_setup_regs (map); }
Signature · 1 line
2.34.1
PATCH v10 2/15 cxl/regs: Prepare for multiple users of register mappings
In reply to Terry BowmanFrom: Robert Richter <[email protected]>
The function devm_cxl_iomap_block() is used to map register mappings of CXL component or device registers. A @dev is used to unmap the IO regions during device removal.
Now, there are multiple devices using the register mappings. E.g. the RAS cap of the Component Registers is used by cxl_pci, the HDM cap used in cxl_mem. This could cause IO blocks not being freed and a subsequent reinitialization to fail if the same device is used for both.
To prevent that, expand cxl_map_component_regs() to pass a @dev to be used with devm to IO unmap. This allows to pass the device that actually is creating and using the IO region.
For symmetry also change the function i/f of cxl_map_device_regs().
--- drivers/cxl/core/hdm.c | 3 ++- drivers/cxl/core/regs.c | 4 ++-- drivers/cxl/cxl.h | 2 ++ drivers/cxl/pci.c | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-)
drivers/cxl/core/hdm.c +2 -1
@@ -98,7 +98,8 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,return -ENODEV ; } -return cxl_map_component_regs (&map, regs,BIT (CXL_CM_CAP_CAP_ID_HDM )); +return cxl_map_component_regs (&map, &port->dev, regs, +BIT (CXL_CM_CAP_CAP_ID_HDM )); }static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info)
drivers/cxl/core/regs.c +2 -2
@@ -201,10 +201,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, }int cxl_map_component_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_component_regs *regs,unsigned long map_mask) { -struct device *dev = map->dev;struct mapinfo {const struct cxl_reg_map *rmap;void __iomem **addr;
@@ -235,9 +235,9 @@ int cxl_map_component_regs(const struct cxl_register_map *map,EXPORT_SYMBOL_NS_GPL (cxl_map_component_regs,CXL );int cxl_map_device_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_device_regs *regs) { -struct device *dev = map->dev;resource_size_t phys_addr = map->resource;struct mapinfo {const struct cxl_reg_map *rmap;
drivers/cxl/cxl.h +2 -0
@@ -274,9 +274,11 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,void cxl_probe_device_regs (struct device *dev,void __iomem *base,struct cxl_device_reg_map *map);int cxl_map_component_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_component_regs *regs,unsigned long map_mask);int cxl_map_device_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_device_regs *regs);int cxl_map_pmu_regs (struct pci_dev *pdev,struct cxl_pmu_regs *regs,struct cxl_register_map *map);
drivers/cxl/pci.c +2 -2
@@ -827,7 +827,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; - rc =cxl_map_device_regs (&map, &cxlds->regs.device_regs); + rc =cxl_map_device_regs (&map, cxlds->dev, &cxlds->regs.device_regs);if (rc)return rc;
@@ -844,7 +844,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) cxlds->component_reg_phys = map.resource; - rc =cxl_map_component_regs (&map, &cxlds->regs.component, + rc =cxl_map_component_regs (&map, cxlds->dev, &cxlds->regs.component,BIT (CXL_CM_CAP_CAP_ID_RAS ));if (rc)dev_dbg (&pdev->dev,"Failed to map RAS capability.\n" );
Signature · 1 line
2.34.1
Re: [PATCH v10 02/15] cxl/regs: Prepare for multiple users of register mappings
Quoted 16 lines · On Thu, 31 Aug 2023 10:20:18 -0500 Terry Bowman <[email protected]> wrote:
From: Robert Richter <[email protected]>
The function
devm_cxl_iomap_block()is used to map register mappings of CXL component or device registers. A @dev is used to unmap the IO regions during device removal.Now, there are multiple devices using the register mappings. E.g. the RAS cap of the Component Registers is used by
cxl_pci, the HDM cap used incxl_mem. This could cause IO blocks not being freed and a subsequent reinitialization to fail if the same device is used for both.To prevent that, expand
cxl_map_component_regs()to pass a @dev to be used with devm to IO unmap. This allows to pass the device that actually is creating and using the IO region.
Quoted 5 lines
For symmetry also change the function i/f of
cxl_map_device_regs().Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>
I was ambiguous in reply to previous, but my RB not valid here as it stands. Just replying so that doesn't get lost for v11!
Quoted 86 lines
--- drivers/cxl/core/hdm.c | 3 ++- drivers/cxl/core/regs.c | 4 ++-- drivers/cxl/cxl.h | 2 ++ drivers/cxl/pci.c | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-)drivers/cxl/core/hdm.c +2
-1@@ -98,7 +98,8 @@ static int map_hdm_decoder_regs(struct cxl_port *port, void __iomem *crb,return -ENODEV ; } -return cxl_map_component_regs (&map, regs,BIT (CXL_CM_CAP_CAP_ID_HDM )); +return cxl_map_component_regs (&map, &port->dev, regs, +BIT (CXL_CM_CAP_CAP_ID_HDM )); }static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info)drivers/cxl/core/regs.c +2
-2@@ -201,10 +201,10 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, }int cxl_map_component_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_component_regs *regs,unsigned long map_mask) { -struct device *dev = map->dev;struct mapinfo {const struct cxl_reg_map *rmap;void __iomem **addr;@@ -235,9 +235,9 @@ int cxl_map_component_regs(const struct cxl_register_map *map,EXPORT_SYMBOL_NS_GPL (cxl_map_component_regs,CXL );int cxl_map_device_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_device_regs *regs) { -struct device *dev = map->dev;resource_size_t phys_addr = map->resource;struct mapinfo {const struct cxl_reg_map *rmap;drivers/cxl/cxl.h +2
-0@@ -274,9 +274,11 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base,void cxl_probe_device_regs (struct device *dev,void __iomem *base,struct cxl_device_reg_map *map);int cxl_map_component_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_component_regs *regs,unsigned long map_mask);int cxl_map_device_regs (const struct cxl_register_map *map, +struct device *dev,struct cxl_device_regs *regs);int cxl_map_pmu_regs (struct pci_dev *pdev,struct cxl_pmu_regs *regs,struct cxl_register_map *map);drivers/cxl/pci.c +2
-2@@ -827,7 +827,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (rc)return rc; - rc =cxl_map_device_regs (&map, &cxlds->regs.device_regs); + rc =cxl_map_device_regs (&map, cxlds->dev, &cxlds->regs.device_regs);if (rc)return rc;@@ -844,7 +844,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) cxlds->component_reg_phys = map.resource; - rc =cxl_map_component_regs (&map, &cxlds->regs.component, + rc =cxl_map_component_regs (&map, cxlds->dev, &cxlds->regs.component,BIT (CXL_CM_CAP_CAP_ID_RAS ));if (rc)dev_dbg (&pdev->dev,"Failed to map RAS capability.\n" );
Re: [PATCH v10 02/15] cxl/regs: Prepare for multiple users of register mappings
Quoted 19 lines · Jonathan Cameron
Quoted 16 lines · On Thu, 31 Aug 2023 10:20:18 -0500 Terry Bowman <[email protected]> wrote:
From: Robert Richter <[email protected]>
The function
devm_cxl_iomap_block()is used to map register mappings of CXL component or device registers. A @dev is used to unmap the IO regions during device removal.Now, there are multiple devices using the register mappings. E.g. the RAS cap of the Component Registers is used by
cxl_pci, the HDM cap used incxl_mem. This could cause IO blocks not being freed and a subsequent reinitialization to fail if the same device is used for both.To prevent that, expand
cxl_map_component_regs()to pass a @dev to be used with devm to IO unmap. This allows to pass the device that actually is creating and using the IO region.
Quoted 8 lines
Quoted 5 lines
For symmetry also change the function i/f of
cxl_map_device_regs().Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>I was ambiguous in reply to previous, but my RB not valid here as it stands. Just replying so that doesn't get lost for v11!
Yes, sorry, I wrongly assumed it here. Will remove for v11.
Thanks,
-Robert
PATCH v10 3/15 cxl/pci: Store the endpoint's Component Register mappings in struct cxl_dev_state
In reply to Terry BowmanFrom: Robert Richter <[email protected]>
Same as for ports and dports, also store the endpoint's Component Register mappings, use struct cxl_dev_state for that.
Keep the Component Register base address @component_reg_phys a bit to not break functionality. It will be removed after the transition in a later patch.
--- drivers/cxl/core/mbox.c | 2 ++ drivers/cxl/cxlmem.h | 2 ++ drivers/cxl/pci.c | 10 ++++++---- 3 files changed, 10 insertions(+), 4 deletions(-)
drivers/cxl/core/mbox.c +2 -0
@@ -1333,6 +1333,8 @@ struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev)mutex_init (&mds->mbox_mutex);mutex_init (&mds->event.log_lock); mds->cxlds.dev = dev; + mds->cxlds.comp_map.dev = dev; + mds->cxlds.comp_map.resource =CXL_RESOURCE_NONE ; mds->cxlds.type =CXL_DEVTYPE_CLASSMEM ;return mds;
drivers/cxl/cxlmem.h +2 -0
@@ -382,6 +382,7 @@ enum cxl_devtype {* * @dev: The device associated with this CXL state * @cxlmd: The device representing the CXL.mem capabilities of @dev +* @comp_map: component register capability mappings * @regs: Parsed register blocks * @cxl_dvsec: Offset to the PCIe device DVSEC * @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
@@ -396,6 +397,7 @@ enum cxl_devtype {struct cxl_dev_state {struct device *dev;struct cxl_memdev *cxlmd; +struct cxl_register_map comp_map;struct cxl_regs regs;int cxl_dvsec;bool rcd;
drivers/cxl/pci.c +6 -4
@@ -836,15 +836,17 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)* still be useful for management functions so don't return an error. */ cxlds->component_reg_phys =CXL_RESOURCE_NONE ; - rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &map); + rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , + &cxlds->comp_map);if (rc)dev_warn (&pdev->dev,"No component registers (%d)\n" , rc); -else if (!map.component_map.ras.valid) +else if (!cxlds->comp_map.component_map.ras.valid)dev_dbg (&pdev->dev,"RAS registers not found\n" ); - cxlds->component_reg_phys = map.resource; + cxlds->component_reg_phys = cxlds->comp_map.resource; - rc =cxl_map_component_regs (&map, cxlds->dev, &cxlds->regs.component, + rc =cxl_map_component_regs (&cxlds->comp_map, cxlds->dev, + &cxlds->regs.component,BIT (CXL_CM_CAP_CAP_ID_RAS ));if (rc)dev_dbg (&pdev->dev,"Failed to map RAS capability.\n" );
Signature · 1 line
2.34.1
PATCH v10 4/15 cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
In reply to Terry BowmanFrom: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Provide a helper function cxl_port_get_comp_map() to locate the mappings depending on the component's type.
--- drivers/cxl/core/hdm.c | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-)
drivers/cxl/core/hdm.c +35 -30
@@ -81,27 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .dev = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, &port->dev, regs, -BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;
@@ -146,6 +125,22 @@ static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)return true; } +static struct cxl_register_map *cxl_port_get_comp_map (struct cxl_port *port) +{ +/* +* HDM capability applies to Endpoints, USPs and VH Host +* Bridges. The Endpoint's component register mappings are +* located in the cxlds. +*/ +if (is_cxl_endpoint (port)) { +struct cxl_memdev *memdev =to_cxl_memdev (port->uport_dev); + +return &memdev->cxlds->comp_map; + } + +return &port->comp_map; +} +/** * devm_cxl_setup_hdm - map HDM decoder component registers * @port: cxl_port to map
@@ -156,7 +151,7 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, {struct device *dev = &port->dev;struct cxl_hdm *cxlhdm; -void __iomem *crb; +struct cxl_register_map *comp_map;int rc; cxlhdm =devm_kzalloc (dev,sizeof (*cxlhdm),GFP_KERNEL );
@@ -165,19 +160,29 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, cxlhdm->port = port;dev_set_drvdata (dev, cxlhdm); - crb =ioremap (port->component_reg_phys,CXL_COMPONENT_REG_BLOCK_SIZE ); -if (!crb && info && info->mem_enabled) { - cxlhdm->decoder_count = info->ranges; -return cxlhdm; - }else if (!crb) { + comp_map =cxl_port_get_comp_map (port); + +if (comp_map->resource ==CXL_RESOURCE_NONE ) { +if (info && info->mem_enabled) { + cxlhdm->decoder_count = info->ranges; +return cxlhdm; + }dev_err (dev,"No component registers mapped\n" );return ERR_PTR (-ENXIO ); } - rc =map_hdm_decoder_regs (port, crb, &cxlhdm->regs); -iounmap (crb); -if (rc) +if (!comp_map->component_map.hdm_decoder.valid) { +dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); +/* unique error code to indicate no HDM decoder capability */ +return ERR_PTR (-ENODEV ); + } + + rc =cxl_map_component_regs (comp_map, dev, &cxlhdm->regs, +BIT (CXL_CM_CAP_CAP_ID_HDM )); +if (rc) { +dev_dbg (dev,"Failed to map HDM capability.\n" );return ERR_PTR (rc); + }parse_hdm_decoder_caps (cxlhdm);if (cxlhdm->decoder_count ==0 ) {
Signature · 1 line
2.34.1
RE: [PATCH v10 04/15] cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
Quoted 61 lines · Terry Bowman
From: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Provide a helper function
cxl_port_get_comp_map()to locate the mappings depending on the component's type.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/cxl/core/hdm.c +5
-21@@ -81,27 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .dev = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, &port->dev, regs, -BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;@@ -146,6 +125,22 @@ static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)return true; } +static struct cxl_register_map *cxl_port_get_comp_map (struct cxl_port *port) +{ +/* +* HDM capability applies to Endpoints, USPs and VH Host +* Bridges. The Endpoint's component register mappings are
drivers/cxl/core/hdm.c static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info) · line 142
Quoted 10 lines
drivers/cxl/core/hdm.c +10
-0+* located in the cxlds. +*/ +if (is_cxl_endpoint (port)) { +struct cxl_memdev *memdev =to_cxl_memdev (port->uport_dev); + +return &memdev->cxlds->comp_map; + } + +return &port->comp_map; +}
This was the function I was hoping would disappear in the new version. cxl_pci and cxl_port care about different register blocks and have different mapping lifetimes. I think that justifies having the endpoint->comp_map be valid for everything that the cxl_port driver cares about even though it duplicates some informatiom from cxlds->comp_map.
Dan Williams
Reviewed-by Dave JiangRE: [PATCH v10 04/15] cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
Quoted 71 lines · Dan Williams
Quoted 70 lines · Terry Bowman
From: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Provide a helper function
cxl_port_get_comp_map()to locate the mappings depending on the component's type.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/cxl/core/hdm.c +14
-21@@ -81,27 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .dev = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, &port->dev, regs, -BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;@@ -146,6 +125,22 @@ static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)return true; } +static struct cxl_register_map *cxl_port_get_comp_map (struct cxl_port *port) +{ +/* +* HDM capability applies to Endpoints, USPs and VH Host +* Bridges. The Endpoint's component register mappings are +* located in the cxlds. +*/ +if (is_cxl_endpoint (port)) { +struct cxl_memdev *memdev =to_cxl_memdev (port->uport_dev); + +return &memdev->cxlds->comp_map; + } + +return &port->comp_map;
Quoted 8 lines
drivers/cxl/core/hdm.c static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info) · line 142
Quoted 1 line
drivers/cxl/core/hdm.c +1
-0+}This was the function I was hoping would disappear in the new version.
cxl_pciandcxl_portcare about different register blocks and have different mapping lifetimes. I think that justifies having theendpoint->comp_mapbe valid for everything that thecxl_portdriver cares about even though it duplicates some informatiom fromcxlds->comp_map.
In the interest of time I went ahead and reflowed this patch to the below and it is passing my tests. I also noticed some other @dev vs @host confusion in some of the previous register conversion so perhaps I should just send out v11 with this all rolled together...
-- >8 --
Subject: cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
From: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Duplicate the cxlds->comp_map in port->comp_map for endpoint ports.
--- drivers/cxl/core/hdm.c | 48 +++++++++++++++++++---------------------------- drivers/cxl/core/port.c | 29 ++++++++++++++++++++++------ drivers/cxl/mem.c | 5 ++--- 3 files changed, 43 insertions(+), 39 deletions(-)
drivers/cxl/core/hdm.c +19 -29
@@ -81,26 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .host = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, regs,BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;
@@ -155,7 +135,7 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, {struct device *dev = &port->dev;struct cxl_hdm *cxlhdm; -void __iomem *crb; +struct cxl_register_map *comp_map;int rc; cxlhdm =devm_kzalloc (dev,sizeof (*cxlhdm),GFP_KERNEL );
@@ -164,19 +144,29 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, cxlhdm->port = port;dev_set_drvdata (dev, cxlhdm); - crb =ioremap (port->component_reg_phys,CXL_COMPONENT_REG_BLOCK_SIZE ); -if (!crb && info && info->mem_enabled) { - cxlhdm->decoder_count = info->ranges; -return cxlhdm; - }else if (!crb) { + comp_map = &port->comp_map; +if (comp_map->resource ==CXL_RESOURCE_NONE ) { +if (info && info->mem_enabled) { + cxlhdm->decoder_count = info->ranges; +return cxlhdm; + } +WARN_ON (1 );dev_err (dev,"No component registers mapped\n" );return ERR_PTR (-ENXIO ); } - rc =map_hdm_decoder_regs (port, crb, &cxlhdm->regs); -iounmap (crb); -if (rc) +if (!comp_map->component_map.hdm_decoder.valid) { +dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); +/* unique error code to indicate no HDM decoder capability */ +return ERR_PTR (-ENODEV ); + } + + rc =cxl_map_component_regs (comp_map, &cxlhdm->regs, +BIT (CXL_CM_CAP_CAP_ID_HDM )); +if (rc) { +dev_dbg (dev,"Failed to map HDM capability.\n" );return ERR_PTR (rc); + }parse_hdm_decoder_caps (cxlhdm);if (cxlhdm->decoder_count ==0 ) {
drivers/cxl/core/port.c +22 -7
@@ -741,16 +741,31 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host,return port; dev = &port->dev; -if (is_cxl_memdev (uport_dev)) +if (is_cxl_memdev (uport_dev)) { +struct cxl_memdev *cxlmd =to_cxl_memdev (uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; + rc =dev_set_name (dev,"endpoint%d" , port->id); -else if (parent_dport) +if (rc) + goto err; + +/* +* The endpoint driver already enumerated the component and RAS +* registers. Reuse that enumeration while prepping them to be +* mapped by the cxl_port driver. +*/ + port->comp_map = cxlds->comp_map; + port->comp_map.host = &port->dev; + }else if (parent_dport) { rc =dev_set_name (dev,"port%d" , port->id); -else - rc =dev_set_name (dev,"root%d" , port->id); -if (rc) - goto err; +if (rc) + goto err; - rc =cxl_port_setup_regs (port, component_reg_phys); + rc =cxl_port_setup_regs (port, component_reg_phys); +if (rc) + goto err; + }else + rc =dev_set_name (dev,"root%d" , port->id);if (rc) goto err;
drivers/cxl/mem.c +2 -3
@@ -49,7 +49,6 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, struct cxl_dport *parent_dport) {struct cxl_port *parent_port = parent_dport->port; -struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_port *endpoint, *iter, *down;int rc;
@@ -65,8 +64,8 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, ep->next = down; } - endpoint =devm_cxl_add_port (host, &cxlmd->dev, - cxlds->component_reg_phys, +/* Note: endpoint port component registers are derived from @cxlds */ + endpoint =devm_cxl_add_port (host, &cxlmd->dev,CXL_RESOURCE_NONE , parent_dport);if (IS_ERR (endpoint))return PTR_ERR (endpoint);
Re: [PATCH v10 04/15] cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
Dan,
Quoted 81 lines · Dan Williams
Quoted 71 lines · Dan Williams
Quoted 70 lines · Terry Bowman
From: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Provide a helper function
cxl_port_get_comp_map()to locate the mappings depending on the component's type.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/cxl/core/hdm.c +14
-21@@ -81,27 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .dev = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, &port->dev, regs, -BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;@@ -146,6 +125,22 @@ static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)return true; } +static struct cxl_register_map *cxl_port_get_comp_map (struct cxl_port *port) +{ +/* +* HDM capability applies to Endpoints, USPs and VH Host +* Bridges. The Endpoint's component register mappings are +* located in the cxlds. +*/ +if (is_cxl_endpoint (port)) { +struct cxl_memdev *memdev =to_cxl_memdev (port->uport_dev); + +return &memdev->cxlds->comp_map; + } + +return &port->comp_map;Quoted 8 lines
drivers/cxl/core/hdm.c static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info) · line 142
Quoted 1 line
drivers/cxl/core/hdm.c +1
-0+}This was the function I was hoping would disappear in the new version.
cxl_pciandcxl_portcare about different register blocks and have different mapping lifetimes. I think that justifies having theendpoint->comp_mapbe valid for everything that thecxl_portdriver cares about even though it duplicates some informatiom fromcxlds->comp_map.
Quoted 4 lines
In the interest of time I went ahead and reflowed this patch to the below and it is passing my tests. I also noticed some other @dev vs @host confusion in some of the previous register conversion so perhaps I should just send out v11 with this all rolled together...
just a quick update here.
We were going to send v11 a couple of days ago but I found an issue during testing, see below. If you don't mind I will send it out next week with a fix for that included.
Quoted 20 lines
-- >8 --
Subject: cxl/hdm: Use stored Component Register mappings to map HDM decoder capabilityFrom: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Duplicate the
cxlds->comp_mapinport->comp_mapfor endpoint ports.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Dave Jiang <[email protected]>[rework to drop cxl_port_get_comp_map()]Signed-off-by Dan Williams <[email protected]>
Quoted 5 lines
--- drivers/cxl/core/hdm.c | 48 +++++++++++++++++++---------------------------- drivers/cxl/core/port.c | 29 ++++++++++++++++++++++------ drivers/cxl/mem.c | 5 ++--- 3 files changed, 43 insertions(+), 39 deletions(-)
Patch look good to me.
I have a similar implementation, but did that with a cxl_port_clone_regs() function in cxl_endpoint_port_probe(). I can take this version instead.
During testing I found an issue freeing IO resources with devm for RCH mode. The endpoint is not removed if the cxl_mem driver is unbound. Then, the resources of the endpoint that also holds the IO mappings are not freed. A subsequent IO map fails when rebinding the driver again. It looks like cxl_mem_find_port() is broken for RCDs preventing the port from being autoremoved. I am working on a fix for this and will test the whole series again.
Thanks,
-Robert
Quoted 145 lines
drivers/cxl/core/hdm.c +19
-29@@ -81,26 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .host = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, regs,BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;@@ -155,7 +135,7 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, {struct device *dev = &port->dev;struct cxl_hdm *cxlhdm; -void __iomem *crb; +struct cxl_register_map *comp_map;int rc; cxlhdm =devm_kzalloc (dev,sizeof (*cxlhdm),GFP_KERNEL );@@ -164,19 +144,29 @@ struct cxl_hdm *devm_cxl_setup_hdm(struct cxl_port *port, cxlhdm->port = port;dev_set_drvdata (dev, cxlhdm); - crb =ioremap (port->component_reg_phys,CXL_COMPONENT_REG_BLOCK_SIZE ); -if (!crb && info && info->mem_enabled) { - cxlhdm->decoder_count = info->ranges; -return cxlhdm; - }else if (!crb) { + comp_map = &port->comp_map; +if (comp_map->resource ==CXL_RESOURCE_NONE ) { +if (info && info->mem_enabled) { + cxlhdm->decoder_count = info->ranges; +return cxlhdm; + } +WARN_ON (1 );dev_err (dev,"No component registers mapped\n" );return ERR_PTR (-ENXIO ); } - rc =map_hdm_decoder_regs (port, crb, &cxlhdm->regs); -iounmap (crb); -if (rc) +if (!comp_map->component_map.hdm_decoder.valid) { +dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); +/* unique error code to indicate no HDM decoder capability */ +return ERR_PTR (-ENODEV ); + } + + rc =cxl_map_component_regs (comp_map, &cxlhdm->regs, +BIT (CXL_CM_CAP_CAP_ID_HDM )); +if (rc) { +dev_dbg (dev,"Failed to map HDM capability.\n" );return ERR_PTR (rc); + }parse_hdm_decoder_caps (cxlhdm);if (cxlhdm->decoder_count ==0 ) {drivers/cxl/core/port.c +22
-7@@ -741,16 +741,31 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host,return port; dev = &port->dev; -if (is_cxl_memdev (uport_dev)) +if (is_cxl_memdev (uport_dev)) { +struct cxl_memdev *cxlmd =to_cxl_memdev (uport_dev); +struct cxl_dev_state *cxlds = cxlmd->cxlds; + rc =dev_set_name (dev,"endpoint%d" , port->id); -else if (parent_dport) +if (rc) + goto err; + +/* +* The endpoint driver already enumerated the component and RAS +* registers. Reuse that enumeration while prepping them to be +* mapped by the cxl_port driver. +*/ + port->comp_map = cxlds->comp_map; + port->comp_map.host = &port->dev; + }else if (parent_dport) { rc =dev_set_name (dev,"port%d" , port->id); -else - rc =dev_set_name (dev,"root%d" , port->id); -if (rc) - goto err; +if (rc) + goto err; - rc =cxl_port_setup_regs (port, component_reg_phys); + rc =cxl_port_setup_regs (port, component_reg_phys); +if (rc) + goto err; + }else + rc =dev_set_name (dev,"root%d" , port->id);if (rc) goto err;drivers/cxl/mem.c +2
-3@@ -49,7 +49,6 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, struct cxl_dport *parent_dport) {struct cxl_port *parent_port = parent_dport->port; -struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_port *endpoint, *iter, *down;int rc;@@ -65,8 +64,8 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, ep->next = down; } - endpoint =devm_cxl_add_port (host, &cxlmd->dev, - cxlds->component_reg_phys, +/* Note: endpoint port component registers are derived from @cxlds */ + endpoint =devm_cxl_add_port (host, &cxlmd->dev,CXL_RESOURCE_NONE , parent_dport);if (IS_ERR (endpoint))return PTR_ERR (endpoint);
Re: [PATCH v10 04/15] cxl/hdm: Use stored Component Register mappings to map HDM decoder capability
Quoted 89 lines · Robert Richter
Dan,
Quoted 81 lines · Dan Williams
Quoted 71 lines · Dan Williams
Quoted 70 lines · Terry Bowman
From: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Provide a helper function
cxl_port_get_comp_map()to locate the mappings depending on the component's type.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/hdm.c | 65 +++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-)drivers/cxl/core/hdm.c +14
-21@@ -81,27 +81,6 @@ static void parse_hdm_decoder_caps(struct cxl_hdm *cxlhdm) cxlhdm->interleave_mask |=GENMASK (14 ,12 ); } -static int map_hdm_decoder_regs (struct cxl_port *port,void __iomem *crb, -struct cxl_component_regs *regs) -{ -struct cxl_register_map map = { - .dev = &port->dev, - .resource = port->component_reg_phys, - .base = crb, - .max_size =CXL_COMPONENT_REG_BLOCK_SIZE , - }; - -cxl_probe_component_regs (&port->dev, crb, &map.component_map); -if (!map.component_map.hdm_decoder.valid) { -dev_dbg (&port->dev,"HDM decoder registers not implemented\n" ); -/* unique error code to indicate no HDM decoder capability */ -return -ENODEV ; - } - -return cxl_map_component_regs (&map, &port->dev, regs, -BIT (CXL_CM_CAP_CAP_ID_HDM )); -} -static bool should_emulate_decoders (struct cxl_endpoint_dvsec_info *info) {struct cxl_hdm *cxlhdm;@@ -146,6 +125,22 @@ static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info)return true; } +static struct cxl_register_map *cxl_port_get_comp_map (struct cxl_port *port) +{ +/* +* HDM capability applies to Endpoints, USPs and VH Host +* Bridges. The Endpoint's component register mappings are +* located in the cxlds. +*/ +if (is_cxl_endpoint (port)) { +struct cxl_memdev *memdev =to_cxl_memdev (port->uport_dev); + +return &memdev->cxlds->comp_map; + } + +return &port->comp_map;Quoted 8 lines
drivers/cxl/core/hdm.c static bool should_emulate_decoders(struct cxl_endpoint_dvsec_info *info) · line 142
Quoted 1 line
drivers/cxl/core/hdm.c +1
-0+}This was the function I was hoping would disappear in the new version.
cxl_pciandcxl_portcare about different register blocks and have different mapping lifetimes. I think that justifies having theendpoint->comp_mapbe valid for everything that thecxl_portdriver cares about even though it duplicates some informatiom fromcxlds->comp_map.Quoted 4 lines
In the interest of time I went ahead and reflowed this patch to the below and it is passing my tests. I also noticed some other @dev vs @host confusion in some of the previous register conversion so perhaps I should just send out v11 with this all rolled together...
Quoted 5 lines
just a quick update here.
We were going to send v11 a couple of days ago but I found an issue during testing, see below. If you don't mind I will send it out next week with a fix for that included.
Sounds good, I will wait for that update. I had found a couple more issues as well, like come some confusion on the @host for cxl_dport register mapping. I will send just that out so you can incorporate.
There was also the feedback on moving register mapping calls out of the __devm_cxl_add_dport() and into the driver that makes use of them. Similar for root port interrupt enabling.
Quoted 33 lines
Quoted 21 lines
-- >8 --
Subject: cxl/hdm: Use stored Component Register mappings to map HDM decoder capabilityFrom: Robert Richter <[email protected]>
Now, that the Component Register mappings are stored, use them to enable and map the HDM decoder capabilities. The Component Registers do not need to be probed again for this, remove probing code.
The HDM capability applies to Endpoints, USPs and VH Host Bridges. The Endpoint's component register mappings are located in the cxlds and else in the port's structure. Duplicate the
cxlds->comp_mapinport->comp_mapfor endpoint ports.Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Dave Jiang <[email protected]>[rework to drop cxl_port_get_comp_map()]Signed-off-by Dan Williams <[email protected]>Quoted 5 lines
--- drivers/cxl/core/hdm.c | 48 +++++++++++++++++++---------------------------- drivers/cxl/core/port.c | 29 ++++++++++++++++++++++------ drivers/cxl/mem.c | 5 ++--- 3 files changed, 43 insertions(+), 39 deletions(-)Patch look good to me.
I have a similar implementation, but did that with a
cxl_port_clone_regs()function incxl_endpoint_port_probe(). I can take this version instead.
Quoted 7 lines
During testing I found an issue freeing IO resources with devm for RCH mode. The endpoint is not removed if the
cxl_memdriver is unbound. Then, the resources of the endpoint that also holds the IO mappings are not freed. A subsequent IO map fails when rebinding the driver again. It looks likecxl_mem_find_port()is broken for RCDs preventing the port from being autoremoved. I am working on a fix for this and will test the whole series again.
Oh, I see that bug, yes, good find. The cxl-topology.sh test is only checking for endpoint port removal on parent port removal, but RCDs do not have the same port interaction when the cxl_mem driver detaches.
I expect you found that delete_enpoint() is the problem in that it assumes the parent_port has a driver, which for RCH it does not because that's the CXL root port.
In any event, glad to see this moving forward, and glad to let you drive the next version.
PATCH v10 5/15 cxl/pci: Remove Component Register base address from struct cxl_dev_state
In reply to Terry BowmanFrom: Robert Richter <[email protected]>
The Component Register base address @component_reg_phys is no longer used after the rework of the Component Register setup which now uses struct member @comp_map instead. Remove the base address.
--- drivers/cxl/cxlmem.h | 2 -- drivers/cxl/mem.c | 4 ++-- drivers/cxl/pci.c | 3 --- tools/testing/cxl/test/mem.c | 1 - 4 files changed, 2 insertions(+), 8 deletions(-)
drivers/cxl/cxlmem.h +0 -2
@@ -390,7 +390,6 @@ enum cxl_devtype {* @dpa_res: Overall DPA resource tree for the device * @pmem_res: Active Persistent memory capacity configuration * @ram_res: Active Volatile memory capacity configuration -* @component_reg_phys: register base of component registers * @serial: PCIe Device Serial Number * @type: Generic Memory Class device or Vendor Specific Memory device */
@@ -405,7 +404,6 @@ struct cxl_dev_state {struct resource dpa_res;struct resource pmem_res;struct resource ram_res; -resource_size_t component_reg_phys;u64 serial;enum cxl_devtype type; };
drivers/cxl/mem.c +2 -2
@@ -49,7 +49,6 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, struct cxl_dport *parent_dport) {struct cxl_port *parent_port = parent_dport->port; -struct cxl_dev_state *cxlds = cxlmd->cxlds;struct cxl_port *endpoint, *iter, *down;int rc;
@@ -65,8 +64,9 @@ static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, ep->next = down; } +/* The Endpoint's component regs are located in cxlds. */ endpoint =devm_cxl_add_port (host, &cxlmd->dev, - cxlds->component_reg_phys, +CXL_RESOURCE_NONE , parent_dport);if (IS_ERR (endpoint))return PTR_ERR (endpoint);
drivers/cxl/pci.c +0 -3
@@ -835,7 +835,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)* 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. */ - cxlds->component_reg_phys =CXL_RESOURCE_NONE ; rc =cxl_pci_setup_regs (pdev,CXL_REGLOC_RBI_COMPONENT , &cxlds->comp_map);if (rc)
@@ -843,8 +842,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)else if (!cxlds->comp_map.component_map.ras.valid)dev_dbg (&pdev->dev,"RAS registers not found\n" ); - cxlds->component_reg_phys = cxlds->comp_map.resource; - rc =cxl_map_component_regs (&cxlds->comp_map, cxlds->dev, &cxlds->regs.component,BIT (CXL_CM_CAP_CAP_ID_RAS ));
tools/testing/cxl/test/mem.c +0 -1
@@ -1423,7 +1423,6 @@ static int cxl_mock_mem_probe(struct platform_device *pdev) cxlds->serial = pdev->id;if (is_rcd (pdev)) { cxlds->rcd = true; - cxlds->component_reg_phys =CXL_RESOURCE_NONE ; } rc =cxl_enumerate_cmds (mds);
Signature · 1 line
2.34.1
PATCH v10 6/15 cxl/port: Remove Component Register base address from struct cxl_port
In reply to Terry BowmanFrom: Robert Richter <[email protected]>
The Component Register base address @component_reg_phys is no longer used after the rework of the Component Register setup which now uses struct member @comp_map instead. Remove the base address.
--- drivers/cxl/core/port.c | 4 +--- drivers/cxl/cxl.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-)
drivers/cxl/core/port.c +1 -3
@@ -618,7 +618,6 @@ static int devm_cxl_link_parent_dport(struct device *host,static struct lock_class_key cxl_port_key;static struct cxl_port *cxl_port_alloc (struct device *uport_dev, -resource_size_t component_reg_phys,struct cxl_dport *parent_dport) {struct cxl_port *port;
@@ -669,7 +668,6 @@ static struct cxl_port *cxl_port_alloc(struct device *uport_dev, }else dev->parent = uport_dev; - port->component_reg_phys = component_reg_phys;ida_init (&port->decoder_ida); port->hdm_end =-1 ; port->commit_end =-1 ;
@@ -731,7 +729,7 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host,struct device *dev;int rc; - port =cxl_port_alloc (uport_dev, component_reg_phys, parent_dport); + port =cxl_port_alloc (uport_dev, parent_dport);if (IS_ERR (port))return port;
drivers/cxl/cxl.h +0 -2
@@ -578,7 +578,6 @@ struct cxl_dax_region {* @nr_dports: number of entries in @dports * @hdm_end: track last allocated HDM decoder instance for allocation ordering * @commit_end: cursor to track highest committed decoder for commit ordering -* @component_reg_phys: component register capability base address (optional) * @dead: last ep has been removed, force port re-creation * @depth: How deep this port is relative to the root. depth 0 is the root. * @cdat: Cached CDAT data
@@ -598,7 +597,6 @@ struct cxl_port {int nr_dports;int hdm_end;int commit_end; -resource_size_t component_reg_phys;bool dead;unsigned int depth;struct cxl_cdat {
Signature · 1 line
2.34.1
PATCH v10 7/15 cxl/pci: Add RCH downstream port AER register discovery
In reply to Terry BowmanRestricted CXL host (RCH) downstream port AER information is not currently logged while in the error state. One problem preventing the error logging is the AER and RAS registers are not accessible. The CXL driver requires changes to find RCH downstream port AER and RAS registers for purpose of error logging.
RCH downstream ports are not enumerated during a PCI bus scan and are instead discovered using system firmware, ACPI in this case.[1] The downstream port is implemented as a Root Complex Register Block (RCRB). The RCRB is a 4k memory block containing PCIe registers based on the PCIe root port.[2] The RCRB includes AER extended capability registers used for reporting errors. Note, the RCH's AER Capability is located in the RCRB memory space instead of PCI configuration space, thus its register access is different. Existing kernel PCIe AER functions can not be used to manage the downstream port AER capabilities and RAS registers because the port was not enumerated during PCI scan and the registers are not PCI config accessible.
Discover RCH downstream port AER extended capability registers. Use MMIO accesses to search for extended AER capability in RCRB register space.
[1] CXL 3.0 Spec, 9.11.2 - System Firmware View of CXL 1.1 Hierarchy
[2] CXL 3.0 Spec, 8.2.1.1 - RCH Downstream Port RCRB
--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 6 ++++++ drivers/cxl/core/regs.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+)
drivers/cxl/core/core.h +1 -0
@@ -73,6 +73,7 @@ struct cxl_rcrb_info;resource_size_t __rcrb_to_component (struct device *dev,struct cxl_rcrb_info *ri,enum cxl_rcrb which); +u16 cxl_rcrb_to_aer (struct device *dev,resource_size_t rcrb);extern struct rw_semaphore cxl_dpa_rwsem;
drivers/cxl/core/port.c +6 -0
@@ -979,6 +979,8 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENOMEM );if (rcrb !=CXL_RESOURCE_NONE ) { +struct pci_host_bridge *host_bridge; + dport->rcrb.base = rcrb; component_reg_phys =__rcrb_to_component (dport_dev, &dport->rcrb,CXL_RCRB_DOWNSTREAM );
@@ -987,6 +989,10 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENXIO ); } + host_bridge =to_pci_host_bridge (dport_dev); +if (host_bridge->native_cxl_error) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); + dport->rch = true; }
drivers/cxl/core/regs.c +35 -0
@@ -470,6 +470,41 @@ int cxl_setup_regs(struct cxl_register_map *map) }EXPORT_SYMBOL_NS_GPL (cxl_setup_regs,CXL ); +u16 cxl_rcrb_to_aer (struct device *dev,resource_size_t rcrb) +{ +void __iomem *addr; +u16 offset =0 ; +u32 cap_hdr; + +if (WARN_ON_ONCE (rcrb ==CXL_RESOURCE_NONE )) +return 0 ; + +if (!request_mem_region (rcrb,SZ_4K ,dev_name (dev))) +return 0 ; + + addr =ioremap (rcrb,SZ_4K ); +if (!addr) { +release_mem_region (rcrb,SZ_4K ); +return 0 ; + } + + cap_hdr =readl (addr + offset); +while (PCI_EXT_CAP_ID (cap_hdr) !=PCI_EXT_CAP_ID_ERR ) { + offset =PCI_EXT_CAP_NEXT (cap_hdr); +if (!offset) +break ; + cap_hdr =readl (addr + offset); + } + +if (offset) +dev_dbg (dev,"found AER extended capability (0x%x)\n" , offset); + +iounmap (addr); +release_mem_region (rcrb,SZ_4K ); + +return offset; +} +resource_size_t __rcrb_to_component (struct device *dev,struct cxl_rcrb_info *ri,enum cxl_rcrb which) {
Signature · 1 line
2.34.1
RE: [PATCH v10 07/15] cxl/pci: Add RCH downstream port AER register discovery
Quoted 61 lines · Terry Bowman
Restricted CXL host (RCH) downstream port AER information is not currently logged while in the error state. One problem preventing the error logging is the AER and RAS registers are not accessible. The CXL driver requires changes to find RCH downstream port AER and RAS registers for purpose of error logging.
RCH downstream ports are not enumerated during a PCI bus scan and are instead discovered using system firmware, ACPI in this case.[1] The downstream port is implemented as a Root Complex Register Block (RCRB). The RCRB is a 4k memory block containing PCIe registers based on the PCIe root port.[2] The RCRB includes AER extended capability registers used for reporting errors. Note, the RCH's AER Capability is located in the RCRB memory space instead of PCI configuration space, thus its register access is different. Existing kernel PCIe AER functions can not be used to manage the downstream port AER capabilities and RAS registers because the port was not enumerated during PCI scan and the registers are not PCI config accessible.
Discover RCH downstream port AER extended capability registers. Use MMIO accesses to search for extended AER capability in RCRB register space.
[1] CXL 3.0 Spec, 9.11.2 - System Firmware View of CXL 1.1 Hierarchy
[2] CXL 3.0 Spec, 8.2.1.1 - RCH Downstream Port RCRBCo-developed-by Robert Richter <[email protected]>Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 6 ++++++ drivers/cxl/core/regs.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+)drivers/cxl/core/core.h +1
-0@@ -73,6 +73,7 @@ struct cxl_rcrb_info;resource_size_t __rcrb_to_component (struct device *dev,struct cxl_rcrb_info *ri,enum cxl_rcrb which); +u16 cxl_rcrb_to_aer (struct device *dev,resource_size_t rcrb);extern struct rw_semaphore cxl_dpa_rwsem;drivers/cxl/core/port.c +2
-0@@ -979,6 +979,8 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENOMEM );if (rcrb !=CXL_RESOURCE_NONE ) { +struct pci_host_bridge *host_bridge; + dport->rcrb.base = rcrb; component_reg_phys =__rcrb_to_component (dport_dev, &dport->rcrb,CXL_RCRB_DOWNSTREAM );
drivers/cxl/core/port.c __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, · line 995
Quoted 7 lines
drivers/cxl/core/port.c +4
-0@@ -987,6 +989,10 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENXIO ); } + host_bridge =to_pci_host_bridge (dport_dev); +if (host_bridge->native_cxl_error) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +
Minor comment...
Is there a need to gate the discovery of the registers on the ACPI setting? For example cxl_pci unconditionally enumerates the RAS component register block but gates *using* them by ->native_cxl_error.
Re: [PATCH v10 07/15] cxl/pci: Add RCH downstream port AER register discovery
Hi Dan,
Thanks for reviewing. I added response below.
Quoted 72 lines · Dan Williams
Quoted 61 lines · Terry Bowman
Restricted CXL host (RCH) downstream port AER information is not currently logged while in the error state. One problem preventing the error logging is the AER and RAS registers are not accessible. The CXL driver requires changes to find RCH downstream port AER and RAS registers for purpose of error logging.
RCH downstream ports are not enumerated during a PCI bus scan and are instead discovered using system firmware, ACPI in this case.[1] The downstream port is implemented as a Root Complex Register Block (RCRB). The RCRB is a 4k memory block containing PCIe registers based on the PCIe root port.[2] The RCRB includes AER extended capability registers used for reporting errors. Note, the RCH's AER Capability is located in the RCRB memory space instead of PCI configuration space, thus its register access is different. Existing kernel PCIe AER functions can not be used to manage the downstream port AER capabilities and RAS registers because the port was not enumerated during PCI scan and the registers are not PCI config accessible.
Discover RCH downstream port AER extended capability registers. Use MMIO accesses to search for extended AER capability in RCRB register space.
[1] CXL 3.0 Spec, 9.11.2 - System Firmware View of CXL 1.1 Hierarchy
[2] CXL 3.0 Spec, 8.2.1.1 - RCH Downstream Port RCRBCo-developed-by Robert Richter <[email protected]>Signed-off-by Robert Richter <[email protected]>Signed-off-by Terry Bowman <[email protected]>Reviewed-by Jonathan Cameron <[email protected]>Reviewed-by Dave Jiang <[email protected]>--- drivers/cxl/core/core.h | 1 + drivers/cxl/core/port.c | 6 ++++++ drivers/cxl/core/regs.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+)drivers/cxl/core/core.h +1
-0@@ -73,6 +73,7 @@ struct cxl_rcrb_info;resource_size_t __rcrb_to_component (struct device *dev,struct cxl_rcrb_info *ri,enum cxl_rcrb which); +u16 cxl_rcrb_to_aer (struct device *dev,resource_size_t rcrb);extern struct rw_semaphore cxl_dpa_rwsem;drivers/cxl/core/port.c +2
-0@@ -979,6 +979,8 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENOMEM );if (rcrb !=CXL_RESOURCE_NONE ) { +struct pci_host_bridge *host_bridge; + dport->rcrb.base = rcrb; component_reg_phys =__rcrb_to_component (dport_dev, &dport->rcrb,CXL_RCRB_DOWNSTREAM );drivers/cxl/core/port.c __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, · line 995
Quoted 7 lines
drivers/cxl/core/port.c +4
-0@@ -987,6 +989,10 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,return ERR_PTR (-ENXIO ); } + host_bridge =to_pci_host_bridge (dport_dev); +if (host_bridge->native_cxl_error) + dport->rcrb.aer_cap =cxl_rcrb_to_aer (dport_dev, dport->rcrb.base); +Minor comment...
Quoted 3 lines
Is there a need to gate the discovery of the registers on the ACPI setting? For example
cxl_pciunconditionally enumerates the RAS component register block but gates *using* them by ->native_cxl_error.
This is to prevent RCH AER and RAS accesses in CXL device driver if CXL error handling was not OSC enabled. Would you like this check moved to immediately before the logging?
Regards,
Terry