aerdrv_errprint.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 (PCI_ERR_UNC_COMP_TIME| \
  27. PCI_ERR_UNC_UNSUP)
  28. #define AER_AGENT_COMPLETER_MASK PCI_ERR_UNC_COMP_ABORT
  29. #define AER_AGENT_TRANSMITTER_MASK(t, e) (e & (PCI_ERR_COR_REP_ROLL| \
  30. ((t == AER_CORRECTABLE) ? PCI_ERR_COR_REP_TIMER : 0)))
  31. #define AER_GET_AGENT(t, e) \
  32. ((e & AER_AGENT_COMPLETER_MASK) ? AER_AGENT_COMPLETER : \
  33. (e & AER_AGENT_REQUESTER_MASK) ? AER_AGENT_REQUESTER : \
  34. (AER_AGENT_TRANSMITTER_MASK(t, e)) ? AER_AGENT_TRANSMITTER : \
  35. AER_AGENT_RECEIVER)
  36. #define AER_PHYSICAL_LAYER_ERROR_MASK PCI_ERR_COR_RCVR
  37. #define AER_DATA_LINK_LAYER_ERROR_MASK(t, e) \
  38. (PCI_ERR_UNC_DLP| \
  39. PCI_ERR_COR_BAD_TLP| \
  40. PCI_ERR_COR_BAD_DLLP| \
  41. PCI_ERR_COR_REP_ROLL| \
  42. ((t == AER_CORRECTABLE) ? \
  43. PCI_ERR_COR_REP_TIMER : 0))
  44. #define AER_PHYSICAL_LAYER_ERROR 0
  45. #define AER_DATA_LINK_LAYER_ERROR 1
  46. #define AER_TRANSACTION_LAYER_ERROR 2
  47. #define AER_GET_LAYER_ERROR(t, e) \
  48. ((e & AER_PHYSICAL_LAYER_ERROR_MASK) ? \
  49. AER_PHYSICAL_LAYER_ERROR : \
  50. (e & AER_DATA_LINK_LAYER_ERROR_MASK(t, e)) ? \
  51. AER_DATA_LINK_LAYER_ERROR : \
  52. AER_TRANSACTION_LAYER_ERROR)
  53. #define AER_PR(info, fmt, args...) \
  54. printk("%s" fmt, (info->severity == AER_CORRECTABLE) ? \
  55. KERN_WARNING : KERN_ERR, ## args)
  56. /*
  57. * AER error strings
  58. */
  59. static char *aer_error_severity_string[] = {
  60. "Uncorrected (Non-Fatal)",
  61. "Uncorrected (Fatal)",
  62. "Corrected"
  63. };
  64. static char *aer_error_layer[] = {
  65. "Physical Layer",
  66. "Data Link Layer",
  67. "Transaction Layer"
  68. };
  69. static char *aer_correctable_error_string[] = {
  70. "Receiver Error ", /* Bit Position 0 */
  71. NULL,
  72. NULL,
  73. NULL,
  74. NULL,
  75. NULL,
  76. "Bad TLP ", /* Bit Position 6 */
  77. "Bad DLLP ", /* Bit Position 7 */
  78. "RELAY_NUM Rollover ", /* Bit Position 8 */
  79. NULL,
  80. NULL,
  81. NULL,
  82. "Replay Timer Timeout ", /* Bit Position 12 */
  83. "Advisory Non-Fatal ", /* Bit Position 13 */
  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. NULL,
  102. };
  103. static char *aer_uncorrectable_error_string[] = {
  104. NULL,
  105. NULL,
  106. NULL,
  107. NULL,
  108. "Data Link Protocol ", /* Bit Position 4 */
  109. NULL,
  110. NULL,
  111. NULL,
  112. NULL,
  113. NULL,
  114. NULL,
  115. NULL,
  116. "Poisoned TLP ", /* Bit Position 12 */
  117. "Flow Control Protocol ", /* Bit Position 13 */
  118. "Completion Timeout ", /* Bit Position 14 */
  119. "Completer Abort ", /* Bit Position 15 */
  120. "Unexpected Completion ", /* Bit Position 16 */
  121. "Receiver Overflow ", /* Bit Position 17 */
  122. "Malformed TLP ", /* Bit Position 18 */
  123. "ECRC ", /* Bit Position 19 */
  124. "Unsupported Request ", /* Bit Position 20 */
  125. NULL,
  126. NULL,
  127. NULL,
  128. NULL,
  129. NULL,
  130. NULL,
  131. NULL,
  132. NULL,
  133. NULL,
  134. NULL,
  135. NULL,
  136. };
  137. static char *aer_agent_string[] = {
  138. "Receiver ID",
  139. "Requester ID",
  140. "Completer ID",
  141. "Transmitter ID"
  142. };
  143. static char *aer_get_error_source_name(int severity,
  144. unsigned int status,
  145. char errmsg_buff[])
  146. {
  147. int i;
  148. char *errmsg = NULL;
  149. for (i = 0; i < 32; i++) {
  150. if (!(status & (1 << i)))
  151. continue;
  152. if (severity == AER_CORRECTABLE)
  153. errmsg = aer_correctable_error_string[i];
  154. else
  155. errmsg = aer_uncorrectable_error_string[i];
  156. if (!errmsg) {
  157. sprintf(errmsg_buff, "Unknown Error Bit %2d ", i);
  158. errmsg = errmsg_buff;
  159. }
  160. break;
  161. }
  162. return errmsg;
  163. }
  164. static DEFINE_SPINLOCK(logbuf_lock);
  165. static char errmsg_buff[100];
  166. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)
  167. {
  168. char *errmsg;
  169. int err_layer, agent;
  170. AER_PR(info, "+------ PCI-Express Device Error ------+\n");
  171. AER_PR(info, "Error Severity\t\t: %s\n",
  172. aer_error_severity_string[info->severity]);
  173. if (info->status == 0) {
  174. AER_PR(info, "PCIE Bus Error type\t: (Unaccessible)\n");
  175. AER_PR(info, "Unaccessible Received\t: %s\n",
  176. info->flags & AER_MULTI_ERROR_VALID_FLAG ?
  177. "Multiple" : "First");
  178. AER_PR(info, "Unregistered Agent ID\t: %04x\n",
  179. (dev->bus->number << 8) | dev->devfn);
  180. } else {
  181. err_layer = AER_GET_LAYER_ERROR(info->severity, info->status);
  182. AER_PR(info, "PCIE Bus Error type\t: %s\n",
  183. aer_error_layer[err_layer]);
  184. spin_lock(&logbuf_lock);
  185. errmsg = aer_get_error_source_name(info->severity,
  186. info->status,
  187. errmsg_buff);
  188. AER_PR(info, "%s\t: %s\n", errmsg,
  189. info->flags & AER_MULTI_ERROR_VALID_FLAG ?
  190. "Multiple" : "First");
  191. spin_unlock(&logbuf_lock);
  192. agent = AER_GET_AGENT(info->severity, info->status);
  193. AER_PR(info, "%s\t\t: %04x\n",
  194. aer_agent_string[agent],
  195. (dev->bus->number << 8) | dev->devfn);
  196. AER_PR(info, "VendorID=%04xh, DeviceID=%04xh,"
  197. " Bus=%02xh, Device=%02xh, Function=%02xh\n",
  198. dev->vendor,
  199. dev->device,
  200. dev->bus->number,
  201. PCI_SLOT(dev->devfn),
  202. PCI_FUNC(dev->devfn));
  203. if (info->flags & AER_TLP_HEADER_VALID_FLAG) {
  204. unsigned char *tlp = (unsigned char *) &info->tlp;
  205. AER_PR(info, "TLP Header:\n");
  206. AER_PR(info, "%02x%02x%02x%02x %02x%02x%02x%02x"
  207. " %02x%02x%02x%02x %02x%02x%02x%02x\n",
  208. *(tlp + 3), *(tlp + 2), *(tlp + 1), *tlp,
  209. *(tlp + 7), *(tlp + 6), *(tlp + 5), *(tlp + 4),
  210. *(tlp + 11), *(tlp + 10), *(tlp + 9),
  211. *(tlp + 8), *(tlp + 15), *(tlp + 14),
  212. *(tlp + 13), *(tlp + 12));
  213. }
  214. }
  215. }