aerdrv_errprint.c 7.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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>
22
#include <linux/cper.h>
23 24 25

#include "aerdrv.h"

L
Lance Ortiz 已提交
26 27 28
#define CREATE_TRACE_POINTS
#include <trace/events/ras.h>

29 30 31 32 33
#define AER_AGENT_RECEIVER		0
#define AER_AGENT_REQUESTER		1
#define AER_AGENT_COMPLETER		2
#define AER_AGENT_TRANSMITTER		3

34 35 36 37 38 39
#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)
40 41

#define AER_GET_AGENT(t, e)						\
42 43 44
	((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 :	\
45 46 47 48 49 50
	AER_AGENT_RECEIVER)

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

51 52 53 54 55 56 57 58 59 60 61 62
#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)
63 64 65 66

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

73
static const char *aer_error_layer[] = {
74 75 76 77
	"Physical Layer",
	"Data Link Layer",
	"Transaction Layer"
};
78 79 80

static const char *aer_correctable_error_string[] = {
	"Receiver Error",		/* Bit Position 0	*/
81 82 83 84 85
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
86 87 88
	"Bad TLP",			/* Bit Position 6	*/
	"Bad DLLP",			/* Bit Position 7	*/
	"RELAY_NUM Rollover",		/* Bit Position 8	*/
89 90 91
	NULL,
	NULL,
	NULL,
92 93
	"Replay Timer Timeout",		/* Bit Position 12	*/
	"Advisory Non-Fatal",		/* Bit Position 13	*/
94 95
};

96
static const char *aer_uncorrectable_error_string[] = {
97 98 99 100
	NULL,
	NULL,
	NULL,
	NULL,
101
	"Data Link Protocol",		/* Bit Position 4	*/
102 103 104 105 106 107 108
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
109 110 111 112 113 114 115 116 117
	"Poisoned TLP",			/* Bit Position 12	*/
	"Flow Control Protocol",	/* Bit Position 13	*/
	"Completion Timeout",		/* Bit Position 14	*/
	"Completer Abort",		/* Bit Position 15	*/
	"Unexpected Completion",	/* Bit Position 16	*/
	"Receiver Overflow",		/* Bit Position 17	*/
	"Malformed TLP",		/* Bit Position 18	*/
	"ECRC",				/* Bit Position 19	*/
	"Unsupported Request",		/* Bit Position 20	*/
118 119
};

120
static const char *aer_agent_string[] = {
121 122 123 124 125 126
	"Receiver ID",
	"Requester ID",
	"Completer ID",
	"Transmitter ID"
};

L
Lance Ortiz 已提交
127
static void __aer_print_error(struct pci_dev *dev,
128
			      struct aer_err_info *info)
129
{
130
	int i, status;
131
	const char *errmsg = NULL;
132 133
	status = (info->status & ~info->mask);

134
	for (i = 0; i < 32; i++) {
135
		if (!(status & (1 << i)))
136 137
			continue;

138
		if (info->severity == AER_CORRECTABLE)
139 140
			errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
				aer_correctable_error_string[i] : NULL;
141
		else
142 143
			errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
				aer_uncorrectable_error_string[i] : NULL;
144

145
		if (errmsg)
L
Lance Ortiz 已提交
146
			dev_err(&dev->dev, "   [%2d] %-22s%s\n", i, errmsg,
147
				info->first_error == i ? " (First)" : "");
148
		else
L
Lance Ortiz 已提交
149 150
			dev_err(&dev->dev, "   [%2d] Unknown Error Bit%s\n",
				i, info->first_error == i ? " (First)" : "");
151 152 153 154 155
	}
}

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

158
	if (info->status == 0) {
L
Lance Ortiz 已提交
159 160 161
		dev_err(&dev->dev,
			"PCIe Bus Error: severity=%s, type=Unaccessible, "
			"id=%04x(Unregistered Agent ID)\n",
162
			aer_error_severity_string[info->severity], id);
163
	} else {
164
		int layer, agent;
165

166
		layer = AER_GET_LAYER_ERROR(info->severity, info->status);
167 168
		agent = AER_GET_AGENT(info->severity, info->status);

L
Lance Ortiz 已提交
169 170 171
		dev_err(&dev->dev,
			"PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
			aer_error_severity_string[info->severity],
172 173
			aer_error_layer[layer], id, aer_agent_string[agent]);

L
Lance Ortiz 已提交
174 175 176
		dev_err(&dev->dev,
			"  device [%04x:%04x] error status/mask=%08x/%08x\n",
			dev->vendor, dev->device,
177
			info->status, info->mask);
178

L
Lance Ortiz 已提交
179
		__aer_print_error(dev, info);
180

H
Hidetoshi Seto 已提交
181
		if (info->tlp_header_valid) {
182
			unsigned char *tlp = (unsigned char *) &info->tlp;
L
Lance Ortiz 已提交
183
			dev_err(&dev->dev, "  TLP Header:"
184
				" %02x%02x%02x%02x %02x%02x%02x%02x"
185
				" %02x%02x%02x%02x %02x%02x%02x%02x\n",
L
Lance Ortiz 已提交
186
				*(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
187 188 189 190 191 192
				*(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
				*(tlp + 11), *(tlp + 10), *(tlp + 9),
				*(tlp + 8), *(tlp + 15), *(tlp + 14),
				*(tlp + 13), *(tlp + 12));
		}
	}
193 194

	if (info->id && info->error_dev_num > 1 && info->id == id)
L
Lance Ortiz 已提交
195 196 197
		dev_err(&dev->dev,
			   "  Error of this Agent(%04x) is reported first\n",
			id);
L
Lance Ortiz 已提交
198 199
	trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask),
			info->severity);
200 201 202 203 204 205 206
}

