Skip to content

Commit 4a20bc3

Browse files
committed
cxl/pci: Move tracepoint definitions to drivers/cxl/core/
CXL is using tracepoints for reporting RAS capability register payloads for AER events, and has plans to use tracepoints for the output payload of Get Poison List and Get Event Records commands. For organization purposes it would be nice to keep those all under a single + local CXL trace system. This also organization also potentially helps in the future when CXL drivers expand beyond generic memory expanders, however that would also entail a move away from the expander-specific cxl_dev_state context, save that for later. Note that the powerpc-specific drivers/misc/cxl/ also defines a 'cxl' trace system, however, it is unlikely that a single platform will ever load both drivers simultaneously. Cc: Steven Rostedt <[email protected]> Tested-by: Alison Schofield <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/167051869176.436579.9728373544811641087.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 88603b6 commit 4a20bc3

File tree

8 files changed

+131
-118
lines changed

8 files changed

+131
-118
lines changed

drivers/cxl/core/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ obj-$(CONFIG_CXL_BUS) += cxl_core.o
33
obj-$(CONFIG_CXL_SUSPEND) += suspend.o
44

55
ccflags-y += -I$(srctree)/drivers/cxl
6+
CFLAGS_trace.o = -DTRACE_INCLUDE_PATH=. -I$(src)
7+
68
cxl_core-y := port.o
79
cxl_core-y += pmem.o
810
cxl_core-y += regs.o
911
cxl_core-y += memdev.o
1012
cxl_core-y += mbox.o
1113
cxl_core-y += pci.o
1214
cxl_core-y += hdm.o
15+
cxl_core-$(CONFIG_TRACING) += trace.o
1316
cxl_core-$(CONFIG_CXL_REGION) += region.o

drivers/cxl/core/pci.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cxlmem.h>
1010
#include <cxl.h>
1111
#include "core.h"
12+
#include "trace.h"
1213

