xref: /rk3399_rockchip-uboot/drivers/pci/aer.c (revision efa01fe41d99153b5cc02750b3a2fa7bf6693120)
1 /*
2  * PCI AER infomation display library
3  *
4  * Author: Shawn Lin <shawn.lin@rock-chips.com>
5  *
6  * Copyright 2025 Rockchip Co., Ltd.
7  *
8  * SPDX-License-Identifier:	GPL-2.0+
9  */
10 
11 #include <common.h>
12 #include <pci.h>
13 #include <errno.h>
14 
15 /**
16  * pci_aer_dump - Parse and print AER information in a human-readable format
17  * @dev: PCI device
18  *
19  * Return: 0 on success, negative error code on failure.
20  */
21 int pci_aer_dump(struct udevice *udev, pci_dev_t dev)
22 {
23 	int aer_cap_ptr;
24 	u32 aer_status, aer_mask, aer_severity;
25 	u32 aer_capabilities;
26 
27 	/* Find the AER Capability */
28 	aer_cap_ptr = dm_pci_find_ext_capability(udev, PCI_EXT_CAP_ID_ERR);
29 	if (!aer_cap_ptr) {
30 		printf("AER Capability not found for device %04x:%04x\n",
31 			   PCI_BUS(dev), PCI_DEV(dev));
32 		return -ENODEV;
33 	}
34 
35 	/* Read AER-related registers */
36 	dm_pci_read_config32(udev, aer_cap_ptr + PCI_AER_STATUS, &aer_status);
37 	dm_pci_read_config32(udev, aer_cap_ptr + PCI_AER_MASK, &aer_mask);
38 	dm_pci_read_config32(udev, aer_cap_ptr + PCI_AER_SEVERITY, &aer_severity);
39 	dm_pci_read_config32(udev, aer_cap_ptr + 0x18, &aer_capabilities); /* AER Capabilities Register */
40 
41 	/* Print AER Capability information */
42 	printf("AER Capability found at offset 0x%x\n", aer_cap_ptr);
43 
44 	/* Print Uncorrectable Error Status (UES) */
45 	printf("  UESta:  ");
46 	printf("DLP-%c ",  (aer_status & (1 << 0))  ? '+' : '-');
47 	printf("SDES-%c ", (aer_status & (1 << 1))  ? '+' : '-');
48 	printf("TLP-%c ",  (aer_status & (1 << 2))  ? '+' : '-');
49 	printf("FCP-%c ",  (aer_status & (1 << 3))  ? '+' : '-');
50 	printf("CmpltTO-%c ", (aer_status & (1 << 4))  ? '+' : '-');
51 	printf("CmpltAbrt-%c ", (aer_status & (1 << 5))  ? '+' : '-');
52 	printf("UnxCmplt-%c ", (aer_status & (1 << 6))  ? '+' : '-');
53 	printf("RxOF-%c ", (aer_status & (1 << 7))  ? '+' : '-');
54 	printf("MalfTLP-%c ", (aer_status & (1 << 8))  ? '+' : '-');
55 	printf("ECRC-%c ", (aer_status & (1 << 9))  ? '+' : '-');
56 	printf("UnsupReq-%c ", (aer_status & (1 << 10)) ? '+' : '-');
57 	printf("ACSViol-%c\n", (aer_status & (1 << 11)) ? '+' : '-');
58 
59 	/* Print Uncorrectable Error Mask (UEMsk) */
60 	printf("  UEMsk:  ");
61 	printf("DLP-%c ",  (aer_mask & (1 << 0))  ? '+' : '-');
62 	printf("SDES-%c ", (aer_mask & (1 << 1))  ? '+' : '-');
63 	printf("TLP-%c ",  (aer_mask & (1 << 2))  ? '+' : '-');
64 	printf("FCP-%c ",  (aer_mask & (1 << 3))  ? '+' : '-');
65 	printf("CmpltTO-%c ", (aer_mask & (1 << 4))  ? '+' : '-');
66 	printf("CmpltAbrt-%c ", (aer_mask & (1 << 5))  ? '+' : '-');
67 	printf("UnxCmplt-%c ", (aer_mask & (1 << 6))  ? '+' : '-');
68 	printf("RxOF-%c ", (aer_mask & (1 << 7))  ? '+' : '-');
69 	printf("MalfTLP-%c ", (aer_mask & (1 << 8))  ? '+' : '-');
70 	printf("ECRC-%c ", (aer_mask & (1 << 9))  ? '+' : '-');
71 	printf("UnsupReq-%c ", (aer_mask & (1 << 10)) ? '+' : '-');
72 	printf("ACSViol-%c\n", (aer_mask & (1 << 11)) ? '+' : '-');
73 
74 	/* Print Uncorrectable Error Severity (UESvrt) */
75 	printf("  UESvrt: ");
76 	printf("DLP%c ",  (aer_severity & (1 << 0))  ? '+' : '-');
77 	printf("SDES%c ", (aer_severity & (1 << 1))  ? '+' : '-');
78 	printf("TLP%c ",  (aer_severity & (1 << 2))  ? '+' : '-');
79 	printf("FCP%c ",  (aer_severity & (1 << 3))  ? '+' : '-');
80 	printf("CmpltTO%c ", (aer_severity & (1 << 4))  ? '+' : '-');
81 	printf("CmpltAbrt%c ", (aer_severity & (1 << 5))  ? '+' : '-');
82 	printf("UnxCmplt%c ", (aer_severity & (1 << 6))  ? '+' : '-');
83 	printf("RxOF%c ", (aer_severity & (1 << 7))  ? '+' : '-');
84 	printf("MalfTLP%c ", (aer_severity & (1 << 8))  ? '+' : '-');
85 	printf("ECRC%c ", (aer_severity & (1 << 9))  ? '+' : '-');
86 	printf("UnsupReq%c ", (aer_severity & (1 << 10)) ? '+' : '-');
87 	printf("ACSViol%c\n", (aer_severity & (1 << 11)) ? '+' : '-');
88 
89 	/* Print Correctable Error Status (CESta) */
90 	printf("  CESta:  ");
91 	printf("RxErr-%c ",  (aer_status & (1 << 12)) ? '+' : '-');
92 	printf("BadTLP-%c ", (aer_status & (1 << 13)) ? '+' : '-');
93 	printf("BadDLLP-%c ", (aer_status & (1 << 14)) ? '+' : '-');
94 	printf("Rollover-%c ", (aer_status & (1 << 15)) ? '+' : '-');
95 	printf("Timeout-%c ", (aer_status & (1 << 16)) ? '+' : '-');
96 	printf("NonFatalErr-%c\n", (aer_status & (1 << 17)) ? '+' : '-');
97 
98 	/* Print Correctable Error Mask (CEMsk) */
99 	printf("  CEMsk:  ");
100 	printf("RxErr-%c ",  (aer_mask & (1 << 12)) ? '+' : '-');
101 	printf("BadTLP-%c ", (aer_mask & (1 << 13)) ? '+' : '-');
102 	printf("BadDLLP-%c ", (aer_mask & (1 << 14)) ? '+' : '-');
103 	printf("Rollover-%c ", (aer_mask & (1 << 15)) ? '+' : '-');
104 	printf("Timeout-%c ", (aer_mask & (1 << 16)) ? '+' : '-');
105 	printf("NonFatalErr-%c\n", (aer_mask & (1 << 17)) ? '+' : '-');
106 
107 	/* Print AER Capabilities (AERCap) */
108 	printf("  AERCap: ");
109 	printf("First Error Pointer: %02x, ", (aer_capabilities >> 0) & 0x1F);
110 	printf("GenCap%c ", (aer_capabilities & (1 << 5)) ? '+' : '-');
111 	printf("CGenEn%c ", (aer_capabilities & (1 << 6)) ? '+' : '-');
112 	printf("ChkCap%c ", (aer_capabilities & (1 << 7)) ? '+' : '-');
113 	printf("ChkEn%c\n", (aer_capabilities & (1 << 8)) ? '+' : '-');
114 
115 	return 0;
116 }
117