aerdrv_errprint.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 __aer_print_error(struct pci_dev *dev,
  113. struct aer_err_info *info)
  114. {
  115. int i, status;
  116. const char *errmsg = NULL;
  117. status = (info->status & ~info->mask);
  118. for (i = 0; i < 32; i++) {
  119. if (!(status & (1 << i)))
  120. continue;
  121. if (info->severity == AER_CORRECTABLE)
  122. errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
  123. aer_correctable_error_string[i] : NULL;
  124. else
  125. errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
  126. aer_uncorrectable_error_string[i] : NULL;
  127. if (errmsg)
  128. dev_err(&dev->dev, " [%2d] %-22s%s\n", i, errmsg,
  129. info->first_error == i ? " (First)" : "");
  130. else
  131. dev_err(&dev->dev, " [%2d] Unknown Error Bit%s\n",
  132. i, info->first_error == i ? " (First)" : "");
  133. }
  134. }
  135. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  136. {
  137. int id = ((dev->bus->number << 8) | dev->devfn);
  138. if (info->status == 0) {
  139. dev_err(&dev->dev,
  140. "PCIe Bus Error: severity=%s, type=Unaccessible, "
  141. "id=%04x(Unregistered Agent ID)\n",
  142. aer_error_severity_string[info->severity], id);
  143. } else {
  144. int layer, agent;
  145. layer = AER_GET_LAYER_ERROR(info->severity, info->status);
  146. agent = AER_GET_AGENT(info->severity, info->status);
  147. dev_err(&dev->dev,
  148. "PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
  149. aer_error_severity_string[info->severity],
  150. aer_error_layer[layer], id, aer_agent_string[agent]);
  151. dev_err(&dev->dev,
  152. " device [%04x:%04x] error status/mask=%08x/%08x\n",
  153. dev->vendor, dev->device,
  154. info->status, info->mask);
  155. __aer_print_error(dev, info);
  156. if (info->tlp_header_valid) {
  157. unsigned char *tlp = (unsigned char *) &info->tlp;
  158. dev_err(&dev->dev, " TLP Header:"
  159. " %02x%02x%02x%02x %02x%02x%02x%02x"
  160. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  161. *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  162. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  163. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  164. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  165. *(tlp + 13), *(tlp + 12));
  166. }
  167. }
  168. if (info->id && info->error_dev_num > 1 && info->id == id)
  169. dev_err(&dev->dev,
  170. " Error of this Agent(%04x) is reported first\n",
  171. id);
  172. trace_aer_event(dev_name(&dev->dev), (info->status & ~info->mask),
  173. info->severity);
  174. }
  175. void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
  176. {
  177. dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
  178. info->multi_error_valid ? "Multiple " : "",
  179. aer_error_severity_string[info->severity], info->id);
  180. }
  181. #ifdef CONFIG_ACPI_APEI_PCIEAER
  182. int cper_severity_to_aer(int cper_severity)
  183. {
  184. switch (cper_severity) {
  185. case CPER_SEV_RECOVERABLE:
  186. return AER_NONFATAL;
  187. case CPER_SEV_FATAL:
  188. return AER_FATAL;
  189. default:
  190. return AER_CORRECTABLE;
  191. }
  192. }
  193. EXPORT_SYMBOL_GPL(cper_severity_to_aer);
  194. void cper_print_aer(const char *prefix, struct pci_dev *dev, int cper_severity,
  195. struct aer_capability_regs *aer)
  196. {
  197. int aer_severity, layer, agent, status_strs_size, tlp_header_valid = 0;
  198. u32 status, mask;
  199. const char **status_strs;
  200. aer_severity = cper_severity_to_aer(cper_severity);
  201. if (aer_severity == AER_CORRECTABLE) {
  202. status = aer->cor_status;
  203. mask = aer->cor_mask;
  204. status_strs = aer_correctable_error_string;
  205. status_strs_size = ARRAY_SIZE(aer_correctable_error_string);
  206. } else {
  207. status = aer->uncor_status;
  208. mask = aer->uncor_mask;
  209. status_strs = aer_uncorrectable_error_string;
  210. status_strs_size = ARRAY_SIZE(aer_uncorrectable_error_string);
  211. tlp_header_valid = status & AER_LOG_TLP_MASKS;
  212. }
  213. layer = AER_GET_LAYER_ERROR(aer_severity, status);
  214. agent = AER_GET_AGENT(aer_severity, status);
  215. dev_err(&dev->dev, "aer_status: 0x%08x, aer_mask: 0x%08x\n",
  216. status, mask);
  217. cper_print_bits(prefix, status, status_strs, status_strs_size);
  218. dev_err(&dev->dev, "aer_layer=%s, aer_agent=%s\n",
  219. aer_error_layer[layer], aer_agent_string[agent]);
  220. if (aer_severity != AER_CORRECTABLE)
  221. dev_err(&dev->dev, "aer_uncor_severity: 0x%08x\n",
  222. aer->uncor_severity);
  223. if (tlp_header_valid) {
  224. const unsigned char *tlp;
  225. tlp = (const unsigned char *)&aer->header_log;
  226. dev_err(&dev->dev, "aer_tlp_header:"
  227. " %02x%02x%02x%02x %02x%02x%02x%02x"
  228. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  229. *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  230. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  231. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  232. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  233. *(tlp + 13), *(tlp + 12));
  234. }
  235. trace_aer_event(dev_name(&dev->dev), (status & ~mask),
  236. aer_severity);
  237. }
  238. #endif