1314
/**
1415
* DOC: cxl core pci
@@ -622,3 +623,114 @@ void read_cdat_data(struct cxl_port *port)
622623
}
623624
}
624625
EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL);
626+
627+
void cxl_cor_error_detected(struct pci_dev *pdev)
628+
{
629+
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
630+
struct cxl_memdev *cxlmd = cxlds->cxlmd;
631+
struct device *dev = &cxlmd->dev;
632+
void __iomem *addr;
633+
u32 status;
634+
635+
if (!cxlds->regs.ras)
636+
return;
637+
638+
addr = cxlds->regs.ras + CXL_RAS_CORRECTABLE_STATUS_OFFSET;
639+
status = readl(addr);
640+
if (status & CXL_RAS_CORRECTABLE_STATUS_MASK) {
641+
writel(status & CXL_RAS_CORRECTABLE_STATUS_MASK, addr);
642+
trace_cxl_aer_correctable_error(dev, status);
643+
}
644+
}
645+
EXPORT_SYMBOL_NS_GPL(cxl_cor_error_detected, CXL);
646+
647+
/* CXL spec rev3.0 8.2.4.16.1 */
648+
static void header_log_copy(struct cxl_dev_state *cxlds, u32 *log)
649+
{
650+
void __iomem *addr;
651+
u32 *log_addr;
652+
int i, log_u32_size = CXL_HEADERLOG_SIZE / sizeof(u32);
653+
654+
addr = cxlds->regs.ras + CXL_RAS_HEADER_LOG_OFFSET;
655+
log_addr = log;
656+
657+
for (i = 0; i < log_u32_size; i++) {
658+
*log_addr = readl(addr);
659+
log_addr++;
660+
addr += sizeof(u32);
661+
}
662+
}
663+
664+
/*
665+
* Log the state of the RAS status registers and prepare them to log the
666+
* next error status. Return 1 if reset needed.
667+
*/
668+
static bool cxl_report_and_clear(struct cxl_dev_state *cxlds)
669+
{
670+
struct cxl_memdev *cxlmd = cxlds->cxlmd;
671+
struct device *dev = &cxlmd->dev;
672+
u32 hl[CXL_HEADERLOG_SIZE_U32];
673+
void __iomem *addr;
674+
u32 status;
675+
u32 fe;
676+
677+
if (!cxlds->regs.ras)
678+
return false;
679+
680+
addr = cxlds->regs.ras + CXL_RAS_UNCORRECTABLE_STATUS_OFFSET;
681+
status = readl(addr);
682+
if (!(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK))
683+
return false;
684+
685+
/* If multiple errors, log header points to first error from ctrl reg */
686+
if (hweight32(status) > 1) {
687+
addr = cxlds->regs.ras + CXL_RAS_CAP_CONTROL_OFFSET;
688+
fe = BIT(FIELD_GET(CXL_RAS_CAP_CONTROL_FE_MASK, readl(addr)));
689+
} else {
690+
fe = status;
691+
}
692+
693+
header_log_copy(cxlds, hl);
694+
trace_cxl_aer_uncorrectable_error(dev, status, fe, hl);
695+
writel(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK, addr);
696+
697+
return true;
698+
}
699+
700+
pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
701+
pci_channel_state_t state)
702+
{
703+
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
704+
struct cxl_memdev *cxlmd = cxlds->cxlmd;
705+
struct device *dev = &cxlmd->dev;
706+
bool ue;
707+
708+
/*
709+
* A frozen channel indicates an impending reset which is fatal to
710+
* CXL.mem operation, and will likely crash the system. On the off
711+
* chance the situation is recoverable dump the status of the RAS
712+
* capability registers and bounce the active state of the memdev.
713+
*/
714+
ue = cxl_report_and_clear(cxlds);
715+
716+
switch (state) {
717+
case pci_channel_io_normal:
718+
if (ue) {
719+
device_release_driver(dev);
720+
return PCI_ERS_RESULT_NEED_RESET;
721+
}
722+
return PCI_ERS_RESULT_CAN_RECOVER;
723+
case pci_channel_io_frozen:
724+
dev_warn(&pdev->dev,
725+
"%s: frozen state error detected, disable CXL.mem\n",
726+
dev_name(dev));
727+
device_release_driver(dev);
728+
return PCI_ERS_RESULT_NEED_RESET;
729+
case pci_channel_io_perm_failure:
730+
dev_warn(&pdev->dev,
731+
"failure state error detected, request disconnect\n");
732+
return PCI_ERS_RESULT_DISCONNECT;
733+
}
734+
return PCI_ERS_RESULT_NEED_RESET;
735+
}
736+
EXPORT_SYMBOL_NS_GPL(cxl_error_detected, CXL);

drivers/cxl/core/trace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/* Copyright(c) 2022 Intel Corporation. All rights reserved. */
3+
4+
#define CREATE_TRACE_POINTS
5+
#include "trace.h"

include/trace/events/cxl.h renamed to drivers/cxl/core/trace.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
/* SPDX-License-Identifier: GPL-2.0 */
1+
// SPDX-License-Identifier: GPL-2.0
2+
/* Copyright(c) 2022 Intel Corporation. All rights reserved. */
23
#undef TRACE_SYSTEM
34
#define TRACE_SYSTEM cxl
45

56
#if !defined(_CXL_EVENTS_H) || defined(TRACE_HEADER_MULTI_READ)
67
#define _CXL_EVENTS_H
78

9+
#include <cxl.h>
810
#include <linux/tracepoint.h>
911

