blob: 0bb91e28d5fee30b91f82c6e015d06a3c262a981 [file] [log] [blame]
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +08001/*
2 * drivers/pci/pcie/aer/aerdrv_errprint.c
3 *
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.
7 *
8 * Format error messages and print them to console.
9 *
10 * Copyright (C) 2006 Intel Corp.
11 * Tom Long Nguyen (tom.l.nguyen@intel.com)
12 * Zhang Yanmin (yanmin.zhang@intel.com)
13 *
14 */
15
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
23#include "aerdrv.h"
24
25#define AER_AGENT_RECEIVER 0
26#define AER_AGENT_REQUESTER 1
27#define AER_AGENT_COMPLETER 2
28#define AER_AGENT_TRANSMITTER 3
29
Hidetoshi Setof1585752009-09-07 17:08:59 +090030#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)
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080036
37#define AER_GET_AGENT(t, e) \
Hidetoshi Setof1585752009-09-07 17:08:59 +090038 ((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 : \
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080041 AER_AGENT_RECEIVER)
42
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080043#define AER_PHYSICAL_LAYER_ERROR 0
44#define AER_DATA_LINK_LAYER_ERROR 1
45#define AER_TRANSACTION_LAYER_ERROR 2
46
Hidetoshi Setof1585752009-09-07 17:08:59 +090047#define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
48 PCI_ERR_COR_RCVR : 0)
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)
54
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)
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080059
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +090060#define AER_PR(info, fmt, args...) \
61 printk("%s" fmt, (info->severity == AER_CORRECTABLE) ? \
62 KERN_WARNING : KERN_ERR, ## args)
63
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080064/*
65 * AER error strings
66 */
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090067static char *aer_error_severity_string[] = {
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080068 "Uncorrected (Non-Fatal)",
69 "Uncorrected (Fatal)",
70 "Corrected"
71};
72
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090073static char *aer_error_layer[] = {
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080074 "Physical Layer",
75 "Data Link Layer",
76 "Transaction Layer"
77};
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090078static char *aer_correctable_error_string[] = {
79 "Receiver Error ", /* Bit Position 0 */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080080 NULL,
81 NULL,
82 NULL,
83 NULL,
84 NULL,
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090085 "Bad TLP ", /* Bit Position 6 */
86 "Bad DLLP ", /* Bit Position 7 */
87 "RELAY_NUM Rollover ", /* Bit Position 8 */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080088 NULL,
89 NULL,
90 NULL,
Hidetoshi Setoc9a91882009-09-07 17:07:29 +090091 "Replay Timer Timeout ", /* Bit Position 12 */
92 "Advisory Non-Fatal ", /* Bit Position 13 */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +080093 NULL,
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 NULL,
108 NULL,
109 NULL,
110 NULL,
111};
112
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900113static char *aer_uncorrectable_error_string[] = {
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800114 NULL,
115 NULL,
116 NULL,
117 NULL,
118 "Data Link Protocol ", /* Bit Position 4 */
119 NULL,
120 NULL,
121 NULL,
122 NULL,
123 NULL,
124 NULL,
125 NULL,
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900126 "Poisoned TLP ", /* Bit Position 12 */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800127 "Flow Control Protocol ", /* Bit Position 13 */
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900128 "Completion Timeout ", /* Bit Position 14 */
129 "Completer Abort ", /* Bit Position 15 */
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800130 "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 */
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 NULL,
140 NULL,
141 NULL,
142 NULL,
143 NULL,
144 NULL,
145 NULL,
146};
147
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900148static char *aer_agent_string[] = {
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800149 "Receiver ID",
150 "Requester ID",
151 "Completer ID",
152 "Transmitter ID"
153};
154
Hidetoshi Seto24dbb7b2009-09-07 17:11:29 +0900155static void aer_print_error_source(struct aer_err_info *info)
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800156{
Hidetoshi Seto0d90c3a2009-09-07 17:12:25 +0900157 int i, status;
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900158 char *errmsg = NULL;
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800159
Hidetoshi Seto0d90c3a2009-09-07 17:12:25 +0900160 status = (info->status & ~info->mask);
161
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800162 for (i = 0; i < 32; i++) {
Hidetoshi Seto0d90c3a2009-09-07 17:12:25 +0900163 if (!(status & (1 << i)))
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800164 continue;
165
Hidetoshi Seto24dbb7b2009-09-07 17:11:29 +0900166 if (info->severity == AER_CORRECTABLE)
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800167 errmsg = aer_correctable_error_string[i];
168 else
169 errmsg = aer_uncorrectable_error_string[i];
170
Hidetoshi Seto24dbb7b2009-09-07 17:11:29 +0900171 if (errmsg)
Hidetoshi Setoe7a0d922009-09-07 17:13:42 +0900172 AER_PR(info, "%s\t: %s\n", errmsg,
173 info->first == i ? "First" : "");
Hidetoshi Seto24dbb7b2009-09-07 17:11:29 +0900174 else
Hidetoshi Setoe7a0d922009-09-07 17:13:42 +0900175 AER_PR(info, "Unknown Error Bit %2d \t: %s\n",
176 i, info->first == i ? "First" : "");
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800177 }
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800178}
179
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800180void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
181{
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800182 int err_layer, agent;
Hidetoshi Seto0d465f22009-09-07 17:10:40 +0900183 int id = ((dev->bus->number << 8) | dev->devfn);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800184
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +0900185 AER_PR(info, "+------ PCI-Express Device Error ------+\n");
186 AER_PR(info, "Error Severity\t\t: %s\n",
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800187 aer_error_severity_string[info->severity]);
188
Hidetoshi Setoc9a91882009-09-07 17:07:29 +0900189 if (info->status == 0) {
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +0900190 AER_PR(info, "PCIE Bus Error type\t: (Unaccessible)\n");
Hidetoshi Seto0d465f22009-09-07 17:10:40 +0900191 AER_PR(info, "Unregistered Agent ID\t: %04x\n", id);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800192 } else {
193 err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +0900194 AER_PR(info, "PCIE Bus Error type\t: %s\n",
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800195 aer_error_layer[err_layer]);
196
Hidetoshi Seto24dbb7b2009-09-07 17:11:29 +0900197 aer_print_error_source(info);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800198
199 agent = AER_GET_AGENT(info->severity, info->status);
Hidetoshi Seto0d465f22009-09-07 17:10:40 +0900200 AER_PR(info, "%s\t\t: %04x\n", aer_agent_string[agent], id);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800201
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +0900202 AER_PR(info, "VendorID=%04xh, DeviceID=%04xh,"
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800203 " Bus=%02xh, Device=%02xh, Function=%02xh\n",
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800204 dev->vendor,
205 dev->device,
206 dev->bus->number,
207 PCI_SLOT(dev->devfn),
208 PCI_FUNC(dev->devfn));
209
210 if (info->flags & AER_TLP_HEADER_VALID_FLAG) {
211 unsigned char *tlp = (unsigned char *) &info->tlp;
Hidetoshi Setobd8fedd2009-09-07 17:08:14 +0900212 AER_PR(info, "TLP Header:\n");
213 AER_PR(info, "%02x%02x%02x%02x %02x%02x%02x%02x"
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800214 " %02x%02x%02x%02x %02x%02x%02x%02x\n",
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800215 *(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));
220 }
221 }
Hidetoshi Seto0d465f22009-09-07 17:10:40 +0900222
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",
225 id);
Zhang, Yanmin6c2b3742006-07-31 15:21:33 +0800226}