aerdrv_errprint.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/kernel.h>
  18. #include <linux/errno.h>
  19. #include <linux/pm.h>
  20. #include <linux/suspend.h>
  21. #include <linux/cper.h>
  22. #include "aerdrv.h"
  23. #define AER_AGENT_RECEIVER 0
  24. #define AER_AGENT_REQUESTER 1
  25. #define AER_AGENT_COMPLETER 2
  26. #define AER_AGENT_TRANSMITTER 3
  27. #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
  28. 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
  29. #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
  30. 0 : PCI_ERR_UNC_COMP_ABORT)
  31. #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
  32. (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
  33. #define AER_GET_AGENT(t, e) \
  34. ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
  35. (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
  36. (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
  37. AER_AGENT_RECEIVER)
  38. #define AER_PHYSICAL_LAYER_ERROR 0
  39. #define AER_DATA_LINK_LAYER_ERROR 1
  40. #define AER_TRANSACTION_LAYER_ERROR 2
  41. #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
  42. PCI_ERR_COR_RCVR : 0)
  43. #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
  44. (PCI_ERR_COR_BAD_TLP| \
  45. PCI_ERR_COR_BAD_DLLP| \
  46. PCI_ERR_COR_REP_ROLL| \
  47. PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
  48. #define AER_GET_LAYER_ERROR(t, e) \
  49. ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
  50. (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
  51. AER_TRANSACTION_LAYER_ERROR)
  52. /*
  53. * AER error strings
  54. */
  55. static const char *aer_error_severity_string[] = {
  56. "Uncorrected (Non-Fatal)",
  57. "Uncorrected (Fatal)",
  58. "Corrected"
  59. };
  60. static const char *aer_error_layer[] = {
  61. "Physical Layer",
  62. "Data Link Layer",
  63. "Transaction Layer"
  64. };
  65. static const char *aer_correctable_error_string[] = {
  66. "Receiver Error", /* Bit Position 0 */
  67. NULL,
  68. NULL,
  69. NULL,
  70. NULL,
  71. NULL,
  72. "Bad TLP", /* Bit Position 6 */
  73. "Bad DLLP", /* Bit Position 7 */
  74. "RELAY_NUM Rollover", /* Bit Position 8 */
  75. NULL,
  76. NULL,
  77. NULL,
  78. "Replay Timer Timeout", /* Bit Position 12 */
  79. "Advisory Non-Fatal", /* Bit Position 13 */
  80. };
  81. static const char *aer_uncorrectable_error_string[] = {
  82. NULL,
  83. NULL,
  84. NULL,
  85. NULL,
  86. "Data Link Protocol", /* Bit Position 4 */
  87. NULL,
  88. NULL,
  89. NULL,
  90. NULL,
  91. NULL,
  92. NULL,
  93. NULL,
  94. "Poisoned TLP", /* Bit Position 12 */
  95. "Flow Control Protocol", /* Bit Position 13 */
  96. "Completion Timeout", /* Bit Position 14 */
  97. "Completer Abort", /* Bit Position 15 */
  98. "Unexpected Completion", /* Bit Position 16 */
  99. "Receiver Overflow", /* Bit Position 17 */
  100. "Malformed TLP", /* Bit Position 18 */
  101. "ECRC", /* Bit Position 19 */
  102. "Unsupported Request", /* Bit Position 20 */
  103. };
  104. static const char *aer_agent_string[] = {
  105. "Receiver ID",
  106. "Requester ID",
  107. "Completer ID",
  108. "Transmitter ID"
  109. };
  110. static void __aer_print_error(const char *prefix,
  111. struct aer_err_info *info)
  112. {
  113. int i, status;
  114. const char *errmsg = NULL;
  115. status = (info->status & ~info->mask);
  116. for (i = 0; i < 32; i++) {
  117. if (!(status & (1 << i)))
  118. continue;
  119. if (info->severity == AER_CORRECTABLE)
  120. errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
  121. aer_correctable_error_string[i] : NULL;
  122. else
  123. errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
  124. aer_uncorrectable_error_string[i] : NULL;
  125. if (errmsg)
  126. printk("%s"" [%2d] %-22s%s\n", prefix, i, errmsg,
  127. info->first_error == i ? " (First)" : "");
  128. else
  129. printk("%s"" [%2d] Unknown Error Bit%s\n", prefix, i,
  130. info->first_error == i ? " (First)" : "");
  131. }
  132. }
  133. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  134. {
  135. int id = ((dev->bus->number << 8) | dev->devfn);
  136. char prefix[44];
  137. snprintf(prefix, sizeof(prefix), "%s%s %s: ",
  138. (info->severity == AER_CORRECTABLE) ? KERN_WARNING : KERN_ERR,
  139. dev_driver_string(&dev->dev), dev_name(&dev->dev));
  140. if (info->status == 0) {
  141. printk("%s""PCIe Bus Error: severity=%s, type=Unaccessible, "
  142. "id=%04x(Unregistered Agent ID)\n", prefix,
  143. aer_error_severity_string[info->severity], id);
  144. } else {
  145. int layer, agent;
  146. layer = AER_GET_LAYER_ERROR(info->severity, info->status);
  147. agent = AER_GET_AGENT(info->severity, info->status);
  148. printk("%s""PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
  149. prefix, aer_error_severity_string[info->severity],
  150. aer_error_layer[layer], id, aer_agent_string[agent]);
  151. printk("%s"" device [%04x:%04x] error status/mask=%08x/%08x\n",
  152. prefix, dev->vendor, dev->device,
  153. info->status, info->mask);
  154. __aer_print_error(prefix, info);
  155. if (info->tlp_header_valid) {
  156. unsigned char *tlp = (unsigned char *) &info->tlp;
  157. printk("%s"" TLP Header:"
  158. " %02x%02x%02x%02x %02x%02x%02x%02x"
  159. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  160. prefix, *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  161. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  162. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  163. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  164. *(tlp + 13), *(tlp + 12));
  165. }
  166. }
  167. if (info->id && info->error_dev_num > 1 && info->id == id)
  168. printk("%s"" Error of this Agent(%04x) is reported first\n",
  169. prefix, id);
  170. }
  171. void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
  172. {
  173. dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
  174. info->multi_error_valid ? "Multiple " : "",
  175. aer_error_severity_string[info->severity], info->id);
  176. }
  177. #ifdef CONFIG_ACPI_APEI_PCIEAER
  178. static int cper_severity_to_aer(int cper_severity)
  179. {
  180. switch (cper_severity) {
  181. case CPER_SEV_RECOVERABLE:
  182. return AER_NONFATAL;
  183. case CPER_SEV_FATAL:
  184. return AER_FATAL;
  185. default:
  186. return AER_CORRECTABLE;
  187. }
  188. }
  189. void cper_print_aer(const char *prefix, int cper_severity,
  190. struct aer_capability_regs *aer)
  191. {
  192. int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0;
  193. u32 status, mask;
  194. const char **status_strs;
  195. aer_severity = cper_severity_to_aer(cper_severity);
  196. if (aer_severity == AER_CORRECTABLE) {
  197. status = aer->cor_status;
  198. mask = aer->cor_mask;
  199. status_strs = aer_correctable_error_string;
  200. status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
  201. } else {
  202. status = aer->uncor_status;
  203. mask = aer->uncor_mask;
  204. status_strs = aer_uncorrectable_error_string;
  205. status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
  206. tlp_header_valid = status & AER_LOG_TLP_MASKS;
  207. }
  208. layer = AER_GET_LAYER_ERROR(aer_severity, status);
  209. agent = AER_GET_AGENT(aer_severity, status);
  210. printk("%s""aer_status: 0x%08x, aer_mask: 0x%08x\n",
  211. prefix, status, mask);
  212. cper_print_bits(prefix, status, status_strs, status_strs_size);
  213. printk("%s""aer_layer=%s, aer_agent=%s\n", prefix,
  214. aer_error_layer[layer], aer_agent_string[agent]);
  215. if (aer_severity != AER_CORRECTABLE)
  216. printk("%s""aer_uncor_severity: 0x%08x\n",
  217. prefix, aer->uncor_severity);
  218. if (tlp_header_valid) {
  219. const unsigned char *tlp;
  220. tlp = (const unsigned char *)&aer->header_log;
  221. printk("%s""aer_tlp_header:"
  222. " %02x%02x%02x%02x %02x%02x%02x%02x"
  223. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  224. prefix, *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  225. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  226. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  227. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  228. *(tlp + 13), *(tlp + 12));
  229. }
  230. }
  231. #endif