aerdrv.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 AER_NONFATAL 0
  14. #define AER_FATAL 1
  15. #define AER_CORRECTABLE 2
  16. #define SYSTEM_ERROR_INTR_ON_MESG_MASK (PCI_EXP_RTCTL_SECEE| \
  17. PCI_EXP_RTCTL_SENFEE| \
  18. PCI_EXP_RTCTL_SEFEE)
  19. #define ROOT_PORT_INTR_ON_MESG_MASK (PCI_ERR_ROOT_CMD_COR_EN| \
  20. PCI_ERR_ROOT_CMD_NONFATAL_EN| \
  21. PCI_ERR_ROOT_CMD_FATAL_EN)
  22. #define ERR_COR_ID(d) (d & 0xffff)
  23. #define ERR_UNCOR_ID(d) (d >> 16)
  24. #define AER_ERROR_SOURCES_MAX 100
  25. #define AER_LOG_TLP_MASKS (PCI_ERR_UNC_POISON_TLP| \
  26. PCI_ERR_UNC_ECRC| \
  27. PCI_ERR_UNC_UNSUP| \
  28. PCI_ERR_UNC_COMP_ABORT| \
  29. PCI_ERR_UNC_UNX_COMP| \
  30. PCI_ERR_UNC_MALF_TLP)
  31. struct header_log_regs {
  32. unsigned int dw0;
  33. unsigned int dw1;
  34. unsigned int dw2;
  35. unsigned int dw3;
  36. };
  37. #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
  38. struct aer_err_info {
  39. struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
  40. int error_dev_num;
  41. unsigned int id:16;
  42. unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
  43. unsigned int __pad1:5;
  44. unsigned int multi_error_valid:1;
  45. unsigned int first_error:5;
  46. unsigned int __pad2:2;
  47. unsigned int tlp_header_valid:1;
  48. unsigned int status; /* COR/UNCOR Error Status */
  49. unsigned int mask; /* COR/UNCOR Error Mask */
  50. struct header_log_regs tlp; /* TLP Header */
  51. };
  52. struct aer_err_source {
  53. unsigned int status;
  54. unsigned int id;
  55. };
  56. struct aer_rpc {
  57. struct pcie_device *rpd; /* Root Port device */
  58. struct work_struct dpc_handler;
  59. struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
  60. unsigned short prod_idx; /* Error Producer Index */
  61. unsigned short cons_idx; /* Error Consumer Index */
  62. int isr;
  63. spinlock_t e_lock; /*
  64. * Lock access to Error Status/ID Regs
  65. * and error producer/consumer index
  66. */
  67. struct mutex rpc_mutex; /*
  68. * only one thread could do
  69. * recovery on the same
  70. * root port hierarchy
  71. */
  72. wait_queue_head_t wait_release;
  73. };
  74. struct aer_broadcast_data {
  75. enum pci_channel_state state;
  76. enum pci_ers_result result;
  77. };
  78. static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
  79. enum pci_ers_result new)
  80. {
  81. if (new == PCI_ERS_RESULT_NONE)
  82. return orig;
  83. switch (orig) {
  84. case PCI_ERS_RESULT_CAN_RECOVER:
  85. case PCI_ERS_RESULT_RECOVERED:
  86. orig = new;
  87. break;
  88. case PCI_ERS_RESULT_DISCONNECT:
  89. if (new == PCI_ERS_RESULT_NEED_RESET)
  90. orig = new;
  91. break;
  92. default:
  93. break;
  94. }
  95. return orig;
  96. }
  97. extern struct bus_type pcie_port_bus_type;
  98. extern void aer_do_secondary_bus_reset(struct pci_dev *dev);
  99. extern int aer_init(struct pcie_device *dev);
  100. extern void aer_isr(struct work_struct *work);
  101. extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
  102. extern void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info);
  103. extern irqreturn_t aer_irq(int irq, void *context);
  104. #ifdef CONFIG_ACPI
  105. extern int aer_osc_setup(struct pcie_device *pciedev);
  106. #else
  107. static inline int aer_osc_setup(struct pcie_device *pciedev)
  108. {
  109. return 0;
  110. }
  111. #endif
  112. #ifdef CONFIG_ACPI_APEI
  113. extern int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
  114. #else
  115. static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
  116. {
  117. if (pci_dev->__aer_firmware_first_valid)
  118. return pci_dev->__aer_firmware_first;
  119. return 0;
  120. }
  121. #endif
  122. static inline void pcie_aer_force_firmware_first(struct pci_dev *pci_dev,
  123. int enable)
  124. {
  125. pci_dev->__aer_firmware_first = !!enable;
  126. pci_dev->__aer_firmware_first_valid = 1;
  127. }
  128. #endif /* _AERDRV_H_ */