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>
25 #define AER_AGENT_RECEIVER 0
26 #define AER_AGENT_REQUESTER 1
27 #define AER_AGENT_COMPLETER 2
28 #define AER_AGENT_TRANSMITTER 3
30 #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
31 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
32 #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
33 0 : PCI_ERR_UNC_COMP_ABORT)
34 #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
35 (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
37 #define AER_GET_AGENT(t, e) \
38 ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
39 (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
40 (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
43 #define AER_PHYSICAL_LAYER_ERROR 0
44 #define AER_DATA_LINK_LAYER_ERROR 1
45 #define AER_TRANSACTION_LAYER_ERROR 2
47 #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
49 #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
50 (PCI_ERR_COR_BAD_TLP| \
51 PCI_ERR_COR_BAD_DLLP| \
52 PCI_ERR_COR_REP_ROLL| \
53 PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
55 #define AER_GET_LAYER_ERROR(t, e) \
56 ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
57 (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
58 AER_TRANSACTION_LAYER_ERROR)
60 #define AER_PR(info, fmt, args...) \
61 printk("%s" fmt, (info->severity == AER_CORRECTABLE) ? \
62 KERN_WARNING : KERN_ERR, ## args)
67 static char *aer_error_severity_string[] = {
68 "Uncorrected (Non-Fatal)",
69 "Uncorrected (Fatal)",
73 static char *aer_error_layer[] = {
78 static char *aer_correctable_error_string[] = {
79 "Receiver Error ", /* Bit Position 0 */
85 "Bad TLP ", /* Bit Position 6 */
86 "Bad DLLP ", /* Bit Position 7 */
87 "RELAY_NUM Rollover ", /* Bit Position 8 */
91 "Replay Timer Timeout ", /* Bit Position 12 */
92 "Advisory Non-Fatal ", /* Bit Position 13 */
113 static char *aer_uncorrectable_error_string[] = {
118 "Data Link Protocol ", /* Bit Position 4 */
126 "Poisoned TLP ", /* Bit Position 12 */
127 "Flow Control Protocol ", /* Bit Position 13 */
128 "Completion Timeout ", /* Bit Position 14 */
129 "Completer Abort ", /* Bit Position 15 */
130 "Unexpected Completion ", /* Bit Position 16 */
131 "Receiver Overflow ", /* Bit Position 17 */
132 "Malformed TLP ", /* Bit Position 18 */
133 "ECRC ", /* Bit Position 19 */
134 "Unsupported Request ", /* Bit Position 20 */
148 static char *aer_agent_string[] = {
155 static void aer_print_error_source(struct aer_err_info *info)
160 status = (info->status & ~info->mask);
162 for (i = 0; i < 32; i++) {
163 if (!(status & (1 << i)))
166 if (info->severity == AER_CORRECTABLE)
167 errmsg = aer_correctable_error_string[i];
169 errmsg = aer_uncorrectable_error_string[i];
172 AER_PR(info, "%s\t: %s\n", errmsg,
173 info->first_error == i ? "First" : "");
175 AER_PR(info, "Unknown Error Bit %2d \t: %s\n",
176 i, info->first_error == i ? "First" : "");
180 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
182 int err_layer, agent;
183 int id = ((dev->bus->number << 8) | dev->devfn);
185 AER_PR(info, "+------ PCI-Express Device Error ------+\n");
186 AER_PR(info, "Error Severity\t\t: %s\n",
187 aer_error_severity_string[info->severity]);
189 if (info->status == 0) {
190 AER_PR(info, "PCIE Bus Error type\t: (Unaccessible)\n");
191 AER_PR(info, "Unregistered Agent ID\t: %04x\n", id);
193 err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
194 AER_PR(info, "PCIE Bus Error type\t: %s\n",
195 aer_error_layer[err_layer]);
197 aer_print_error_source(info);
199 agent = AER_GET_AGENT(info->severity, info->status);
200 AER_PR(info, "%s\t\t: %04x\n", aer_agent_string[agent], id);
202 AER_PR(info, "VendorID=%04xh, DeviceID=%04xh,"
203 " Bus=%02xh, Device=%02xh, Function=%02xh\n",
207 PCI_SLOT(dev->devfn),
208 PCI_FUNC(dev->devfn));
210 if (info->tlp_header_valid) {
211 unsigned char *tlp = (unsigned char *) &info->tlp;
212 AER_PR(info, "TLP Header:\n");
213 AER_PR(info, "%02x%02x%02x%02x %02x%02x%02x%02x"
214 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
215 *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
216 *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
217 *(tlp + 11), *(tlp + 10), *(tlp + 9),
218 *(tlp + 8), *(tlp + 15), *(tlp + 14),
219 *(tlp + 13), *(tlp + 12));
223 if (info->id && info->error_dev_num > 1 && info->id == id)
224 AER_PR(info, "Error of this Agent(%04x) is reported first\n",