Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 1 | /* |
| 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> |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 22 | #include <linux/cper.h> |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 23 | |
| 24 | #include "aerdrv.h" |
Chen, Gong | 0a2409a | 2014-06-11 13:57:27 -0700 | [diff] [blame] | 25 | #include <ras/ras_event.h> |
Lance Ortiz | 1d52100 | 2013-01-03 15:34:08 -0700 | [diff] [blame] | 26 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 27 | #define AER_AGENT_RECEIVER 0 |
| 28 | #define AER_AGENT_REQUESTER 1 |
| 29 | #define AER_AGENT_COMPLETER 2 |
| 30 | #define AER_AGENT_TRANSMITTER 3 |
| 31 | |
Hidetoshi Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 32 | #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \ |
| 33 | 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP)) |
| 34 | #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \ |
| 35 | 0 : PCI_ERR_UNC_COMP_ABORT) |
| 36 | #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \ |
| 37 | (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 38 | |
| 39 | #define AER_GET_AGENT(t, e) \ |
Hidetoshi Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 40 | ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \ |
| 41 | (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \ |
| 42 | (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 43 | AER_AGENT_RECEIVER) |
| 44 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 45 | #define AER_PHYSICAL_LAYER_ERROR 0 |
| 46 | #define AER_DATA_LINK_LAYER_ERROR 1 |
| 47 | #define AER_TRANSACTION_LAYER_ERROR 2 |
| 48 | |
Hidetoshi Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 49 | #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \ |
| 50 | PCI_ERR_COR_RCVR : 0) |
| 51 | #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \ |
| 52 | (PCI_ERR_COR_BAD_TLP| \ |
| 53 | PCI_ERR_COR_BAD_DLLP| \ |
| 54 | PCI_ERR_COR_REP_ROLL| \ |
| 55 | PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP) |
| 56 | |
| 57 | #define AER_GET_LAYER_ERROR(t, e) \ |
| 58 | ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \ |
| 59 | (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \ |
| 60 | AER_TRANSACTION_LAYER_ERROR) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * AER error strings |
| 64 | */ |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 65 | static const char *aer_error_severity_string[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 66 | "Uncorrected (Non-Fatal)", |
| 67 | "Uncorrected (Fatal)", |
| 68 | "Corrected" |
| 69 | }; |
| 70 | |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 71 | static const char *aer_error_layer[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 72 | "Physical Layer", |
| 73 | "Data Link Layer", |
| 74 | "Transaction Layer" |
| 75 | }; |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 76 | |
| 77 | static const char *aer_correctable_error_string[] = { |
| 78 | "Receiver Error", /* Bit Position 0 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 79 | NULL, |
| 80 | NULL, |
| 81 | NULL, |
| 82 | NULL, |
| 83 | NULL, |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 84 | "Bad TLP", /* Bit Position 6 */ |
| 85 | "Bad DLLP", /* Bit Position 7 */ |
| 86 | "RELAY_NUM Rollover", /* Bit Position 8 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 87 | NULL, |
| 88 | NULL, |
| 89 | NULL, |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 90 | "Replay Timer Timeout", /* Bit Position 12 */ |
| 91 | "Advisory Non-Fatal", /* Bit Position 13 */ |
Chen, Gong | d179111 | 2014-09-25 09:36:43 -0600 | [diff] [blame] | 92 | "Corrected Internal Error", /* Bit Position 14 */ |
| 93 | "Header Log Overflow", /* Bit Position 15 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 94 | }; |
| 95 | |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 96 | static const char *aer_uncorrectable_error_string[] = { |
Chen, Gong | d179111 | 2014-09-25 09:36:43 -0600 | [diff] [blame] | 97 | "Undefined", /* Bit Position 0 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 98 | NULL, |
| 99 | NULL, |
| 100 | NULL, |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 101 | "Data Link Protocol", /* Bit Position 4 */ |
Chen, Gong | d179111 | 2014-09-25 09:36:43 -0600 | [diff] [blame] | 102 | "Surprise Down Error", /* Bit Position 5 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 103 | NULL, |
| 104 | NULL, |
| 105 | NULL, |
| 106 | NULL, |
| 107 | NULL, |
| 108 | NULL, |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 109 | "Poisoned TLP", /* Bit Position 12 */ |
| 110 | "Flow Control Protocol", /* Bit Position 13 */ |
| 111 | "Completion Timeout", /* Bit Position 14 */ |
| 112 | "Completer Abort", /* Bit Position 15 */ |
| 113 | "Unexpected Completion", /* Bit Position 16 */ |
| 114 | "Receiver Overflow", /* Bit Position 17 */ |
| 115 | "Malformed TLP", /* Bit Position 18 */ |
| 116 | "ECRC", /* Bit Position 19 */ |
| 117 | "Unsupported Request", /* Bit Position 20 */ |
Chen, Gong | d179111 | 2014-09-25 09:36:43 -0600 | [diff] [blame] | 118 | "ACS Violation", /* Bit Position 21 */ |
| 119 | "Uncorrectable Internal Error", /* Bit Position 22 */ |
| 120 | "MC Blocked TLP", /* Bit Position 23 */ |
| 121 | "AtomicOp Egress Blocked", /* Bit Position 24 */ |
| 122 | "TLP Prefix Blocked Error", /* Bit Position 25 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 123 | }; |
| 124 | |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 125 | static const char *aer_agent_string[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 126 | "Receiver ID", |
| 127 | "Requester ID", |
| 128 | "Completer ID", |
| 129 | "Transmitter ID" |
| 130 | }; |
| 131 | |
Borislav Petkov | fab4c25 | 2013-12-13 14:39:56 -0700 | [diff] [blame] | 132 | static void __print_tlp_header(struct pci_dev *dev, |
| 133 | struct aer_header_log_regs *t) |
| 134 | { |
| 135 | unsigned char *tlp = (unsigned char *)&t; |
| 136 | |
| 137 | dev_err(&dev->dev, " TLP Header:" |
| 138 | " %02x%02x%02x%02x %02x%02x%02x%02x" |
| 139 | " %02x%02x%02x%02x %02x%02x%02x%02x\n", |
| 140 | *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp, |
| 141 | *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4), |
| 142 | *(tlp + 11), *(tlp + 10), *(tlp + 9), |
| 143 | *(tlp + 8), *(tlp + 15), *(tlp + 14), |
| 144 | *(tlp + 13), *(tlp + 12)); |
| 145 | } |
| 146 | |
Lance Ortiz | 2cced2d | 2013-01-03 15:34:15 -0700 | [diff] [blame] | 147 | static void __aer_print_error(struct pci_dev *dev, |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 148 | struct aer_err_info *info) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 149 | { |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 150 | int i, status; |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 151 | const char *errmsg = NULL; |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 152 | status = (info->status & ~info->mask); |
| 153 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 154 | for (i = 0; i < 32; i++) { |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 155 | if (!(status & (1 << i))) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 156 | continue; |
| 157 | |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 158 | if (info->severity == AER_CORRECTABLE) |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 159 | errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ? |
| 160 | aer_correctable_error_string[i] : NULL; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 161 | else |
Huang Ying | b64a441 | 2011-02-21 13:54:42 +0800 | [diff] [blame] | 162 | errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ? |
| 163 | aer_uncorrectable_error_string[i] : NULL; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 164 | |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 165 | if (errmsg) |
Lance Ortiz | 2cced2d | 2013-01-03 15:34:15 -0700 | [diff] [blame] | 166 | dev_err(&dev->dev, " [%2d] %-22s%s\n", i, errmsg, |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 167 | info->first_error == i ? " (First)" : ""); |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 168 | else |
Lance Ortiz | 2cced2d | 2013-01-03 15:34:15 -0700 | [diff] [blame] | 169 | dev_err(&dev->dev, " [%2d] Unknown Error Bit%s\n", |
| 170 | i, info->first_error == i ? " (First)" : ""); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 171 | } |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 172 | } |
| 173 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 174 | void aer_print_error(struct pci_dev *dev, struct aer_err_info *info) |
| 175 | { |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 176 | int layer, agent; |
Hidetoshi Seto | 0d465f2 | 2009-09-07 17:10:40 +0900 | [diff] [blame] | 177 | int id = ((dev->bus->number << 8) | dev->devfn); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 178 | |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 179 | if (!info->status) { |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 180 | dev_err(&dev->dev, "PCIe Bus Error: severity=%s, type=Unaccessible, id=%04x(Unregistered Agent ID)\n", |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 181 | aer_error_severity_string[info->severity], id); |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 182 | goto out; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 183 | } |
Hidetoshi Seto | 0d465f2 | 2009-09-07 17:10:40 +0900 | [diff] [blame] | 184 | |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 185 | layer = AER_GET_LAYER_ERROR(info->severity, info->status); |
| 186 | agent = AER_GET_AGENT(info->severity, info->status); |
| 187 | |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 188 | dev_err(&dev->dev, "PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n", |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 189 | aer_error_severity_string[info->severity], |
| 190 | aer_error_layer[layer], id, aer_agent_string[agent]); |
| 191 | |
Ryan Desfosses | 227f064 | 2014-04-18 20:13:50 -0400 | [diff] [blame] | 192 | dev_err(&dev->dev, " device [%04x:%04x] error status/mask=%08x/%08x\n", |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 193 | dev->vendor, dev->device, |
| 194 | info->status, info->mask); |
| 195 | |
| 196 | __aer_print_error(dev, info); |
| 197 | |
| 198 | if (info->tlp_header_valid) |
| 199 | __print_tlp_header(dev, &info->tlp); |
| 200 | |
| 201 | out: |
Hidetoshi Seto | 0d465f2 | 2009-09-07 17:10:40 +0900 | [diff] [blame] | 202 | if (info->id && info->error_dev_num > 1 && info->id == id) |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 203 | dev_err(&dev->dev, " Error of this Agent(%04x) is reported first\n", id); |
| 204 | |
Lance Ortiz | 1d52100 | 2013-01-03 15:34:08 -0700 | [diff] [blame] | 205 | trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask), |
| 206 | info->severity); |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info) |
| 210 | { |
| 211 | dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n", |
| 212 | info->multi_error_valid ? "Multiple " : "", |
| 213 | aer_error_severity_string[info->severity], info->id); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 214 | } |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 215 | |
| 216 | #ifdef CONFIG_ACPI_APEI_PCIEAER |
Huang Ying | 0918472 | 2011-05-17 16:08:37 +0800 | [diff] [blame] | 217 | int cper_severity_to_aer(int cper_severity) |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 218 | { |
| 219 | switch (cper_severity) { |
| 220 | case CPER_SEV_RECOVERABLE: |
| 221 | return AER_NONFATAL; |
| 222 | case CPER_SEV_FATAL: |
| 223 | return AER_FATAL; |
| 224 | default: |
| 225 | return AER_CORRECTABLE; |
| 226 | } |
| 227 | } |
Huang Ying | 0918472 | 2011-05-17 16:08:37 +0800 | [diff] [blame] | 228 | EXPORT_SYMBOL_GPL(cper_severity_to_aer); |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 229 | |
Lance Ortiz | 37448ad | 2013-05-30 08:25:12 -0600 | [diff] [blame] | 230 | void cper_print_aer(struct pci_dev *dev, int cper_severity, |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 231 | struct aer_capability_regs *aer) |
| 232 | { |
| 233 | int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0; |
| 234 | u32 status, mask; |
| 235 | const char **status_strs; |
| 236 | |
| 237 | aer_severity = cper_severity_to_aer(cper_severity); |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 238 | |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 239 | if (aer_severity == AER_CORRECTABLE) { |
| 240 | status = aer->cor_status; |
| 241 | mask = aer->cor_mask; |
| 242 | status_strs = aer_correctable_error_string; |
| 243 | status_strs_size = ARRAY_SIZE(aer_correctable_error_string); |
| 244 | } else { |
| 245 | status = aer->uncor_status; |
| 246 | mask = aer->uncor_mask; |
| 247 | status_strs = aer_uncorrectable_error_string; |
| 248 | status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string); |
| 249 | tlp_header_valid = status & AER_LOG_TLP_MASKS; |
| 250 | } |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 251 | |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 252 | layer = AER_GET_LAYER_ERROR(aer_severity, status); |
| 253 | agent = AER_GET_AGENT(aer_severity, status); |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 254 | |
| 255 | dev_err(&dev->dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n", status, mask); |
Lance Ortiz | 37448ad | 2013-05-30 08:25:12 -0600 | [diff] [blame] | 256 | cper_print_bits("", status, status_strs, status_strs_size); |
Lance Ortiz | 2cced2d | 2013-01-03 15:34:15 -0700 | [diff] [blame] | 257 | dev_err(&dev->dev, "aer_layer=%s, aer_agent=%s\n", |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 258 | aer_error_layer[layer], aer_agent_string[agent]); |
| 259 | |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 260 | if (aer_severity != AER_CORRECTABLE) |
Lance Ortiz | 2cced2d | 2013-01-03 15:34:15 -0700 | [diff] [blame] | 261 | dev_err(&dev->dev, "aer_uncor_severity: 0x%08x\n", |
Borislav Petkov | 1c38108 | 2013-12-13 14:40:03 -0700 | [diff] [blame] | 262 | aer->uncor_severity); |
Borislav Petkov | fab4c25 | 2013-12-13 14:39:56 -0700 | [diff] [blame] | 263 | |
| 264 | if (tlp_header_valid) |
| 265 | __print_tlp_header(dev, &aer->header_log); |
| 266 | |
Lance Ortiz | 1d52100 | 2013-01-03 15:34:08 -0700 | [diff] [blame] | 267 | trace_aer_event(dev_name(&dev->dev), (status & ~mask), |
| 268 | aer_severity); |
Huang Ying | c413d76 | 2011-02-21 13:54:43 +0800 | [diff] [blame] | 269 | } |
| 270 | #endif |