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
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>
21 #include <linux/suspend.h>
22 #include <linux/cper.h>
26 #define CREATE_TRACE_POINTS
27 #include <trace/events/ras.h>
29 #define AER_AGENT_RECEIVER 0
30 #define AER_AGENT_REQUESTER 1
31 #define AER_AGENT_COMPLETER 2
32 #define AER_AGENT_TRANSMITTER 3
34 #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
35 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
36 #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
37 0 : PCI_ERR_UNC_COMP_ABORT)
38 #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
39 (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
41 #define AER_GET_AGENT(t, e) \
42 ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
43 (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
44 (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
47 #define AER_PHYSICAL_LAYER_ERROR 0
48 #define AER_DATA_LINK_LAYER_ERROR 1
49 #define AER_TRANSACTION_LAYER_ERROR 2
51 #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
53 #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
54 (PCI_ERR_COR_BAD_TLP| \
55 PCI_ERR_COR_BAD_DLLP| \
56 PCI_ERR_COR_REP_ROLL| \
57 PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
59 #define AER_GET_LAYER_ERROR(t, e) \
60 ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
61 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
62 AER_TRANSACTION_LAYER_ERROR)
67 static const char *aer_error_severity_string
[] = {
68 "Uncorrected (Non-Fatal)",
69 "Uncorrected (Fatal)",
73 static const char *aer_error_layer
[] = {
79 static const char *aer_correctable_error_string
[] = {
80 "Receiver Error", /* Bit Position 0 */
86 "Bad TLP", /* Bit Position 6 */
87 "Bad DLLP", /* Bit Position 7 */
88 "RELAY_NUM Rollover", /* Bit Position 8 */
92 "Replay Timer Timeout", /* Bit Position 12 */
93 "Advisory Non-Fatal", /* Bit Position 13 */
96 static const char *aer_uncorrectable_error_string
[] = {
101 "Data Link Protocol", /* Bit Position 4 */
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 */
120 static const char *aer_agent_string
[] = {
127 static void __print_tlp_header(struct pci_dev
*dev
,
128 struct aer_header_log_regs
*t
)
130 unsigned char *tlp
= (unsigned char *)&t
;
132 dev_err(&dev
->dev
, " TLP Header:"
133 " %02x%02x%02x%02x %02x%02x%02x%02x"
134 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
135 *(tlp
+ 3), *(tlp
+ 2), *(tlp
+ 1), *tlp
,
136 *(tlp
+ 7), *(tlp
+ 6), *(tlp
+ 5), *(tlp
+ 4),
137 *(tlp
+ 11), *(tlp
+ 10), *(tlp
+ 9),
138 *(tlp
+ 8), *(tlp
+ 15), *(tlp
+ 14),
139 *(tlp
+ 13), *(tlp
+ 12));
142 static void __aer_print_error(struct pci_dev
*dev
,
143 struct aer_err_info
*info
)
146 const char *errmsg
= NULL
;
147 status
= (info
->status
& ~info
->mask
);
149 for (i
= 0; i
< 32; i
++) {
150 if (!(status
& (1 << i
)))
153 if (info
->severity
== AER_CORRECTABLE
)
154 errmsg
= i
< ARRAY_SIZE(aer_correctable_error_string
) ?
155 aer_correctable_error_string
[i
] : NULL
;
157 errmsg
= i
< ARRAY_SIZE(aer_uncorrectable_error_string
) ?
158 aer_uncorrectable_error_string
[i
] : NULL
;
161 dev_err(&dev
->dev
, " [%2d] %-22s%s\n", i
, errmsg
,
162 info
->first_error
== i
? " (First)" : "");
164 dev_err(&dev
->dev
, " [%2d] Unknown Error Bit%s\n",
165 i
, info
->first_error
== i
? " (First)" : "");
169 void aer_print_error(struct pci_dev
*dev
, struct aer_err_info
*info
)
172 int id
= ((dev
->bus
->number
<< 8) | dev
->devfn
);
176 "PCIe Bus Error: severity=%s, type=Unaccessible, "
177 "id=%04x(Unregistered Agent ID)\n",
178 aer_error_severity_string
[info
->severity
], id
);
182 layer
= AER_GET_LAYER_ERROR(info
->severity
, info
->status
);
183 agent
= AER_GET_AGENT(info
->severity
, info
->status
);
186 "PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
187 aer_error_severity_string
[info
->severity
],
188 aer_error_layer
[layer
], id
, aer_agent_string
[agent
]);
191 " device [%04x:%04x] error status/mask=%08x/%08x\n",
192 dev
->vendor
, dev
->device
,
193 info
->status
, info
->mask
);
195 __aer_print_error(dev
, info
);
197 if (info
->tlp_header_valid
)
198 __print_tlp_header(dev
, &info
->tlp
);
201 if (info
->id
&& info
->error_dev_num
> 1 && info
->id
== id
)
202 dev_err(&dev
->dev
, " Error of this Agent(%04x) is reported first\n", id
);
204 trace_aer_event(dev_name(&dev
->dev
), (info
->status
& ~info
->mask
),
208 void aer_print_port_info(struct pci_dev
*dev
, struct aer_err_info
*info
)
210 dev_info(&dev
->dev
, "AER: %s%s error received: id=%04x\n",
211 info
->multi_error_valid
? "Multiple " : "",
212 aer_error_severity_string
[info
->severity
], info
->id
);
215 #ifdef CONFIG_ACPI_APEI_PCIEAER
216 int cper_severity_to_aer(int cper_severity
)
218 switch (cper_severity
) {
219 case CPER_SEV_RECOVERABLE
:
224 return AER_CORRECTABLE
;
227 EXPORT_SYMBOL_GPL(cper_severity_to_aer
);
229 void cper_print_aer(struct pci_dev
*dev
, int cper_severity
,
230 struct aer_capability_regs
*aer
)
232 int aer_severity
, layer
, agent
, status_strs_size
, tlp_header_valid
= 0;
234 const char **status_strs
;
236 aer_severity
= cper_severity_to_aer(cper_severity
);
238 if (aer_severity
== AER_CORRECTABLE
) {
239 status
= aer
->cor_status
;
240 mask
= aer
->cor_mask
;
241 status_strs
= aer_correctable_error_string
;
242 status_strs_size
= ARRAY_SIZE(aer_correctable_error_string
);
244 status
= aer
->uncor_status
;
245 mask
= aer
->uncor_mask
;
246 status_strs
= aer_uncorrectable_error_string
;
247 status_strs_size
= ARRAY_SIZE(aer_uncorrectable_error_string
);
248 tlp_header_valid
= status
& AER_LOG_TLP_MASKS
;
251 layer
= AER_GET_LAYER_ERROR(aer_severity
, status
);
252 agent
= AER_GET_AGENT(aer_severity
, status
);
254 dev_err(&dev
->dev
, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status
, mask
);
255 cper_print_bits("", status
, status_strs
, status_strs_size
);
256 dev_err(&dev
->dev
, "aer_layer=%s, aer_agent=%s\n",
257 aer_error_layer
[layer
], aer_agent_string
[agent
]);
259 if (aer_severity
!= AER_CORRECTABLE
)
260 dev_err(&dev
->dev
, "aer_uncor_severity: 0x%08x\n",
261 aer
->uncor_severity
);
263 if (tlp_header_valid
)
264 __print_tlp_header(dev
, &aer
->header_log
);
266 trace_aer_event(dev_name(&dev
->dev
), (status
& ~mask
),