aerdrv.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
  32. struct aer_err_info {
  33. struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
  34. int error_dev_num;
  35. unsigned int id:16;
  36. unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
  37. unsigned int __pad1:5;
  38. unsigned int multi_error_valid:1;
  39. unsigned int first_error:5;
  40. unsigned int __pad2:2;
  41. unsigned int tlp_header_valid:1;
  42. unsigned int status; /* COR/UNCOR Error Status */
  43. unsigned int mask; /* COR/UNCOR Error Mask */
  44. struct aer_header_log_regs tlp; /* TLP Header */
  45. };
  46. struct aer_err_source {
  47. unsigned int status;
  48. unsigned int id;
  49. };
  50. struct aer_rpc {
  51. struct pcie_device *rpd; /* Root Port device */
  52. struct work_struct dpc_handler;
  53. struct aer_err_source e_sources[AER_ERROR_SOURCES_MAX];
  54. unsigned short prod_idx; /* Error Producer Index */
  55. unsigned short cons_idx; /* Error Consumer Index */
  56. int isr;
  57. spinlock_t e_lock; /*
  58. * Lock access to Error Status/ID Regs
  59. * and error producer/consumer index
  60. */
  61. struct mutex rpc_mutex; /*
  62. * only one thread could do
  63. * recovery on the same
  64. * root port hierarchy
  65. */
  66. wait_queue_head_t wait_release;
  67. };
  68. struct aer_broadcast_data {
  69. enum pci_channel_state state;
  70. enum pci_ers_result result;
  71. };
  72. static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
  73. enum pci_ers_result new)
  74. {
  75. if (new == PCI_ERS_RESULT_NONE)
  76. return orig;
  77. switch (orig) {
  78. case PCI_ERS_RESULT_CAN_RECOVER:
  79. case PCI_ERS_RESULT_RECOVERED:
  80. orig = new;
  81. break;
  82. case PCI_ERS_RESULT_DISCONNECT:
  83. if (new == PCI_ERS_RESULT_NEED_RESET)
  84. orig = new;
  85. break;
  86. default:
  87. break;
  88. }
  89. return orig;
  90. }
  91. extern struct bus_type pcie_port_bus_type;
  92. extern void aer_do_secondary_bus_reset(struct pci_dev *dev);
  93. extern int aer_init(struct pcie_device *dev);
  94. extern void aer_isr(struct work_struct *work);
  95. extern void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
  96. extern void aer_print_port_info(struct pci_dev *dev, struct aer_err_info *info);
  97. extern irqreturn_t aer_irq(int irq, void *context);
  98. #ifdef CONFIG_ACPI_APEI
  99. extern int pcie_aer_get_firmware_first(struct pci_dev *pci_dev);
  100. #else
  101. static inline int pcie_aer_get_firmware_first(struct pci_dev *pci_dev)
  102. {
  103. if (pci_dev->__aer_firmware_first_valid)
  104. return pci_dev->__aer_firmware_first;
  105. return 0;
  106. }
  107. #endif
  108. static inline void pcie_aer_force_firmware_first(struct pci_dev *pci_dev,
  109. int enable)
  110. {
  111. pci_dev->__aer_firmware_first = !!enable;
  112. pci_dev->__aer_firmware_first_valid = 1;
  113. }
  114. #endif /* _AERDRV_H_ */