aerdrv_errprint.c 5.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * drivers/pci/pcie/aer/aerdrv_errprint.c
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Format error messages and print them to console.
 *
 * Copyright (C) 2006 Intel Corp.
 *	Tom Long Nguyen (tom.l.nguyen@intel.com)
 *	Zhang Yanmin (yanmin.zhang@intel.com)
 *
 */

#include <linux/module.h>
#include <linux/pci.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/pm.h>
#include <linux/suspend.h>

#include "aerdrv.h"

#define AER_AGENT_RECEIVER		0
#define AER_AGENT_REQUESTER		1
#define AER_AGENT_COMPLETER		2
#define AER_AGENT_TRANSMITTER		3

30 31 32 33 34 35
#define AER_AGENT_REQUESTER_MASK(t)	((t == AER_CORRECTABLE) ?	\
	0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
#define AER_AGENT_COMPLETER_MASK(t)	((t == AER_CORRECTABLE) ?	\
	0 : PCI_ERR_UNC_COMP_ABORT)
#define AER_AGENT_TRANSMITTER_MASK(t)	((t == AER_CORRECTABLE) ?	\
	(PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
36 37

#define AER_GET_AGENT(t, e)						\
38 39 40
	((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER :	\
	(e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER :	\
	(e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER :	\
41 42 43 44 45 46
	AER_AGENT_RECEIVER)

#define AER_PHYSICAL_LAYER_ERROR	0
#define AER_DATA_LINK_LAYER_ERROR	1
#define AER_TRANSACTION_LAYER_ERROR	2

47 48 49 50 51 52 53 54 55 56 57 58
#define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ?	\
	PCI_ERR_COR_RCVR : 0)
#define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ?	\
	(PCI_ERR_COR_BAD_TLP|						\
	PCI_ERR_COR_BAD_DLLP|						\
	PCI_ERR_COR_REP_ROLL|						\
	PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)

#define AER_GET_LAYER_ERROR(t, e)					\
	((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
	(e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
	AER_TRANSACTION_LAYER_ERROR)
59

60 61 62 63
#define AER_PR(info, fmt, args...)				\
	printk("%s" fmt, (info->severity == AER_CORRECTABLE) ?	\
		KERN_WARNING : KERN_ERR, ## args)

64 65 66
/*
 * AER error strings
 */
67
static char *aer_error_severity_string[] = {
68 69 70 71 72
	"Uncorrected (Non-Fatal)",
	"Uncorrected (Fatal)",
	"Corrected"
};

73
static char *aer_error_layer[] = {
74 75 76 77
	"Physical Layer",
	"Data Link Layer",
	"Transaction Layer"
};
78 79
static char *aer_correctable_error_string[] = {
	"Receiver Error        ",	/* Bit Position 0	*/
80 81 82 83 84
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
85 86 87
	"Bad TLP               ",	/* Bit Position 6	*/
	"Bad DLLP              ",	/* Bit Position 7	*/
	"RELAY_NUM Rollover    ",	/* Bit Position 8	*/
88 89 90
	NULL,
	NULL,
	NULL,
91 92
	"Replay Timer Timeout  ",	/* Bit Position 12	*/
	"Advisory Non-Fatal    ",	/* Bit Position 13	*/
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
};

113
static char *aer_uncorrectable_error_string[] = {
114 115 116 117 118 119 120 121 122 123 124 125
	NULL,
	NULL,
	NULL,
	NULL,
	"Data Link Protocol    ",	/* Bit Position 4	*/
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
126
	"Poisoned TLP          ",	/* Bit Position 12	*/
127
	"Flow Control Protocol ",	/* Bit Position 13	*/
128 129
	"Completion Timeout    ",	/* Bit Position 14	*/
	"Completer Abort       ",	/* Bit Position 15	*/
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
	"Unexpected Completion ",	/* Bit Position 16	*/
	"Receiver Overflow     ",	/* Bit Position 17	*/
	"Malformed TLP         ",	/* Bit Position 18	*/
	"ECRC                  ",	/* Bit Position 19	*/
	"Unsupported Request   ",	/* Bit Position 20	*/
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
};

148
static char *aer_agent_string[] = {
149 150 151 152 153 154
	"Receiver ID",
	"Requester ID",
	"Completer ID",
	"Transmitter ID"
};

155
static void aer_print_error_source(struct aer_err_info *info)
156
{
157
	int i, status;
158
	char *errmsg = NULL;
159

160 161
	status = (info->status & ~info->mask);

162
	for (i = 0; i < 32; i++) {
163
		if (!(status & (1 << i)))
164 165
			continue;

166
		if (info->severity == AER_CORRECTABLE)
167 168 169 170
			errmsg = aer_correctable_error_string[i];
		else
			errmsg = aer_uncorrectable_error_string[i];

171
		if (errmsg)
172
			AER_PR(info, "%s\t: %s\n", errmsg,
H
Hidetoshi Seto 已提交
173
				info->first_error == i ? "First" : "");
174
		else
175
			AER_PR(info, "Unknown Error Bit %2d  \t: %s\n",
H
Hidetoshi Seto 已提交
176
				i, info->first_error == i ? "First" : "");
177 178 179 180 181 182
	}
}

void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
{
	int err_layer, agent;
183
	int id = ((dev->bus->number << 8) | dev->devfn);
184

185 186
	AER_PR(info, "+------ PCI-Express Device Error ------+\n");
	AER_PR(info, "Error Severity\t\t: %s\n",
187 188
		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);
192 193
	} else {
		err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
194
		AER_PR(info, "PCIE Bus Error type\t: %s\n",
195 196
			aer_error_layer[err_layer]);

197
		aer_print_error_source(info);
198 199

		agent = AER_GET_AGENT(info->severity, info->status);
200
		AER_PR(info, "%s\t\t: %04x\n", aer_agent_string[agent], id);
201

202
		AER_PR(info, "VendorID=%04xh, DeviceID=%04xh,"
203 204 205 206 207 208 209
			" Bus=%02xh, Device=%02xh, Function=%02xh\n",
			dev->vendor,
			dev->device,
			dev->bus->number,
			PCI_SLOT(dev->devfn),
			PCI_FUNC(dev->devfn));

H
Hidetoshi Seto 已提交
210
		if (info->tlp_header_valid) {
211
			unsigned char *tlp = (unsigned char *) &info->tlp;
212 213
			AER_PR(info, "TLP Header:\n");
			AER_PR(info, "%02x%02x%02x%02x %02x%02x%02x%02x"
214 215 216 217 218 219 220 221
				" %02x%02x%02x%02x %02x%02x%02x%02x\n",
				*(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
				*(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
				*(tlp + 11), *(tlp + 10), *(tlp + 9),
				*(tlp + 8), *(tlp + 15), *(tlp + 14),
				*(tlp + 13), *(tlp + 12));
		}
	}
222 223 224 225

	if (info->id && info->error_dev_num > 1 && info->id == id)
		AER_PR(info, "Error of this Agent(%04x) is reported first\n",
			id);
226
}