Skip to content

Commit dab7162

Browse files
djbwdavejiang
authored andcommitted
cxl/port: Move endpoint component register management to cxl_port
In preparation for generic protocol error handling across CXL endpoints, whether they be memory expander class devices or accelerators, drop the endpoint component management from cxl_dev_state. Organize all CXL port component management through the common cxl_port driver. Note that the end game is that drivers/cxl/core/ras.c loses all dependencies on a 'struct cxl_dev_state' parameter and operates only on port resources. The removal of component register mapping from cxl_pci is an incremental step towards that. Reviewed-by: Terry Bowman <terry.bowman@amd.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Tested-by: Terry Bowman <terry.bowman@amd.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> Link: https://patch.msgid.link/20260131000403.2135324-9-dan.j.williams@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent ef1df6c commit dab7162

4 files changed

Lines changed: 60 additions & 67 deletions

File tree

drivers/cxl/core/ras.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ bool cxl_handle_ras(struct device *dev, void __iomem *ras_base)
255255
void cxl_cor_error_detected(struct pci_dev *pdev)
256256
{
257257
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
258+
struct cxl_memdev *cxlmd = cxlds->cxlmd;
258259
struct device *dev = &cxlds->cxlmd->dev;
259260

260261
scoped_guard(device, dev) {
@@ -268,7 +269,7 @@ void cxl_cor_error_detected(struct pci_dev *pdev)
268269
if (cxlds->rcd)
269270
cxl_handle_rdport_errors(cxlds);
270271

271-
cxl_handle_cor_ras(&cxlds->cxlmd->dev, cxlds->regs.ras);
272+
cxl_handle_cor_ras(&cxlds->cxlmd->dev, cxlmd->endpoint->regs.ras);
272273
}
273274
}
274275
EXPORT_SYMBOL_NS_GPL(cxl_cor_error_detected, "CXL");
@@ -297,10 +298,9 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
297298
* chance the situation is recoverable dump the status of the RAS
298299
* capability registers and bounce the active state of the memdev.
299300
*/
300-
ue = cxl_handle_ras(&cxlds->cxlmd->dev, cxlds->regs.ras);
301+
ue = cxl_handle_ras(&cxlds->cxlmd->dev, cxlmd->endpoint->regs.ras);
301302
}
302303

