aerdrv_errprint.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. #define AER_PR(info, pdev, fmt, args...) \
  52. printk("%s%s %s: " fmt, (info->severity == AER_CORRECTABLE) ? \
  53. KERN_WARNING : KERN_ERR, dev_driver_string(&pdev->dev), \
  54. dev_name(&pdev->dev), ## args)
  55. /*
  56. * AER error strings
  57. */
  58. static char *aer_error_severity_string[] = {
  59. "Uncorrected (Non-Fatal)",
  60. "Uncorrected (Fatal)",
  61. "Corrected"
  62. };
  63. static char *aer_error_layer[] = {
  64. "Physical Layer",
  65. "Data Link Layer",
  66. "Transaction Layer"
  67. };
  68. static char *aer_correctable_error_string[] = {
  69. "Receiver Error ", /* Bit Position 0 */
  70. NULL,
  71. NULL,
  72. NULL,
  73. NULL,
  74. NULL,
  75. "Bad TLP ", /* Bit Position 6 */
  76. "Bad DLLP ", /* Bit Position 7 */
  77. "RELAY_NUM Rollover ", /* Bit Position 8 */
  78. NULL,
  79. NULL,
  80. NULL,
  81. "Replay Timer Timeout ", /* Bit Position 12 */
  82. "Advisory Non-Fatal ", /* Bit Position 13 */
  83. NULL,
  84. NULL,
  85. NULL,
  86. NULL,
  87. NULL,
  88. NULL,
  89. NULL,
  90. NULL,
  91. NULL,
  92. NULL,
  93. NULL,
  94. NULL,
  95. NULL,
  96. NULL,
  97. NULL,
  98. NULL,
  99. NULL,
  100. NULL,
  101. };
  102. static char *aer_uncorrectable_error_string[] = {
  103. NULL,
  104. NULL,
  105. NULL,
  106. NULL,
  107. "Data Link Protocol ", /* Bit Position 4 */
  108. NULL,
  109. NULL,
  110. NULL,
  111. NULL,
  112. NULL,
  113. NULL,
  114. NULL,
  115. "Poisoned TLP ", /* Bit Position 12 */
  116. "Flow Control Protocol ", /* Bit Position 13 */
  117. "Completion Timeout ", /* Bit Position 14 */
  118. "Completer Abort ", /* Bit Position 15 */
  119. "Unexpected Completion ", /* Bit Position 16 */
  120. "Receiver Overflow ", /* Bit Position 17 */
  121. "Malformed TLP ", /* Bit Position 18 */
  122. "ECRC ", /* Bit Position 19 */
  123. "Unsupported Request ", /* Bit Position 20 */
  124. NULL,
  125. NULL,
  126. NULL,
  127. NULL,
  128. NULL,
  129. NULL,
  130. NULL,
  131. NULL,
  132. NULL,
  133. NULL,
  134. NULL,
  135. };
  136. static char *aer_agent_string[] = {
  137. "Receiver ID",
  138. "Requester ID",
  139. "Completer ID",
  140. "Transmitter ID"
  141. };
  142. static void __aer_print_error(struct aer_err_info *info, struct pci_dev *dev)
  143. {
  144. int i, status;
  145. char *errmsg = NULL;
  146. status = (info->status & ~info->mask);
  147. for (i = 0; i < 32; i++) {
  148. if (!(status & (1 << i)))
  149. continue;
  150. if (info->severity == AER_CORRECTABLE)
  151. errmsg = aer_correctable_error_string[i];
  152. else
  153. errmsg = aer_uncorrectable_error_string[i];
  154. if (errmsg)
  155. AER_PR(info, dev, " [%2d] %s%s\n", i, errmsg,
  156. info->first_error == i ? " (First)" : "");
  157. else
  158. AER_PR(info, dev, " [%2d] Unknown Error Bit%s\n", i,
  159. info->first_error == i ? " (First)" : "");
  160. }
  161. }
  162. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  163. {
  164. int id = ((dev->bus->number << 8) | dev->devfn);
  165. if (info->status == 0) {
  166. AER_PR(info, dev,
  167. "PCIE Bus Error: severity=%s, type=Unaccessible, "
  168. "id=%04x(Unregistered Agent ID)\n",
  169. aer_error_severity_string[info->severity], id);
  170. } else {
  171. int layer, agent;
  172. layer = AER_GET_LAYER_ERROR(info->severity, info->status);
  173. agent = AER_GET_AGENT(info->severity, info->status);
  174. AER_PR(info, dev,
  175. "PCIE Bus Error: severity=%s, type=%s, id=%04x(%s)\n",
  176. aer_error_severity_string[info->severity],
  177. aer_error_layer[layer], id, aer_agent_string[agent]);
  178. AER_PR(info, dev,
  179. " device [%04x:%04x] error status/mask=%08x/%08x\n",
  180. dev->vendor, dev->device, info->status, info->mask);
  181. __aer_print_error(info, dev);
  182. if (info->tlp_header_valid) {
  183. unsigned char *tlp = (unsigned char *) &info->tlp;
  184. AER_PR(info, dev, " TLP Header:"
  185. " %02x%02x%02x%02x %02x%02x%02x%02x"
  186. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  187. *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  188. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  189. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  190. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  191. *(tlp + 13), *(tlp + 12));
  192. }
  193. }
  194. if (info->id && info->error_dev_num > 1 && info->id == id)
  195. AER_PR(info, dev,
  196. " Error of this Agent(%04x) is reported first\n", id);
  197. }
  198. void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info)
  199. {
  200. dev_info(&dev->dev, "AER: %s%s error received: id=%04x\n",
  201. info->multi_error_valid ? "Multiple " : "",
  202. aer_error_severity_string[info->severity], info->id);
  203. }