Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / pci / pcie / aer / aerdrv_errprint.c
blob167fe411ce2e30460ba6d0c8a04383976532b4e9
1 /*
2 * drivers/pci/pcie/aer/aerdrv_errprint.c
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
8 * Format error messages and print them to console.
10 * Copyright (C) 2006 Intel Corp.
11 * Tom Long Nguyen (tom.l.nguyen@intel.com)
12 * Zhang Yanmin (yanmin.zhang@intel.com)
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/pm.h>
21 #include <linux/suspend.h>
22 #include <linux/cper.h>
24 #include "aerdrv.h"
25 #include <ras/ras_event.h>
27 #define AER_AGENT_RECEIVER 0
28 #define AER_AGENT_REQUESTER 1
29 #define AER_AGENT_COMPLETER 2
30 #define AER_AGENT_TRANSMITTER 3
32 #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
33 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
34 #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
35 0 : PCI_ERR_UNC_COMP_ABORT)
36 #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
37 (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
39 #define AER_GET_AGENT(t, e) \
40 ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
41 (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
42 (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
43 AER_AGENT_RECEIVER)
45 #define AER_PHYSICAL_LAYER_ERROR 0
46 #define AER_DATA_LINK_LAYER_ERROR 1
47 #define AER_TRANSACTION_LAYER_ERROR 2
49 #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
50 PCI_ERR_COR_RCVR : 0)
51 #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
52 (PCI_ERR_COR_BAD_TLP| \
53 PCI_ERR_COR_BAD_DLLP| \
54 PCI_ERR_COR_REP_ROLL| \
55 PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
57 #define AER_GET_LAYER_ERROR(t, e) \
58 ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
59 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
60 AER_TRANSACTION_LAYER_ERROR)
63 * AER error strings
65 static const char *aer_error_severity_string[] = {
66 "Uncorrected (Non-Fatal)",
67 "Uncorrected (Fatal)",
68 "Corrected"
71 static const char *aer_error_layer[] = {
72 "Physical Layer",
73 "Data Link Layer",
74 "Transaction Layer"
77 static const char *aer_correctable_error_string[] = {
78 "Receiver Error", /* Bit Position 0 */
79 NULL,
80 NULL,
81 NULL,
82 NULL,
83 NULL,
84 "Bad TLP", /* Bit Position 6 */
85 "Bad DLLP", /* Bit Position 7 */
86 "RELAY_NUM Rollover", /* Bit Position 8 */
87 NULL,
88 NULL,
89 NULL,
90 "Replay Timer Timeout", /* Bit Position 12 */
91 "Advisory Non-Fatal", /* Bit Position 13 */
92 "Corrected Internal Error", /* Bit Position 14 */
93 "Header Log Overflow", /* Bit Position 15 */
96 static const char *aer_uncorrectable_error_string[] = {
97 "Undefined", /* Bit Position 0 */
98 NULL,
99 NULL,
100 NULL,
101 "Data Link Protocol", /* Bit Position 4 */
102 "Surprise Down Error", /* Bit Position 5 */
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 NULL,
108 NULL,
109 "Poisoned TLP", /* Bit Position 12 */
110 "Flow Control Protocol", /* Bit Position 13 */
111 "Completion Timeout", /* Bit Position 14 */
112 "Completer Abort", /* Bit Position 15 */
113 "Unexpected Completion", /* Bit Position 16 */
114 "Receiver Overflow", /* Bit Position 17 */
115 "Malformed TLP", /* Bit Position 18 */
116 "ECRC", /* Bit Position 19 */
117 "Unsupported Request", /* Bit Position 20 */
118 "ACS Violation", /* Bit Position 21 */
119 "Uncorrectable Internal Error", /* Bit Position 22 */
120 "MC Blocked TLP", /* Bit Position 23 */
121 "AtomicOp Egress Blocked", /* Bit Position 24 */
122 "TLP Prefix Blocked Error", /* Bit Position 25 */
125 static const char *aer_agent_string[] = {
126 "Receiver ID",
127 "Requester ID",
128 "Completer ID",
129 "Transmitter ID"
132 static void __print_tlp_header(struct pci_dev *dev,
133 struct aer_header_log_regs *t)
135 dev_err(&dev->dev, " TLP Header: %08x %08x %08x %08x\n",
136 t->dw0, t->dw1, t->dw2, t->dw3);
139 static void __aer_print_error(struct pci_dev *dev,
140 struct aer_err_info *info)
142 int i, status;
143 const char *errmsg = NULL;
144 status = (info->status & ~info->mask);
146 for (i = 0; i < 32; i++) {
147 if (!(status & (1 << i)))
148 continue;
150 if (info->severity == AER_CORRECTABLE)
151 errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
152 aer_correctable_error_string[i] : NULL;
153 else
154 errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
155 aer_uncorrectable_error_string[i] : NULL;
157 if (errmsg)
158 dev_err(&dev->dev, " [%2d] %-22s%s\n", i, errmsg,
159 info->first_error == i ? " (First)" : "");
160 else
161 dev_err(&dev->dev, " [%2d] Unknown Error Bit%s\n",
162 i, info->first_error == i ? " (First)" : "");
166 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
168 int layer, agent;
169 int id = ((dev->bus->number << 8) | dev->devfn);
171 if (!info->status) {
172 dev_err(&dev->dev, "PCIe Bus Error: severity=%s, type=Unaccessible, id=%04x(Unregistered Agent ID)\n",
173 aer_error_severity_string[info->severity], id);
174 goto out;
177 layer = AER_GET_LAYER_ERROR(info->severity, info->status);
178 agent = AER_GET_AGENT(info->severity, info->status);
180 dev_err(&dev->dev, "PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
181 aer_error_severity_string[info->severity],
182 aer_error_layer[layer], id, aer_agent_string[agent]);
184 dev_err(&dev->dev, " device [%04x:%04x] error status/mask=%08x/%08x\n",
185 dev->vendor, dev->device,
186 info->status, info->mask);
188 __aer_print_error(dev, info);
190 if (info->tlp_header_valid)
191 __print_tlp_header(dev, &info->tlp);
193 out:
194 if (info->id && info->error_dev_num > 1 && info->id == id)
195 dev_err(&dev->dev, " Error of this Agent(%04x) is reported first\n", id);
197 trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask),
198 info->severity);
201 void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
203 dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
204 info->multi_error_valid ? "Multiple " : "",
205 aer_error_severity_string[info->severity], info->id);
208 #ifdef CONFIG_ACPI_APEI_PCIEAER
209 int cper_severity_to_aer(int cper_severity)
211 switch (cper_severity) {
212 case CPER_SEV_RECOVERABLE:
213 return AER_NONFATAL;
214 case CPER_SEV_FATAL:
215 return AER_FATAL;
216 default:
217 return AER_CORRECTABLE;
220 EXPORT_SYMBOL_GPL(cper_severity_to_aer);
222 void cper_print_aer(struct pci_dev *dev, int cper_severity,
223 struct aer_capability_regs *aer)
225 int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0;
226 u32 status, mask;
227 const char **status_strs;
229 aer_severity = cper_severity_to_aer(cper_severity);
231 if (aer_severity == AER_CORRECTABLE) {
232 status = aer->cor_status;
233 mask = aer->cor_mask;
234 status_strs = aer_correctable_error_string;
235 status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
236 } else {
237 status = aer->uncor_status;
238 mask = aer->uncor_mask;
239 status_strs = aer_uncorrectable_error_string;
240 status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
241 tlp_header_valid = status & AER_LOG_TLP_MASKS;
244 layer = AER_GET_LAYER_ERROR(aer_severity, status);
245 agent = AER_GET_AGENT(aer_severity, status);
247 dev_err(&dev->dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask);
248 cper_print_bits("", status, status_strs, status_strs_size);
249 dev_err(&dev->dev, "aer_layer=%s, aer_agent=%s\n",
250 aer_error_layer[layer], aer_agent_string[agent]);
252 if (aer_severity != AER_CORRECTABLE)
253 dev_err(&dev->dev, "aer_uncor_severity: 0x%08x\n",
254 aer->uncor_severity);
256 if (tlp_header_valid)
257 __print_tlp_header(dev, &aer->header_log);
259 trace_aer_event(dev_name(&dev->dev), (status & ~mask),
260 aer_severity);
262 #endif