10-
#define CXL_HEADERLOG_SIZE SZ_512
11-
#define CXL_HEADERLOG_SIZE_U32 SZ_512 / sizeof(u32)
12-
1312
#define CXL_RAS_UC_CACHE_DATA_PARITY BIT(0)
1413
#define CXL_RAS_UC_CACHE_ADDR_PARITY BIT(1)
1514
#define CXL_RAS_UC_CACHE_BE_PARITY BIT(2)
@@ -106,7 +105,5 @@ TRACE_EVENT(cxl_aer_correctable_error,
106105

107106
#endif /* _CXL_EVENTS_H */
108107

109-
/* This part must be outside protection */
110-
#undef TRACE_INCLUDE_FILE
111-
#define TRACE_INCLUDE_FILE cxl
108+
#define TRACE_INCLUDE_FILE trace
112109
#include <trace/define_trace.h>

drivers/cxl/cxl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)
140140
#define CXL_RAS_CAP_CONTROL_FE_MASK GENMASK(5, 0)
141141
#define CXL_RAS_HEADER_LOG_OFFSET 0x18
142142
#define CXL_RAS_CAPABILITY_LENGTH 0x58
143+
#define CXL_HEADERLOG_SIZE SZ_512
144+
#define CXL_HEADERLOG_SIZE_U32 SZ_512 / sizeof(u32)
143145

144146
/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */
145147
#define CXLDEV_CAP_ARRAY_OFFSET 0x0

drivers/cxl/cxlpci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,7 @@ int devm_cxl_port_enumerate_dports(struct cxl_port *port);
6666
struct cxl_dev_state;
6767
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm);
6868
void read_cdat_data(struct cxl_port *port);
69+
void cxl_cor_error_detected(struct pci_dev *pdev);
70+
pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
71+
pci_channel_state_t state);
6972
#endif /* __CXL_PCI_H__ */

drivers/cxl/pci.c

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "cxlmem.h"
1515
#include "cxlpci.h"
1616
#include "cxl.h"
17-
#define CREATE_TRACE_POINTS
18-
#include <trace/events/cxl.h>
1917

2018
/**
2119
* DOC: cxl pci
@@ -514,96 +512,6 @@ static const struct pci_device_id cxl_mem_pci_tbl[] = {
514512
};
515513
MODULE_DEVICE_TABLE(pci, cxl_mem_pci_tbl);
516514

517-
/* CXL spec rev3.0 8.2.4.16.1 */
518-
static void header_log_copy(struct cxl_dev_state *cxlds, u32 *log)
519-
{
520-
void __iomem *addr;
521-
u32 *log_addr;
522-
int i, log_u32_size = CXL_HEADERLOG_SIZE / sizeof(u32);
523-
524-
addr = cxlds->regs.ras + CXL_RAS_HEADER_LOG_OFFSET;
525-
log_addr = log;
526-
527-
for (i = 0; i < log_u32_size; i++) {
528-
*log_addr = readl(addr);
529-
log_addr++;
530-
addr += sizeof(u32);
531-
}
532-
}
533-
534-
/*
535-
* Log the state of the RAS status registers and prepare them to log the
536-
* next error status. Return 1 if reset needed.
537-
*/
538-
static bool cxl_report_and_clear(struct cxl_dev_state *cxlds)
539-
{
540-
struct cxl_memdev *cxlmd = cxlds->cxlmd;
541-
struct device *dev = &cxlmd->dev;
542-
u32 hl[CXL_HEADERLOG_SIZE_U32];
543-
void __iomem *addr;
544-
u32 status;
545-
u32 fe;
546-
547-
if (!cxlds->regs.ras)
548-
return false;
549-
550-
addr = cxlds->regs.ras + CXL_RAS_UNCORRECTABLE_STATUS_OFFSET;
551-
status = readl(addr);
552-
if (!(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK))
553-
return false;
554-
555-
/* If multiple errors, log header points to first error from ctrl reg */
556-
if (hweight32(status) > 1) {
557-
addr = cxlds->regs.ras + CXL_RAS_CAP_CONTROL_OFFSET;
558-
fe = BIT(FIELD_GET(CXL_RAS_CAP_CONTROL_FE_MASK, readl(addr)));
559-
} else {
560-
fe = status;
561-
}
562-
563-
header_log_copy(cxlds, hl);
564-
trace_cxl_aer_uncorrectable_error(dev, status, fe, hl);
565-
writel(status & CXL_RAS_UNCORRECTABLE_STATUS_MASK, addr);
566-
567-
return true;
568-
}
569-
570-
static pci_ers_result_t cxl_error_detected(struct pci_dev *pdev,
571-
pci_channel_state_t state)
572-
{
573-
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
574-
struct cxl_memdev *cxlmd = cxlds->cxlmd;
575-
struct device *dev = &cxlmd->dev;
576-
bool ue;
577-
578-
/*
579-
* A frozen channel indicates an impending reset which is fatal to
580-
* CXL.mem operation, and will likely crash the system. On the off
581-
* chance the situation is recoverable dump the status of the RAS
582-
* capability registers and bounce the active state of the memdev.
583-
*/
584-
ue = cxl_report_and_clear(cxlds);
585-
586-
switch (state) {
587-
case pci_channel_io_normal:
588-
if (ue) {
589-
device_release_driver(dev);
590-
return PCI_ERS_RESULT_NEED_RESET;
591-
}
592-
return PCI_ERS_RESULT_CAN_RECOVER;
593-
case pci_channel_io_frozen:
594-
dev_warn(&pdev->dev,
595-
"%s: frozen state error detected, disable CXL.mem\n",
596-
dev_name(dev));
597-
device_release_driver(dev);
598-
return PCI_ERS_RESULT_NEED_RESET;
599-
case pci_channel_io_perm_failure:
600-
dev_warn(&pdev->dev,
601-
"failure state error detected, request disconnect\n");
602-
return PCI_ERS_RESULT_DISCONNECT;
603-
}
604-
return PCI_ERS_RESULT_NEED_RESET;
605-
}
606-
607515
static pci_ers_result_t cxl_slot_reset(struct pci_dev *pdev)
608516
{
609517
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
@@ -628,25 +536,6 @@ static void cxl_error_resume(struct pci_dev *pdev)
628536
dev->driver ? "successful" : "failed");
629537
}
630538

