aerdrv_errprint.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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, fmt, args...) \
  52. printk("%s" fmt, (info->severity == AER_CORRECTABLE) ? \
  53. KERN_WARNING : KERN_ERR, ## args)
  54. /*
  55. * AER error strings
  56. */
  57. static char *aer_error_severity_string[] = {
  58. "Uncorrected (Non-Fatal)",
  59. "Uncorrected (Fatal)",
  60. "Corrected"
  61. };
  62. static char *aer_error_layer[] = {
  63. "Physical Layer",
  64. "Data Link Layer",
  65. "Transaction Layer"
  66. };
  67. static 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. NULL,
  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. };
  101. static char *aer_uncorrectable_error_string[] = {
  102. NULL,
  103. NULL,
  104. NULL,
  105. NULL,
  106. "Data Link Protocol ", /* Bit Position 4 */
  107. NULL,
  108. NULL,
  109. NULL,
  110. NULL,
  111. NULL,
  112. NULL,
  113. NULL,
  114. "Poisoned TLP ", /* Bit Position 12 */
  115. "Flow Control Protocol ", /* Bit Position 13 */
  116. "Completion Timeout ", /* Bit Position 14 */
  117. "Completer Abort ", /* Bit Position 15 */
  118. "Unexpected Completion ", /* Bit Position 16 */
  119. "Receiver Overflow ", /* Bit Position 17 */
  120. "Malformed TLP ", /* Bit Position 18 */
  121. "ECRC ", /* Bit Position 19 */
  122. "Unsupported Request ", /* Bit Position 20 */
  123. NULL,
  124. NULL,
  125. NULL,
  126. NULL,
  127. NULL,
  128. NULL,
  129. NULL,
  130. NULL,
  131. NULL,
  132. NULL,
  133. NULL,
  134. };
  135. static char *aer_agent_string[] = {
  136. "Receiver ID",
  137. "Requester ID",
  138. "Completer ID",
  139. "Transmitter ID"
  140. };
  141. static char *aer_get_error_source_name(int severity,
  142. unsigned int status,
  143. char errmsg_buff[])
  144. {
  145. int i;
  146. char *errmsg = NULL;
  147. for (i = 0; i < 32; i++) {
  148. if (!(status & (1 << i)))
  149. continue;
  150. if (severity == AER_CORRECTABLE)
  151. errmsg = aer_correctable_error_string[i];
  152. else
  153. errmsg = aer_uncorrectable_error_string[i];
  154. if (!errmsg) {
  155. sprintf(errmsg_buff, "Unknown Error Bit %2d ", i);
  156. errmsg = errmsg_buff;
  157. }
  158. break;
  159. }
  160. return errmsg;
  161. }
  162. static DEFINE_SPINLOCK(logbuf_lock);
  163. static char errmsg_buff[100];
  164. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  165. {
  166. char *errmsg;
  167. int err_layer, agent;
  168. int id = ((dev->bus->number << 8) | dev->devfn);
  169. AER_PR(info, "+------ PCI-Express Device Error ------+\n");
  170. AER_PR(info, "Error Severity\t\t: %s\n",
  171. aer_error_severity_string[info->severity]);
  172. if (info->status == 0) {
  173. AER_PR(info, "PCIE Bus Error type\t: (Unaccessible)\n");
  174. AER_PR(info, "Unregistered Agent ID\t: %04x\n", id);
  175. } else {
  176. err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
  177. AER_PR(info, "PCIE Bus Error type\t: %s\n",
  178. aer_error_layer[err_layer]);
  179. spin_lock(&logbuf_lock);
  180. errmsg = aer_get_error_source_name(info->severity,
  181. info->status,
  182. errmsg_buff);
  183. AER_PR(info, "%s\t:\n", errmsg);
  184. spin_unlock(&logbuf_lock);
  185. agent = AER_GET_AGENT(info->severity, info->status);
  186. AER_PR(info, "%s\t\t: %04x\n", aer_agent_string[agent], id);
  187. AER_PR(info, "VendorID=%04xh, DeviceID=%04xh,"
  188. " Bus=%02xh, Device=%02xh, Function=%02xh\n",
  189. dev->vendor,
  190. dev->device,
  191. dev->bus->number,
  192. PCI_SLOT(dev->devfn),
  193. PCI_FUNC(dev->devfn));
  194. if (info->flags & AER_TLP_HEADER_VALID_FLAG) {
  195. unsigned char *tlp = (unsigned char *) &info->tlp;
  196. AER_PR(info, "TLP Header:\n");
  197. AER_PR(info, "%02x%02x%02x%02x %02x%02x%02x%02x"
  198. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  199. *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  200. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  201. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  202. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  203. *(tlp + 13), *(tlp + 12));
  204. }
  205. }
  206. if (info->id && info->error_dev_num > 1 && info->id == id)
  207. AER_PR(info, "Error of this Agent(%04x) is reported first\n",
  208. id);
  209. }