x86/topology: Fix function name in documentation
[cris-mirror.git] / drivers / pci / pcie / aer / aerdrv_errprint.c
blob6a352e63869902f1ae038d156eeec37ccf6dfc63
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * drivers/pci/pcie/aer/aerdrv_errprint.c
5 * Format error messages and print them to console.
7 * Copyright (C) 2006 Intel Corp.
8 * Tom Long Nguyen (tom.l.nguyen@intel.com)
9 * Zhang Yanmin (yanmin.zhang@intel.com)
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/pm.h>
18 #include <linux/suspend.h>
19 #include <linux/cper.h>
21 #include "aerdrv.h"
22 #include <ras/ras_event.h>
24 #define AER_AGENT_RECEIVER 0
25 #define AER_AGENT_REQUESTER 1
26 #define AER_AGENT_COMPLETER 2
27 #define AER_AGENT_TRANSMITTER 3
29 #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
30 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
31 #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
32 0 : PCI_ERR_UNC_COMP_ABORT)
33 #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
34 (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
36 #define AER_GET_AGENT(t, e) \
37 ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
38 (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
39 (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
40 AER_AGENT_RECEIVER)
42 #define AER_PHYSICAL_LAYER_ERROR 0
43 #define AER_DATA_LINK_LAYER_ERROR 1
44 #define AER_TRANSACTION_LAYER_ERROR 2
46 #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
47 PCI_ERR_COR_RCVR : 0)
48 #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
49 (PCI_ERR_COR_BAD_TLP| \
50 PCI_ERR_COR_BAD_DLLP| \
51 PCI_ERR_COR_REP_ROLL| \
52 PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
54 #define AER_GET_LAYER_ERROR(t, e) \
55 ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
56 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
57 AER_TRANSACTION_LAYER_ERROR)
60 * AER error strings
62 static const char *aer_error_severity_string[] = {
63 "Uncorrected (Non-Fatal)",
64 "Uncorrected (Fatal)",
65 "Corrected"
68 static const char *aer_error_layer[] = {
69 "Physical Layer",
70 "Data Link Layer",
71 "Transaction Layer"
74 static const char *aer_correctable_error_string[] = {
75 "Receiver Error", /* Bit Position 0 */
76 NULL,
77 NULL,
78 NULL,
79 NULL,
80 NULL,
81 "Bad TLP", /* Bit Position 6 */
82 "Bad DLLP", /* Bit Position 7 */
83 "RELAY_NUM Rollover", /* Bit Position 8 */
84 NULL,
85 NULL,
86 NULL,
87 "Replay Timer Timeout", /* Bit Position 12 */
88 "Advisory Non-Fatal", /* Bit Position 13 */
89 "Corrected Internal Error", /* Bit Position 14 */
90 "Header Log Overflow", /* Bit Position 15 */
93 static const char *aer_uncorrectable_error_string[] = {
94 "Undefined", /* Bit Position 0 */
95 NULL,
96 NULL,
97 NULL,
98 "Data Link Protocol", /* Bit Position 4 */
99 "Surprise Down Error", /* Bit Position 5 */
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL,
106 "Poisoned TLP", /* Bit Position 12 */
107 "Flow Control Protocol", /* Bit Position 13 */
108 "Completion Timeout", /* Bit Position 14 */
109 "Completer Abort", /* Bit Position 15 */
110 "Unexpected Completion", /* Bit Position 16 */
111 "Receiver Overflow", /* Bit Position 17 */
112 "Malformed TLP", /* Bit Position 18 */
113 "ECRC", /* Bit Position 19 */
114 "Unsupported Request", /* Bit Position 20 */
115 "ACS Violation", /* Bit Position 21 */
116 "Uncorrectable Internal Error", /* Bit Position 22 */
117 "MC Blocked TLP", /* Bit Position 23 */
118 "AtomicOp Egress Blocked", /* Bit Position 24 */
119 "TLP Prefix Blocked Error", /* Bit Position 25 */
122 static const char *aer_agent_string[] = {
123 "Receiver ID",
124 "Requester ID",
125 "Completer ID",
126 "Transmitter ID"
129 static void __print_tlp_header(struct pci_dev *dev,
130 struct aer_header_log_regs *t)
132 pci_err(dev, " TLP Header: %08x %08x %08x %08x\n",
133 t->dw0, t->dw1, t->dw2, t->dw3);
136 static void __aer_print_error(struct pci_dev *dev,
137 struct aer_err_info *info)
139 int i, status;
140 const char *errmsg = NULL;
141 status = (info->status & ~info->mask);
143 for (i = 0; i < 32; i++) {
144 if (!(status & (1 << i)))
145 continue;
147 if (info->severity == AER_CORRECTABLE)
148 errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
149 aer_correctable_error_string[i] : NULL;
150 else
151 errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
152 aer_uncorrectable_error_string[i] : NULL;
154 if (errmsg)
155 pci_err(dev, " [%2d] %-22s%s\n", i, errmsg,
156 info->first_error == i ? " (First)" : "");
157 else
158 pci_err(dev, " [%2d] Unknown Error Bit%s\n",
159 i, info->first_error == i ? " (First)" : "");
163 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
165 int layer, agent;
166 int id = ((dev->bus->number << 8) | dev->devfn);
168 if (!info->status) {
169 pci_err(dev, "PCIe Bus Error: severity=%s, type=Unaccessible, id=%04x(Unregistered Agent ID)\n",
170 aer_error_severity_string[info->severity], id);
171 goto out;
174 layer = AER_GET_LAYER_ERROR(info->severity, info->status);
175 agent = AER_GET_AGENT(info->severity, info->status);
177 pci_err(dev, "PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
178 aer_error_severity_string[info->severity],
179 aer_error_layer[layer], id, aer_agent_string[agent]);
181 pci_err(dev, " device [%04x:%04x] error status/mask=%08x/%08x\n",
182 dev->vendor, dev->device,
183 info->status, info->mask);
185 __aer_print_error(dev, info);
187 if (info->tlp_header_valid)
188 __print_tlp_header(dev, &info->tlp);
190 out:
191 if (info->id && info->error_dev_num > 1 && info->id == id)
192 pci_err(dev, " Error of this Agent(%04x) is reported first\n", id);
194 trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask),
195 info->severity);
198 void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
200 pci_info(dev, "AER: %s%s error received: id=%04x\n",
201 info->multi_error_valid ? "Multiple " : "",
202 aer_error_severity_string[info->severity], info->id);
205 #ifdef CONFIG_ACPI_APEI_PCIEAER
206 int cper_severity_to_aer(int cper_severity)
208 switch (cper_severity) {
209 case CPER_SEV_RECOVERABLE:
210 return AER_NONFATAL;
211 case CPER_SEV_FATAL:
212 return AER_FATAL;
213 default:
214 return AER_CORRECTABLE;
217 EXPORT_SYMBOL_GPL(cper_severity_to_aer);
219 void cper_print_aer(struct pci_dev *dev, int aer_severity,
220 struct aer_capability_regs *aer)
222 int layer, agent, status_strs_size, tlp_header_valid = 0;
223 u32 status, mask;
224 const char **status_strs;
226 if (aer_severity == AER_CORRECTABLE) {
227 status = aer->cor_status;
228 mask = aer->cor_mask;
229 status_strs = aer_correctable_error_string;
230 status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
231 } else {
232 status = aer->uncor_status;
233 mask = aer->uncor_mask;
234 status_strs = aer_uncorrectable_error_string;
235 status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
236 tlp_header_valid = status & AER_LOG_TLP_MASKS;
239 layer = AER_GET_LAYER_ERROR(aer_severity, status);
240 agent = AER_GET_AGENT(aer_severity, status);
242 pci_err(dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask);
243 cper_print_bits("", status, status_strs, status_strs_size);
244 pci_err(dev, "aer_layer=%s, aer_agent=%s\n",
245 aer_error_layer[layer], aer_agent_string[agent]);
247 if (aer_severity != AER_CORRECTABLE)
248 pci_err(dev, "aer_uncor_severity: 0x%08x\n",
249 aer->uncor_severity);
251 if (tlp_header_valid)
252 __print_tlp_header(dev, &aer->header_log);
254 trace_aer_event(dev_name(&dev->dev), (status & ~mask),
255 aer_severity);
257 #endif