aerdrv_errprint.c 7.2 KB

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