perf buildid: Fix possible unterminated readlink() result buffer
[linux-2.6/linux-mips.git] / drivers / pci / pcie / aer / aerdrv_errprint.c
blob3ea51736f18db45be7c40280626eb0d803c157b1
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"
26 #define AER_AGENT_RECEIVER 0
27 #define AER_AGENT_REQUESTER 1
28 #define AER_AGENT_COMPLETER 2
29 #define AER_AGENT_TRANSMITTER 3
31 #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
32 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
33 #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
34 0 : PCI_ERR_UNC_COMP_ABORT)
35 #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
36 (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
38 #define AER_GET_AGENT(t, e) \
39 ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
40 (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
41 (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
42 AER_AGENT_RECEIVER)
44 #define AER_PHYSICAL_LAYER_ERROR 0
45 #define AER_DATA_LINK_LAYER_ERROR 1
46 #define AER_TRANSACTION_LAYER_ERROR 2
48 #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
49 PCI_ERR_COR_RCVR : 0)
50 #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
51 (PCI_ERR_COR_BAD_TLP| \
52 PCI_ERR_COR_BAD_DLLP| \
53 PCI_ERR_COR_REP_ROLL| \
54 PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
56 #define AER_GET_LAYER_ERROR(t, e) \
57 ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
58 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
59 AER_TRANSACTION_LAYER_ERROR)
62 * AER error strings
64 static const char *aer_error_severity_string[] = {
65 "Uncorrected (Non-Fatal)",
66 "Uncorrected (Fatal)",
67 "Corrected"
70 static const char *aer_error_layer[] = {
71 "Physical Layer",
72 "Data Link Layer",
73 "Transaction Layer"
76 static const char *aer_correctable_error_string[] = {
77 "Receiver Error", /* Bit Position 0 */
78 NULL,
79 NULL,
80 NULL,
81 NULL,
82 NULL,
83 "Bad TLP", /* Bit Position 6 */
84 "Bad DLLP", /* Bit Position 7 */
85 "RELAY_NUM Rollover", /* Bit Position 8 */
86 NULL,
87 NULL,
88 NULL,
89 "Replay Timer Timeout", /* Bit Position 12 */
90 "Advisory Non-Fatal", /* Bit Position 13 */
93 static const char *aer_uncorrectable_error_string[] = {
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 "Data Link Protocol", /* Bit Position 4 */
99 NULL,
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 */
117 static const char *aer_agent_string[] = {
118 "Receiver ID",
119 "Requester ID",
120 "Completer ID",
121 "Transmitter ID"
124 static void __aer_print_error(const char *prefix,
125 struct aer_err_info *info)
127 int i, status;
128 const char *errmsg = NULL;
130 status = (info->status & ~info->mask);
132 for (i = 0; i < 32; i++) {
133 if (!(status & (1 << i)))
134 continue;
136 if (info->severity == AER_CORRECTABLE)
137 errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
138 aer_correctable_error_string[i] : NULL;
139 else
140 errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
141 aer_uncorrectable_error_string[i] : NULL;
143 if (errmsg)
144 printk("%s"" [%2d] %-22s%s\n", prefix, i, errmsg,
145 info->first_error == i ? " (First)" : "");
146 else
147 printk("%s"" [%2d] Unknown Error Bit%s\n", prefix, i,
148 info->first_error == i ? " (First)" : "");
152 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
154 int id = ((dev->bus->number << 8) | dev->devfn);
155 char prefix[44];
157 snprintf(prefix, sizeof(prefix), "%s%s %s: ",
158 (info->severity == AER_CORRECTABLE) ? KERN_WARNING : KERN_ERR,
159 dev_driver_string(&dev->dev), dev_name(&dev->dev));
161 if (info->status == 0) {
162 printk("%s""PCIe Bus Error: severity=%s, type=Unaccessible, "
163 "id=%04x(Unregistered Agent ID)\n", prefix,
164 aer_error_severity_string[info->severity], id);
165 } else {
166 int layer, agent;
168 layer = AER_GET_LAYER_ERROR(info->severity, info->status);
169 agent = AER_GET_AGENT(info->severity, info->status);
171 printk("%s""PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
172 prefix, aer_error_severity_string[info->severity],
173 aer_error_layer[layer], id, aer_agent_string[agent]);
175 printk("%s"" device [%04x:%04x] error status/mask=%08x/%08x\n",
176 prefix, dev->vendor, dev->device,
177 info->status, info->mask);
179 __aer_print_error(prefix, info);
181 if (info->tlp_header_valid) {
182 unsigned char *tlp = (unsigned char *) &info->tlp;
183 printk("%s"" TLP Header:"
184 " %02x%02x%02x%02x %02x%02x%02x%02x"
185 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
186 prefix, *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
187 *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
188 *(tlp + 11), *(tlp + 10), *(tlp + 9),
189 *(tlp + 8), *(tlp + 15), *(tlp + 14),
190 *(tlp + 13), *(tlp + 12));
194 if (info->id && info->error_dev_num > 1 && info->id == id)
195 printk("%s"" Error of this Agent(%04x) is reported first\n",
196 prefix, id);
199 void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
201 dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
202 info->multi_error_valid ? "Multiple " : "",
203 aer_error_severity_string[info->severity], info->id);
206 #ifdef CONFIG_ACPI_APEI_PCIEAER
207 int cper_severity_to_aer(int cper_severity)
209 switch (cper_severity) {
210 case CPER_SEV_RECOVERABLE:
211 return AER_NONFATAL;
212 case CPER_SEV_FATAL:
213 return AER_FATAL;
214 default:
215 return AER_CORRECTABLE;
218 EXPORT_SYMBOL_GPL(cper_severity_to_aer);
220 void cper_print_aer(const char *prefix, int cper_severity,
221 struct aer_capability_regs *aer)
223 int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0;
224 u32 status, mask;
225 const char **status_strs;
227 aer_severity = cper_severity_to_aer(cper_severity);
228 if (aer_severity == AER_CORRECTABLE) {
229 status = aer->cor_status;
230 mask = aer->cor_mask;
231 status_strs = aer_correctable_error_string;
232 status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
233 } else {
234 status = aer->uncor_status;
235 mask = aer->uncor_mask;
236 status_strs = aer_uncorrectable_error_string;
237 status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
238 tlp_header_valid = status & AER_LOG_TLP_MASKS;
240 layer = AER_GET_LAYER_ERROR(aer_severity, status);
241 agent = AER_GET_AGENT(aer_severity, status);
242 printk("%s""aer_status: 0x%08x, aer_mask: 0x%08x\n",
243 prefix, status, mask);
244 cper_print_bits(prefix, status, status_strs, status_strs_size);
245 printk("%s""aer_layer=%s, aer_agent=%s\n", prefix,
246 aer_error_layer[layer], aer_agent_string[agent]);
247 if (aer_severity != AER_CORRECTABLE)
248 printk("%s""aer_uncor_severity: 0x%08x\n",
249 prefix, aer->uncor_severity);
250 if (tlp_header_valid) {
251 const unsigned char *tlp;
252 tlp = (const unsigned char *)&aer->header_log;
253 printk("%s""aer_tlp_header:"
254 " %02x%02x%02x%02x %02x%02x%02x%02x"
255 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
256 prefix, *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
257 *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
258 *(tlp + 11), *(tlp + 10), *(tlp + 9),
259 *(tlp + 8), *(tlp + 15), *(tlp + 14),
260 *(tlp + 13), *(tlp + 12));
263 #endif