aerdrv_errprint.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 "aerdrv.h"
  22. #define AER_AGENT_RECEIVER 0
  23. #define AER_AGENT_REQUESTER 1
  24. #define AER_AGENT_COMPLETER 2
  25. #define AER_AGENT_TRANSMITTER 3
  26. #define AER_AGENT_REQUESTER_MASK(t) ((t == AER_CORRECTABLE) ? \
  27. 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP))
  28. #define AER_AGENT_COMPLETER_MASK(t) ((t == AER_CORRECTABLE) ? \
  29. 0 : PCI_ERR_UNC_COMP_ABORT)
  30. #define AER_AGENT_TRANSMITTER_MASK(t) ((t == AER_CORRECTABLE) ? \
  31. (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0)
  32. #define AER_GET_AGENT(t, e) \
  33. ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \
  34. (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \
  35. (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \
  36. AER_AGENT_RECEIVER)
  37. #define AER_PHYSICAL_LAYER_ERROR 0
  38. #define AER_DATA_LINK_LAYER_ERROR 1
  39. #define AER_TRANSACTION_LAYER_ERROR 2
  40. #define AER_PHYSICAL_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
  41. PCI_ERR_COR_RCVR : 0)
  42. #define AER_DATA_LINK_LAYER_ERROR_MASK(t) ((t == AER_CORRECTABLE) ? \
  43. (PCI_ERR_COR_BAD_TLP| \
  44. PCI_ERR_COR_BAD_DLLP| \
  45. PCI_ERR_COR_REP_ROLL| \
  46. PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP)
  47. #define AER_GET_LAYER_ERROR(t, e) \
  48. ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \
  49. (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \
  50. AER_TRANSACTION_LAYER_ERROR)
  51. /*
  52. * AER error strings
  53. */
  54. static const char *aer_error_severity_string[] = {
  55. "Uncorrected (Non-Fatal)",
  56. "Uncorrected (Fatal)",
  57. "Corrected"
  58. };
  59. static const char *aer_error_layer[] = {
  60. "Physical Layer",
  61. "Data Link Layer",
  62. "Transaction Layer"
  63. };
  64. static const char *aer_correctable_error_string[] = {
  65. "Receiver Error", /* Bit Position 0 */
  66. NULL,
  67. NULL,
  68. NULL,
  69. NULL,
  70. NULL,
  71. "Bad TLP", /* Bit Position 6 */
  72. "Bad DLLP", /* Bit Position 7 */
  73. "RELAY_NUM Rollover", /* Bit Position 8 */
  74. NULL,
  75. NULL,
  76. NULL,
  77. "Replay Timer Timeout", /* Bit Position 12 */
  78. "Advisory Non-Fatal", /* Bit Position 13 */
  79. };
  80. static const char *aer_uncorrectable_error_string[] = {
  81. NULL,
  82. NULL,
  83. NULL,
  84. NULL,
  85. "Data Link Protocol", /* Bit Position 4 */
  86. NULL,
  87. NULL,
  88. NULL,
  89. NULL,
  90. NULL,
  91. NULL,
  92. NULL,
  93. "Poisoned TLP", /* Bit Position 12 */
  94. "Flow Control Protocol", /* Bit Position 13 */
  95. "Completion Timeout", /* Bit Position 14 */
  96. "Completer Abort", /* Bit Position 15 */
  97. "Unexpected Completion", /* Bit Position 16 */
  98. "Receiver Overflow", /* Bit Position 17 */
  99. "Malformed TLP", /* Bit Position 18 */
  100. "ECRC", /* Bit Position 19 */
  101. "Unsupported Request", /* Bit Position 20 */
  102. };
  103. static const char *aer_agent_string[] = {
  104. "Receiver ID",
  105. "Requester ID",
  106. "Completer ID",
  107. "Transmitter ID"
  108. };
  109. static void __aer_print_error(const char *prefix,
  110. struct aer_err_info *info)
  111. {
  112. int i, status;
  113. const char *errmsg = NULL;
  114. status = (info->status & ~info->mask);
  115. for (i = 0; i < 32; i++) {
  116. if (!(status & (1 << i)))
  117. continue;
  118. if (info->severity == AER_CORRECTABLE)
  119. errmsg = i < ARRAY_SIZE(aer_correctable_error_string) ?
  120. aer_correctable_error_string[i] : NULL;
  121. else
  122. errmsg = i < ARRAY_SIZE(aer_uncorrectable_error_string) ?
  123. aer_uncorrectable_error_string[i] : NULL;
  124. if (errmsg)
  125. printk("%s"" [%2d] %-22s%s\n", prefix, i, errmsg,
  126. info->first_error == i ? " (First)" : "");
  127. else
  128. printk("%s"" [%2d] Unknown Error Bit%s\n", prefix, i,
  129. info->first_error == i ? " (First)" : "");
  130. }
  131. }
  132. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  133. {
  134. int id = ((dev->bus->number << 8) | dev->devfn);
  135. char prefix[44];
  136. snprintf(prefix, sizeof(prefix), "%s%s %s: ",
  137. (info->severity == AER_CORRECTABLE) ? KERN_WARNING : KERN_ERR,
  138. dev_driver_string(&dev->dev), dev_name(&dev->dev));
  139. if (info->status == 0) {
  140. printk("%s""PCIe Bus Error: severity=%s, type=Unaccessible, "
  141. "id=%04x(Unregistered Agent ID)\n", prefix,
  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. printk("%s""PCIe Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
  148. prefix, aer_error_severity_string[info->severity],
  149. aer_error_layer[layer], id, aer_agent_string[agent]);
  150. printk("%s"" device [%04x:%04x] error status/mask=%08x/%08x\n",
  151. prefix, dev->vendor, dev->device,
  152. info->status, info->mask);
  153. __aer_print_error(prefix, info);
  154. if (info->tlp_header_valid) {
  155. unsigned char *tlp = (unsigned char *) &info->tlp;
  156. printk("%s"" TLP Header:"
  157. " %02x%02x%02x%02x %02x%02x%02x%02x"
  158. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  159. prefix, *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  160. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  161. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  162. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  163. *(tlp + 13), *(tlp + 12));
  164. }
  165. }
  166. if (info->id && info->error_dev_num > 1 && info->id == id)
  167. printk("%s"" Error of this Agent(%04x) is reported first\n",
  168. prefix, id);
  169. }
  170. void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
  171. {
  172. dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
  173. info->multi_error_valid ? "Multiple " : "",
  174. aer_error_severity_string[info->severity], info->id);
  175. }