event.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright(c) 2023 Intel Corporation. */
  3. #ifndef _LINUX_CXL_EVENT_H
  4. #define _LINUX_CXL_EVENT_H
  5. #include <linux/types.h>
  6. #include <linux/uuid.h>
  7. #include <linux/workqueue_types.h>
  8. /*
  9. * Common Event Record Format
  10. * CXL rev 3.0 section 8.2.9.2.1; Table 8-42
  11. */
  12. struct cxl_event_record_hdr {
  13. u8 length;
  14. u8 flags[3];
  15. __le16 handle;
  16. __le16 related_handle;
  17. __le64 timestamp;
  18. u8 maint_op_class;
  19. u8 reserved[15];
  20. } __packed;
  21. struct cxl_event_media_hdr {
  22. struct cxl_event_record_hdr hdr;
  23. __le64 phys_addr;
  24. u8 descriptor;
  25. u8 type;
  26. u8 transaction_type;
  27. /*
  28. * The meaning of Validity Flags from bit 2 is
  29. * different across DRAM and General Media records
  30. */
  31. u8 validity_flags[2];
  32. u8 channel;
  33. u8 rank;
  34. } __packed;
  35. #define CXL_EVENT_RECORD_DATA_LENGTH 0x50
  36. struct cxl_event_generic {
  37. struct cxl_event_record_hdr hdr;
  38. u8 data[CXL_EVENT_RECORD_DATA_LENGTH];
  39. } __packed;
  40. /*
  41. * General Media Event Record
  42. * CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
  43. */
  44. #define CXL_EVENT_GEN_MED_COMP_ID_SIZE 0x10
  45. struct cxl_event_gen_media {
  46. struct cxl_event_media_hdr media_hdr;
  47. u8 device[3];
  48. u8 component_id[CXL_EVENT_GEN_MED_COMP_ID_SIZE];
  49. u8 reserved[46];
  50. } __packed;
  51. /*
  52. * DRAM Event Record - DER
  53. * CXL rev 3.0 section 8.2.9.2.1.2; Table 3-44
  54. */
  55. #define CXL_EVENT_DER_CORRECTION_MASK_SIZE 0x20
  56. struct cxl_event_dram {
  57. struct cxl_event_media_hdr media_hdr;
  58. u8 nibble_mask[3];
  59. u8 bank_group;
  60. u8 bank;
  61. u8 row[3];
  62. u8 column[2];
  63. u8 correction_mask[CXL_EVENT_DER_CORRECTION_MASK_SIZE];
  64. u8 reserved[0x17];
  65. } __packed;
  66. /*
  67. * Get Health Info Record
  68. * CXL rev 3.0 section 8.2.9.8.3.1; Table 8-100
  69. */
  70. struct cxl_get_health_info {
  71. u8 health_status;
  72. u8 media_status;
  73. u8 add_status;
  74. u8 life_used;
  75. u8 device_temp[2];
  76. u8 dirty_shutdown_cnt[4];
  77. u8 cor_vol_err_cnt[4];
  78. u8 cor_per_err_cnt[4];
  79. } __packed;
  80. /*
  81. * Memory Module Event Record
  82. * CXL rev 3.0 section 8.2.9.2.1.3; Table 8-45
  83. */
  84. struct cxl_event_mem_module {
  85. struct cxl_event_record_hdr hdr;
  86. u8 event_type;
  87. struct cxl_get_health_info info;
  88. u8 reserved[0x3d];
  89. } __packed;
  90. union cxl_event {
  91. struct cxl_event_generic generic;
  92. struct cxl_event_gen_media gen_media;
  93. struct cxl_event_dram dram;
  94. struct cxl_event_mem_module mem_module;
  95. /* dram & gen_media event header */
  96. struct cxl_event_media_hdr media_hdr;
  97. } __packed;
  98. /*
  99. * Common Event Record Format; in event logs
  100. * CXL rev 3.0 section 8.2.9.2.1; Table 8-42
  101. */
  102. struct cxl_event_record_raw {
  103. uuid_t id;
  104. union cxl_event event;
  105. } __packed;
  106. enum cxl_event_type {
  107. CXL_CPER_EVENT_GENERIC,
  108. CXL_CPER_EVENT_GEN_MEDIA,
  109. CXL_CPER_EVENT_DRAM,
  110. CXL_CPER_EVENT_MEM_MODULE,
  111. };
  112. #define CPER_CXL_DEVICE_ID_VALID BIT(0)
  113. #define CPER_CXL_DEVICE_SN_VALID BIT(1)
  114. #define CPER_CXL_COMP_EVENT_LOG_VALID BIT(2)
  115. struct cxl_cper_event_rec {
  116. struct {
  117. u32 length;
  118. u64 validation_bits;
  119. struct cper_cxl_event_devid {
  120. u16 vendor_id;
  121. u16 device_id;
  122. u8 func_num;
  123. u8 device_num;
  124. u8 bus_num;
  125. u16 segment_num;
  126. u16 slot_num; /* bits 2:0 reserved */
  127. u8 reserved;
  128. } __packed device_id;
  129. struct cper_cxl_event_sn {
  130. u32 lower_dw;
  131. u32 upper_dw;
  132. } __packed dev_serial_num;
  133. } __packed hdr;
  134. union cxl_event event;
  135. } __packed;
  136. struct cxl_cper_work_data {
  137. enum cxl_event_type event_type;
  138. struct cxl_cper_event_rec rec;
  139. };
  140. #ifdef CONFIG_ACPI_APEI_GHES
  141. int cxl_cper_register_work(struct work_struct *work);
  142. int cxl_cper_unregister_work(struct work_struct *work);
  143. int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd);
  144. #else
  145. static inline int cxl_cper_register_work(struct work_struct *work)
  146. {
  147. return 0;
  148. }
  149. static inline int cxl_cper_unregister_work(struct work_struct *work)
  150. {
  151. return 0;
  152. }
  153. static inline int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd)
  154. {
  155. return 0;
  156. }
  157. #endif
  158. #endif /* _LINUX_CXL_EVENT_H */