amd64_edac_inj.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "amd64_edac.h"
  2. /*
  3. * store error injection section value which refers to one of 4 16-byte sections
  4. * within a 64-byte cacheline
  5. *
  6. * range: 0..3
  7. */
  8. static ssize_t amd64_inject_section_store(struct mem_ctl_info *mci,
  9. const char *data, size_t count)
  10. {
  11. struct amd64_pvt *pvt = mci->pvt_info;
  12. unsigned long value;
  13. int ret = 0;
  14. ret = strict_strtoul(data, 10, &value);
  15. if (ret != -EINVAL) {
  16. pvt->injection.section = (u32) value;
  17. return count;
  18. }
  19. return ret;
  20. }
  21. /*
  22. * store error injection word value which refers to one of 9 16-bit word of the
  23. * 16-byte (128-bit + ECC bits) section
  24. *
  25. * range: 0..8
  26. */
  27. static ssize_t amd64_inject_word_store(struct mem_ctl_info *mci,
  28. const char *data, size_t count)
  29. {
  30. struct amd64_pvt *pvt = mci->pvt_info;
  31. unsigned long value;
  32. int ret = 0;
  33. ret = strict_strtoul(data, 10, &value);
  34. if (ret != -EINVAL) {
  35. value = (value <= 8) ? value : 0;
  36. pvt->injection.word = (u32) value;
  37. return count;
  38. }
  39. return ret;
  40. }
  41. /*
  42. * store 16 bit error injection vector which enables injecting errors to the
  43. * corresponding bit within the error injection word above. When used during a
  44. * DRAM ECC read, it holds the contents of the of the DRAM ECC bits.
  45. */
  46. static ssize_t amd64_inject_ecc_vector_store(struct mem_ctl_info *mci,
  47. const char *data, size_t count)
  48. {
  49. struct amd64_pvt *pvt = mci->pvt_info;
  50. unsigned long value;
  51. int ret = 0;
  52. ret = strict_strtoul(data, 16, &value);
  53. if (ret != -EINVAL) {
  54. pvt->injection.bit_map = (u32) value & 0xFFFF;
  55. return count;
  56. }
  57. return ret;
  58. }
  59. /*
  60. * Do a DRAM ECC read. Assemble staged values in the pvt area, format into
  61. * fields needed by the injection registers and read the NB Array Data Port.
  62. */
  63. static ssize_t amd64_inject_read_store(struct mem_ctl_info *mci,
  64. const char *data, size_t count)
  65. {
  66. struct amd64_pvt *pvt = mci->pvt_info;
  67. unsigned long value;
  68. u32 section, word_bits;
  69. int ret = 0;
  70. ret = strict_strtoul(data, 10, &value);
  71. if (ret != -EINVAL) {
  72. /* Form value to choose 16-byte section of cacheline */
  73. section = F10_NB_ARRAY_DRAM_ECC |
  74. SET_NB_ARRAY_ADDRESS(pvt->injection.section);
  75. pci_write_config_dword(pvt->misc_f3_ctl,
  76. F10_NB_ARRAY_ADDR, section);
  77. word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word,
  78. pvt->injection.bit_map);
  79. /* Issue 'word' and 'bit' along with the READ request */
  80. pci_write_config_dword(pvt->misc_f3_ctl,
  81. F10_NB_ARRAY_DATA, word_bits);
  82. debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
  83. return count;
  84. }
  85. return ret;
  86. }
  87. /*
  88. * Do a DRAM ECC write. Assemble staged values in the pvt area and format into
  89. * fields needed by the injection registers.
  90. */
  91. static ssize_t amd64_inject_write_store(struct mem_ctl_info *mci,
  92. const char *data, size_t count)
  93. {
  94. struct amd64_pvt *pvt = mci->pvt_info;
  95. unsigned long value;
  96. u32 section, word_bits;
  97. int ret = 0;
  98. ret = strict_strtoul(data, 10, &value);
  99. if (ret != -EINVAL) {
  100. /* Form value to choose 16-byte section of cacheline */
  101. section = F10_NB_ARRAY_DRAM_ECC |
  102. SET_NB_ARRAY_ADDRESS(pvt->injection.section);
  103. pci_write_config_dword(pvt->misc_f3_ctl,
  104. F10_NB_ARRAY_ADDR, section);
  105. word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word,
  106. pvt->injection.bit_map);
  107. /* Issue 'word' and 'bit' along with the READ request */
  108. pci_write_config_dword(pvt->misc_f3_ctl,
  109. F10_NB_ARRAY_DATA, word_bits);
  110. debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
  111. return count;
  112. }
  113. return ret;
  114. }
  115. /*
  116. * update NUM_INJ_ATTRS in case you add new members
  117. */
  118. struct mcidev_sysfs_attribute amd64_inj_attrs[] = {
  119. {
  120. .attr = {
  121. .name = "inject_section",
  122. .mode = (S_IRUGO | S_IWUSR)
  123. },
  124. .show = NULL,
  125. .store = amd64_inject_section_store,
  126. },
  127. {
  128. .attr = {
  129. .name = "inject_word",
  130. .mode = (S_IRUGO | S_IWUSR)
  131. },
  132. .show = NULL,
  133. .store = amd64_inject_word_store,
  134. },
  135. {
  136. .attr = {
  137. .name = "inject_ecc_vector",
  138. .mode = (S_IRUGO | S_IWUSR)
  139. },
  140. .show = NULL,
  141. .store = amd64_inject_ecc_vector_store,
  142. },
  143. {
  144. .attr = {
  145. .name = "inject_write",
  146. .mode = (S_IRUGO | S_IWUSR)
  147. },
  148. .show = NULL,
  149. .store = amd64_inject_write_store,
  150. },
  151. {
  152. .attr = {
  153. .name = "inject_read",
  154. .mode = (S_IRUGO | S_IWUSR)
  155. },
  156. .show = NULL,
  157. .store = amd64_inject_read_store,
  158. },
  159. };