303-
304304
switch (state) {
305305
case pci_channel_io_normal:
306306
if (ue) {

drivers/cxl/cxlmem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ struct cxl_dpa_partition {
415415
* @dev: The device associated with this CXL state
416416
* @cxlmd: The device representing the CXL.mem capabilities of @dev
417417
* @reg_map: component and ras register mapping parameters
418-
* @regs: Parsed register blocks
418+
* @regs: Class device "Device" registers
419419
* @cxl_dvsec: Offset to the PCIe device DVSEC
420420
* @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
421421
* @media_ready: Indicate whether the device media is usable
@@ -431,7 +431,7 @@ struct cxl_dev_state {
431431
struct device *dev;
432432
struct cxl_memdev *cxlmd;
433433
struct cxl_register_map reg_map;
434-
struct cxl_regs regs;
434+
struct cxl_device_regs regs;
435435
int cxl_dvsec;
436436
bool rcd;
437437
bool media_ready;

drivers/cxl/pci.c

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -535,52 +535,6 @@ static int cxl_pci_setup_regs(struct pci_dev *pdev, enum cxl_regloc_type type,
535535
return cxl_setup_regs(map);
536536
}
537537

538-
static int cxl_pci_ras_unmask(struct pci_dev *pdev)
539-
{
540-
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
541-
void __iomem *addr;
542-
u32 orig_val, val, mask;
543-
u16 cap;
544-
int rc;
545-
546-
if (!cxlds->regs.ras) {
547-
dev_dbg(&pdev->dev, "No RAS registers.\n");
548-
return 0;
549-
}
550-
551-
/* BIOS has PCIe AER error control */
552-
if (!pcie_aer_is_native(pdev))
553-
return 0;
554-
555-
rc = pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap);
556-
if (rc)
557-
return rc;
558-
559-
if (cap & PCI_EXP_DEVCTL_URRE) {
560-
addr = cxlds->regs.ras + CXL_RAS_UNCORRECTABLE_MASK_OFFSET;
561-
orig_val = readl(addr);
562-
563-
mask = CXL_RAS_UNCORRECTABLE_MASK_MASK |
564-
CXL_RAS_UNCORRECTABLE_MASK_F256B_MASK;
565-
val = orig_val & ~mask;
566-
writel(val, addr);
567-
dev_dbg(&pdev->dev,
568-
"Uncorrectable RAS Errors Mask: %#x -> %#x\n",
569-
orig_val, val);
570-
}
571-
572-
if (cap & PCI_EXP_DEVCTL_CERE) {
573-
addr = cxlds->regs.ras + CXL_RAS_CORRECTABLE_MASK_OFFSET;
574-
orig_val = readl(addr);
575-
val = orig_val & ~CXL_RAS_CORRECTABLE_MASK_MASK;
576-
writel(val, addr);
577-
dev_dbg(&pdev->dev, "Correctable RAS Errors Mask: %#x -> %#x\n",
578-
orig_val, val);
579-
}
580-
581-
return 0;
582-
}
583-
584538
static void free_event_buf(void *buf)
585539
{
586540
kvfree(buf);
@@ -912,13 +866,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
912866
unsigned int i;
913867
bool irq_avail;
914868

915-
/*
916-
* Double check the anonymous union trickery in struct cxl_regs
917-
* FIXME switch to struct_group()
918-
*/
919-
BUILD_BUG_ON(offsetof(struct cxl_regs, memdev) !=
920-
offsetof(struct cxl_regs, device_regs.memdev));
921-
922869
rc = pcim_enable_device(pdev);
923870
if (rc)
924871
return rc;
@@ -942,7 +889,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
942889
if (rc)
943890
return rc;
944891

945-
rc = cxl_map_device_regs(&map, &cxlds->regs.device_regs);
892+
rc = cxl_map_device_regs(&map, &cxlds->regs);
946893
if (rc)
947894
return rc;
948895

@@ -957,11 +904,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
957904
else if (!cxlds->reg_map.component_map.ras.valid)
958905
dev_dbg(&pdev->dev, "RAS registers not found\n");
959906

960-
rc = cxl_map_component_regs(&cxlds->reg_map, &cxlds->regs.component,
961-
BIT(CXL_CM_CAP_CAP_ID_RAS));
962-
if (rc)
963-
dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");
964-
965907
rc = cxl_pci_type3_init_mailbox(cxlds);
966908
if (rc)
967909
return rc;
@@ -1052,9 +994,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1052994
if (rc)
1053995
return rc;
1054996

1055-
if (cxl_pci_ras_unmask(pdev))
1056-
dev_dbg(&pdev->dev, "No RAS reporting unmasked\n");
1057-
1058997
pci_save_state(pdev);
1059998

1060999
return rc;

drivers/cxl/port.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/* Copyright(c) 2022 Intel Corporation. All rights reserved. */
3+
#include <linux/aer.h>
34
#include <linux/device.h>
45
#include <linux/module.h>
56
#include <linux/slab.h>
@@ -68,6 +69,55 @@ static int cxl_switch_port_probe(struct cxl_port *port)
6869
return 0;
6970
}
7071

72+
static int cxl_ras_unmask(struct cxl_port *port)
73+
{
74+
struct pci_dev *pdev;
75+
void __iomem *addr;
76+
u32 orig_val, val, mask;
77+
u16 cap;
78+
int rc;
79+
80+
if (!dev_is_pci(port->uport_dev))
81+
return 0;
82+
pdev = to_pci_dev(port->uport_dev);
83+
84+
if (!port->regs.ras) {
85+
pci_dbg(pdev, "No RAS registers.\n");
86+
return 0;
87+
}
88+
89+
/* BIOS has PCIe AER error control */
90+
if (!pcie_aer_is_native(pdev))
91+
return 0;
92+
93+
rc = pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap);
94+
if (rc)
95+
return rc;
96+
97+
if (cap & PCI_EXP_DEVCTL_URRE) {
98+
addr = port->regs.ras + CXL_RAS_UNCORRECTABLE_MASK_OFFSET;
99+
orig_val = readl(addr);
100+
101+
mask = CXL_RAS_UNCORRECTABLE_MASK_MASK |
102+
CXL_RAS_UNCORRECTABLE_MASK_F256B_MASK;
103+
val = orig_val & ~mask;
104+
writel(val, addr);
105+
pci_dbg(pdev, "Uncorrectable RAS Errors Mask: %#x -> %#x\n",
106+
orig_val, val);
107+
}
108+
109+
if (cap & PCI_EXP_DEVCTL_CERE) {
110+
addr = port->regs.ras + CXL_RAS_CORRECTABLE_MASK_OFFSET;
111+
orig_val = readl(addr);
112+
val = orig_val & ~CXL_RAS_CORRECTABLE_MASK_MASK;
113+
writel(val, addr);
114+
pci_dbg(pdev, "Correctable RAS Errors Mask: %#x -> %#x\n",
115+
orig_val, val);
116+
}
117+
118+
return 0;
119+
}
120+
71121
static int cxl_endpoint_port_probe(struct cxl_port *port)
72122
{
73123
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
@@ -98,6 +148,10 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
98148
if (dport->rch)
99149
devm_cxl_dport_rch_ras_setup(dport);
100150

151+
devm_cxl_port_ras_setup(port);
152+
if (cxl_ras_unmask(port))
153+
dev_dbg(&port->dev, "failed to unmask RAS interrupts\n");
154+
101155
/*
102156
* Now that all endpoint decoders are successfully enumerated, try to
103157
* assemble regions from committed decoders

0 commit comments

Comments
 (0)