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> |
| 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 Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 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) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 36 | |
| 37 | #define AER_GET_AGENT(t, e) \ |
Hidetoshi Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 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 : \ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 41 | AER_AGENT_RECEIVER) |
| 42 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 43 | #define AER_PHYSICAL_LAYER_ERROR 0 |
| 44 | #define AER_DATA_LINK_LAYER_ERROR 1 |
| 45 | #define AER_TRANSACTION_LAYER_ERROR 2 |
| 46 | |
Hidetoshi Seto | f158575 | 2009-09-07 17:08:59 +0900 | [diff] [blame] | 47 | #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, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 59 | |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 60 | #define AER_PR(info, pdev, fmt, args...) \ |
| 61 | printk("%s%s %s: " fmt, (info->severity == AER_CORRECTABLE) ? \ |
| 62 | KERN_WARNING : KERN_ERR, dev_driver_string(&pdev->dev), \ |
| 63 | dev_name(&pdev->dev), ## args) |
Hidetoshi Seto | bd8fedd | 2009-09-07 17:08:14 +0900 | [diff] [blame] | 64 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 65 | /* |
| 66 | * AER error strings |
| 67 | */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 68 | static char *aer_error_severity_string[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 69 | "Uncorrected (Non-Fatal)", |
| 70 | "Uncorrected (Fatal)", |
| 71 | "Corrected" |
| 72 | }; |
| 73 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 74 | static char *aer_error_layer[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 75 | "Physical Layer", |
| 76 | "Data Link Layer", |
| 77 | "Transaction Layer" |
| 78 | }; |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 79 | static char *aer_correctable_error_string[] = { |
| 80 | "Receiver Error ", /* Bit Position 0 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 81 | NULL, |
| 82 | NULL, |
| 83 | NULL, |
| 84 | NULL, |
| 85 | NULL, |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 86 | "Bad TLP ", /* Bit Position 6 */ |
| 87 | "Bad DLLP ", /* Bit Position 7 */ |
| 88 | "RELAY_NUM Rollover ", /* Bit Position 8 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 89 | NULL, |
| 90 | NULL, |
| 91 | NULL, |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 92 | "Replay Timer Timeout ", /* Bit Position 12 */ |
| 93 | "Advisory Non-Fatal ", /* Bit Position 13 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 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 | NULL, |
| 112 | }; |
| 113 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 114 | static char *aer_uncorrectable_error_string[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 115 | NULL, |
| 116 | NULL, |
| 117 | NULL, |
| 118 | NULL, |
| 119 | "Data Link Protocol ", /* Bit Position 4 */ |
| 120 | NULL, |
| 121 | NULL, |
| 122 | NULL, |
| 123 | NULL, |
| 124 | NULL, |
| 125 | NULL, |
| 126 | NULL, |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 127 | "Poisoned TLP ", /* Bit Position 12 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 128 | "Flow Control Protocol ", /* Bit Position 13 */ |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 129 | "Completion Timeout ", /* Bit Position 14 */ |
| 130 | "Completer Abort ", /* Bit Position 15 */ |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 131 | "Unexpected Completion ", /* Bit Position 16 */ |
| 132 | "Receiver Overflow ", /* Bit Position 17 */ |
| 133 | "Malformed TLP ", /* Bit Position 18 */ |
| 134 | "ECRC ", /* Bit Position 19 */ |
| 135 | "Unsupported Request ", /* Bit Position 20 */ |
| 136 | NULL, |
| 137 | NULL, |
| 138 | NULL, |
| 139 | NULL, |
| 140 | NULL, |
| 141 | NULL, |
| 142 | NULL, |
| 143 | NULL, |
| 144 | NULL, |
| 145 | NULL, |
| 146 | NULL, |
| 147 | }; |
| 148 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 149 | static char *aer_agent_string[] = { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 150 | "Receiver ID", |
| 151 | "Requester ID", |
| 152 | "Completer ID", |
| 153 | "Transmitter ID" |
| 154 | }; |
| 155 | |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 156 | static void __aer_print_error(struct aer_err_info *info, struct pci_dev *dev) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 157 | { |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 158 | int i, status; |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 159 | char *errmsg = NULL; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 160 | |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 161 | status = (info->status & ~info->mask); |
| 162 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 163 | for (i = 0; i < 32; i++) { |
Hidetoshi Seto | 0d90c3a | 2009-09-07 17:12:25 +0900 | [diff] [blame] | 164 | if (!(status & (1 << i))) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 165 | continue; |
| 166 | |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 167 | if (info->severity == AER_CORRECTABLE) |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 168 | errmsg = aer_correctable_error_string[i]; |
| 169 | else |
| 170 | errmsg = aer_uncorrectable_error_string[i]; |
| 171 | |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 172 | if (errmsg) |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 173 | AER_PR(info, dev, " [%2d] %s%s\n", i, errmsg, |
| 174 | info->first_error == i ? " (First)" : ""); |
Hidetoshi Seto | 24dbb7b | 2009-09-07 17:11:29 +0900 | [diff] [blame] | 175 | else |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 176 | AER_PR(info, dev, " [%2d] Unknown Error Bit%s\n", i, |
| 177 | info->first_error == i ? " (First)" : ""); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 178 | } |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 179 | } |
| 180 | |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 181 | void aer_print_error(struct pci_dev *dev, struct aer_err_info *info) |
| 182 | { |
Hidetoshi Seto | 0d465f2 | 2009-09-07 17:10:40 +0900 | [diff] [blame] | 183 | int id = ((dev->bus->number << 8) | dev->devfn); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 184 | |
Hidetoshi Seto | c9a9188 | 2009-09-07 17:07:29 +0900 | [diff] [blame] | 185 | if (info->status == 0) { |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 186 | AER_PR(info, dev, |
| 187 | "PCIE Bus Error: severity=%s, type=Unaccessible, " |
| 188 | "id=%04x(Unregistered Agent ID)\n", |
| 189 | aer_error_severity_string[info->severity], id); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 190 | } else { |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 191 | int layer, agent; |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 192 | |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 193 | layer = AER_GET_LAYER_ERROR(info->severity, info->status); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 194 | agent = AER_GET_AGENT(info->severity, info->status); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 195 | |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 196 | AER_PR(info, dev, |
| 197 | "PCIE Bus Error: severity=%s, type=%s, id=%04x(%s)\n", |
| 198 | aer_error_severity_string[info->severity], |
| 199 | aer_error_layer[layer], id, aer_agent_string[agent]); |
| 200 | |
| 201 | AER_PR(info, dev, |
| 202 | " device [%04x:%04x] error status/mask=%08x/%08x\n", |
| 203 | dev->vendor, dev->device, info->status, info->mask); |
| 204 | |
| 205 | __aer_print_error(info, dev); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 206 | |
Hidetoshi Seto | 273024d | 2009-09-07 17:16:20 +0900 | [diff] [blame] | 207 | if (info->tlp_header_valid) { |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 208 | unsigned char *tlp = (unsigned char *) &info->tlp; |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 209 | AER_PR(info, dev, " TLP Header:" |
| 210 | " %02x%02x%02x%02x %02x%02x%02x%02x" |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 211 | " %02x%02x%02x%02x %02x%02x%02x%02x\n", |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 212 | *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp, |
| 213 | *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4), |
| 214 | *(tlp + 11), *(tlp + 10), *(tlp + 9), |
| 215 | *(tlp + 8), *(tlp + 15), *(tlp + 14), |
| 216 | *(tlp + 13), *(tlp + 12)); |
| 217 | } |
| 218 | } |
Hidetoshi Seto | 0d465f2 | 2009-09-07 17:10:40 +0900 | [diff] [blame] | 219 | |
| 220 | if (info->id && info->error_dev_num > 1 && info->id == id) |
Hidetoshi Seto | 79e4b89 | 2009-09-07 17:16:45 +0900 | [diff] [blame] | 221 | AER_PR(info, dev, |
| 222 | " Error of this Agent(%04x) is reported first\n", id); |
| 223 | } |
| 224 | |
| 225 | void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info) |
| 226 | { |
| 227 | dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n", |
| 228 | info->multi_error_valid ? "Multiple " : "", |
| 229 | aer_error_severity_string[info->severity], info->id); |
Zhang, Yanmin | 6c2b374 | 2006-07-31 15:21:33 +0800 | [diff] [blame] | 230 | } |