void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
{
	dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
		info->multi_error_valid ? "Multiple " : "",
		aer_error_severity_string[info->severity], info->id);
207
}
208 209

#ifdef CONFIG_ACPI_APEI_PCIEAER
210
int cper_severity_to_aer(int cper_severity)
211 212 213 214 215 216 217 218 219 220
{
	switch (cper_severity) {
	case CPER_SEV_RECOVERABLE:
		return AER_NONFATAL;
	case CPER_SEV_FATAL:
		return AER_FATAL;
	default:
		return AER_CORRECTABLE;
	}
}
221
EXPORT_SYMBOL_GPL(cper_severity_to_aer);
222

L
Lance Ortiz 已提交
223
void cper_print_aer(const char *prefix, struct pci_dev *dev, int cper_severity,
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
		    struct aer_capability_regs *aer)
{
	int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0;
	u32 status, mask;
	const char **status_strs;

	aer_severity = cper_severity_to_aer(cper_severity);
	if (aer_severity == AER_CORRECTABLE) {
		status = aer->cor_status;
		mask = aer->cor_mask;
		status_strs = aer_correctable_error_string;
		status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
	} else {
		status = aer->uncor_status;
		mask = aer->uncor_mask;
		status_strs = aer_uncorrectable_error_string;
		status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
		tlp_header_valid = status & AER_LOG_TLP_MASKS;
	}
	layer = AER_GET_LAYER_ERROR(aer_severity, status);
	agent = AER_GET_AGENT(aer_severity, status);
L
Lance Ortiz 已提交
245 246
	dev_err(&dev->dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n",
	       status, mask);
247
	cper_print_bits(prefix, status, status_strs, status_strs_size);
L
Lance Ortiz 已提交
248
	dev_err(&dev->dev, "aer_layer=%s, aer_agent=%s\n",
249 250
	       aer_error_layer[layer], aer_agent_string[agent]);
	if (aer_severity != AER_CORRECTABLE)
L
Lance Ortiz 已提交
251 252
		dev_err(&dev->dev, "aer_uncor_severity: 0x%08x\n",
		       aer->uncor_severity);
253 254 255
	if (tlp_header_valid) {
		const unsigned char *tlp;
		tlp = (const unsigned char *)&aer->header_log;
L
Lance Ortiz 已提交
256
		dev_err(&dev->dev, "aer_tlp_header:"
257 258
			" %02x%02x%02x%02x %02x%02x%02x%02x"
			" %02x%02x%02x%02x %02x%02x%02x%02x\n",
L
Lance Ortiz 已提交
259
			*(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
260 261 262 263 264
			*(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
			*(tlp + 11), *(tlp + 10), *(tlp + 9),
			*(tlp + 8), *(tlp + 15), *(tlp + 14),
			*(tlp + 13), *(tlp + 12));
	}
L
Lance Ortiz 已提交
265 266
	trace_aer_event(dev_name(&dev->dev), (status & ~mask),
			aer_severity);
267 268
}
#endif