631-
static void cxl_cor_error_detected(struct pci_dev *pdev)
632-
{
633-
struct cxl_dev_state *cxlds = pci_get_drvdata(pdev);
634-
struct cxl_memdev *cxlmd = cxlds->cxlmd;
635-
struct device *dev = &cxlmd->dev;
636-
void __iomem *addr;
637-
u32 status;
638-
639-
if (!cxlds->regs.ras)
640-
return;
641-
642-
addr = cxlds->regs.ras + CXL_RAS_CORRECTABLE_STATUS_OFFSET;
643-
status = readl(addr);
644-
if (status & CXL_RAS_CORRECTABLE_STATUS_MASK) {
645-
writel(status & CXL_RAS_CORRECTABLE_STATUS_MASK, addr);
646-
trace_cxl_aer_correctable_error(dev, status);
647-
}
648-
}
649-
650539
static const struct pci_error_handlers cxl_error_handlers = {
651540
.error_detected = cxl_error_detected,
652541
.slot_reset = cxl_slot_reset,

tools/testing/cxl/Kbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CXL_SRC := $(DRIVERS)/cxl
1717
CXL_CORE_SRC := $(DRIVERS)/cxl/core
1818
ccflags-y := -I$(srctree)/drivers/cxl/
1919
ccflags-y += -D__mock=__weak
20+
ccflags-y += -DTRACE_INCLUDE_PATH=$(CXL_CORE_SRC) -I$(srctree)/drivers/cxl/core/
2021

2122
obj-m += cxl_acpi.o
2223

@@ -49,6 +50,7 @@ cxl_core-y += $(CXL_CORE_SRC)/memdev.o
4950
cxl_core-y += $(CXL_CORE_SRC)/mbox.o
5051
cxl_core-y += $(CXL_CORE_SRC)/pci.o
5152
cxl_core-y += $(CXL_CORE_SRC)/hdm.o
53+
cxl_core-$(CONFIG_TRACING) += $(CXL_CORE_SRC)/trace.o
5254
cxl_core-$(CONFIG_CXL_REGION) += $(CXL_CORE_SRC)/region.o
5355
cxl_core-y += config_check.o
5456

0 commit comments

Comments
 (0)