aerdrv.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2006 Intel Corp.
  3. * Tom Long Nguyen (tom.l.nguyen@intel.com)
  4. * Zhang Yanmin (yanmin.zhang@intel.com)
  5. *
  6. */
  7. #ifndef _AERDRV_H_
  8. #define _AERDRV_H_
  9. #include <linux/workqueue.h>
  10. #include <linux/pcieport_if.h>
  11. #include <linux/aer.h>
  12. #include <linux/interrupt.h>
  13. #define SYSTEM_ERROR_INTR_ON_MESG_MASK (PCI_EXP_RTCTL_SECEE| \
  14. PCI_EXP_RTCTL_SENFEE| \
  15. PCI_EXP_RTCTL_SEFEE)
  16. #define ROOT_PORT_INTR_ON_MESG_MASK (PCI_ERR_ROOT_CMD_COR_EN| \
  17. PCI_ERR_ROOT_CMD_NONFATAL_EN| \
  18. PCI_ERR_ROOT_CMD_FATAL_EN)
  19. #define ERR_COR_ID(d) (d & 0xffff)
  20. #define ERR_UNCOR_ID(d) (d >> 16)
  21. #define AER_ERROR_SOURCES_MAX 100
  22. #define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \
  23. PCI_ERR_UNC_ECRC| \
  24. PCI_ERR_UNC_UNSUP| \
  25. PCI_ERR_UNC_COMP_ABORT| \
  26. PCI_ERR_UNC_UNX_COMP| \
  27. PCI_ERR_UNC_MALF_TLP)
  28. #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
  29. struct aer_err_info {
  30. struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
  31. int error_dev_num;
  32. unsigned int id:16;
  33. unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
  34. unsigned int __pad1:5;
  35. unsigned int multi_error_valid:1;
  36. unsigned int first_error:5;
  37. unsigned int __pad2:2;
  38. unsigned int tlp_header_valid:1;
  39. unsigned int status; /* COR/UNCOR Error Status */
  40. unsigned int mask; /* COR/UNCOR Error Mask */
  41. struct aer_header_log_regs tlp; /* TLP Header */
  42. };
  43. struct aer_err_source {
  44. unsigned int status;
  45. unsigned int id;
  46. };
  47. struct aer_rpc {
  48. struct pcie_device *rpd; /* Root Port device */
  49. struct work_struct dpc_handler;
  50. struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
  51. unsigned short prod_idx; /* Error Producer Index */
  52. unsigned short cons_idx; /* Error Consumer Index */
  53. int isr;
  54. spinlock_t e_lock; /*
  55. * Lock access to Error Status/ID Regs
  56. * and error producer/consumer index
  57. */
  58. struct mutex rpc_mutex; /*
  59. * only one thread could do
  60. * recovery on the same
  61. * root port hierarchy
  62. */
  63. };
  64. struct aer_broadcast_data {
  65. enum pci_channel_state state;
  66. enum pci_ers_result result;
  67. };
  68. static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
  69. enum pci_ers_result new)
  70. {
  71. if (new == PCI_ERS_RESULT_NO_AER_DRIVER)
  72. return PCI_ERS_RESULT_NO_AER_DRIVER;
  73. if (new == PCI_ERS_RESULT_NONE)
  74. return orig;
  75. switch (orig) {
  76. case PCI_ERS_RESULT_CAN_RECOVER:
  77. case PCI_ERS_RESULT_RECOVERED:
  78. orig = new;
  79. break;
  80. case PCI_ERS_RESULT_DISCONNECT:
  81. if (new == PCI_ERS_RESULT_NEED_RESET)
  82. orig = PCI_ERS_RESULT_NEED_RESET;
  83. break;
  84. default:
  85. break;
  86. }
  87. return orig;
  88. }
  89. extern struct bus_type pcie_port_bus_type;
  90. int aer_init(struct pcie_device *dev);
  91. void aer_isr(struct work_struct *work);
  92. void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
  93. void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info);
  94. irqreturn_t aer_irq(int irq, void *context);
  95. #ifdef CONFIG_ACPI_APEI
  96. int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
  97. #else
  98. static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
  99. {
  100. if (pci_dev->__aer_firmware_first_valid)
  101. return pci_dev->__aer_firmware_first;
  102. return 0;
  103. }
  104. #endif
  105. static inline void pcie_aer_force_firmware_first(struct pci_dev *pci_dev,
  106. int enable)
  107. {
  108. pci_dev->__aer_firmware_first = !!enable;
  109. pci_dev->__aer_firmware_first_valid = 1;
  110. }
  111. #endif /* _AERDRV_H_ */