blob: 523ce4a6edc66265f3f50adad5cc652ecd02de8a [file] [log] [blame]
Doug Thompsoneb919692009-05-05 20:07:11 +02001#include "amd64_edac.h"
2
Borislav Petkov94baaee2009-09-24 11:05:30 +02003static ssize_t amd64_inject_section_show(struct mem_ctl_info *mci, char *buf)
4{
5 struct amd64_pvt *pvt = mci->pvt_info;
6 return sprintf(buf, "0x%x\n", pvt->injection.section);
7}
8
Doug Thompsoneb919692009-05-05 20:07:11 +02009/*
10 * store error injection section value which refers to one of 4 16-byte sections
11 * within a 64-byte cacheline
12 *
13 * range: 0..3
14 */
15static ssize_t amd64_inject_section_store(struct mem_ctl_info *mci,
16 const char *data, size_t count)
17{
18 struct amd64_pvt *pvt = mci->pvt_info;
19 unsigned long value;
20 int ret = 0;
21
22 ret = strict_strtoul(data, 10, &value);
23 if (ret != -EINVAL) {
Borislav Petkov94baaee2009-09-24 11:05:30 +020024
25 if (value > 3) {
26 amd64_printk(KERN_WARNING,
27 "%s: invalid section 0x%lx\n",
28 __func__, value);
29 return -EINVAL;
30 }
31
Doug Thompsoneb919692009-05-05 20:07:11 +020032 pvt->injection.section = (u32) value;
33 return count;
34 }
35 return ret;
36}
37
Borislav Petkov94baaee2009-09-24 11:05:30 +020038static ssize_t amd64_inject_word_show(struct mem_ctl_info *mci, char *buf)
39{
40 struct amd64_pvt *pvt = mci->pvt_info;
41 return sprintf(buf, "0x%x\n", pvt->injection.word);
42}
43
Doug Thompsoneb919692009-05-05 20:07:11 +020044/*
45 * store error injection word value which refers to one of 9 16-bit word of the
46 * 16-byte (128-bit + ECC bits) section
47 *
48 * range: 0..8
49 */
50static ssize_t amd64_inject_word_store(struct mem_ctl_info *mci,
51 const char *data, size_t count)
52{
53 struct amd64_pvt *pvt = mci->pvt_info;
54 unsigned long value;
55 int ret = 0;
56
57 ret = strict_strtoul(data, 10, &value);
58 if (ret != -EINVAL) {
59
Borislav Petkov94baaee2009-09-24 11:05:30 +020060 if (value > 8) {
61 amd64_printk(KERN_WARNING,
62 "%s: invalid word 0x%lx\n",
63 __func__, value);
64 return -EINVAL;
65 }
Doug Thompsoneb919692009-05-05 20:07:11 +020066
Borislav Petkov94baaee2009-09-24 11:05:30 +020067 pvt->injection.word = (u32) value;
Doug Thompsoneb919692009-05-05 20:07:11 +020068 return count;
69 }
70 return ret;
71}
72
Borislav Petkov94baaee2009-09-24 11:05:30 +020073static ssize_t amd64_inject_ecc_vector_show(struct mem_ctl_info *mci, char *buf)
74{
75 struct amd64_pvt *pvt = mci->pvt_info;
76 return sprintf(buf, "0x%x\n", pvt->injection.bit_map);
77}
78
Doug Thompsoneb919692009-05-05 20:07:11 +020079/*
80 * store 16 bit error injection vector which enables injecting errors to the
81 * corresponding bit within the error injection word above. When used during a
82 * DRAM ECC read, it holds the contents of the of the DRAM ECC bits.
83 */
84static ssize_t amd64_inject_ecc_vector_store(struct mem_ctl_info *mci,
85 const char *data, size_t count)
86{
87 struct amd64_pvt *pvt = mci->pvt_info;
88 unsigned long value;
89 int ret = 0;
90
91 ret = strict_strtoul(data, 16, &value);
92 if (ret != -EINVAL) {
93
Borislav Petkov94baaee2009-09-24 11:05:30 +020094 if (value & 0xFFFF0000) {
95 amd64_printk(KERN_WARNING,
96 "%s: invalid EccVector: 0x%lx\n",
97 __func__, value);
98 return -EINVAL;
99 }
Doug Thompsoneb919692009-05-05 20:07:11 +0200100
Borislav Petkov94baaee2009-09-24 11:05:30 +0200101 pvt->injection.bit_map = (u32) value;
Doug Thompsoneb919692009-05-05 20:07:11 +0200102 return count;
103 }
104 return ret;
105}
106
107/*
108 * Do a DRAM ECC read. Assemble staged values in the pvt area, format into
109 * fields needed by the injection registers and read the NB Array Data Port.
110 */
111static ssize_t amd64_inject_read_store(struct mem_ctl_info *mci,
112 const char *data, size_t count)
113{
114 struct amd64_pvt *pvt = mci->pvt_info;
115 unsigned long value;
116 u32 section, word_bits;
117 int ret = 0;
118
119 ret = strict_strtoul(data, 10, &value);
120 if (ret != -EINVAL) {
121
122 /* Form value to choose 16-byte section of cacheline */
123 section = F10_NB_ARRAY_DRAM_ECC |
124 SET_NB_ARRAY_ADDRESS(pvt->injection.section);
Borislav Petkov8d5b5d92010-10-01 20:11:07 +0200125 pci_write_config_dword(pvt->F3, F10_NB_ARRAY_ADDR, section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200126
127 word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word,
128 pvt->injection.bit_map);
129
130 /* Issue 'word' and 'bit' along with the READ request */
Borislav Petkov8d5b5d92010-10-01 20:11:07 +0200131 pci_write_config_dword(pvt->F3, F10_NB_ARRAY_DATA, word_bits);
Doug Thompsoneb919692009-05-05 20:07:11 +0200132
133 debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
134
135 return count;
136 }
137 return ret;
138}
139
140/*
141 * Do a DRAM ECC write. Assemble staged values in the pvt area and format into
142 * fields needed by the injection registers.
143 */
144static ssize_t amd64_inject_write_store(struct mem_ctl_info *mci,
145 const char *data, size_t count)
146{
147 struct amd64_pvt *pvt = mci->pvt_info;
148 unsigned long value;
149 u32 section, word_bits;
150 int ret = 0;
151
152 ret = strict_strtoul(data, 10, &value);
153 if (ret != -EINVAL) {
154
155 /* Form value to choose 16-byte section of cacheline */
156 section = F10_NB_ARRAY_DRAM_ECC |
157 SET_NB_ARRAY_ADDRESS(pvt->injection.section);
Borislav Petkov8d5b5d92010-10-01 20:11:07 +0200158 pci_write_config_dword(pvt->F3, F10_NB_ARRAY_ADDR, section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200159
160 word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word,
161 pvt->injection.bit_map);
162
163 /* Issue 'word' and 'bit' along with the READ request */
Borislav Petkov8d5b5d92010-10-01 20:11:07 +0200164 pci_write_config_dword(pvt->F3, F10_NB_ARRAY_DATA, word_bits);
Doug Thompsoneb919692009-05-05 20:07:11 +0200165
166 debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
167
168 return count;
169 }
170 return ret;
171}
172
173/*
174 * update NUM_INJ_ATTRS in case you add new members
175 */
176struct mcidev_sysfs_attribute amd64_inj_attrs[] = {
177
178 {
179 .attr = {
180 .name = "inject_section",
181 .mode = (S_IRUGO | S_IWUSR)
182 },
Borislav Petkov94baaee2009-09-24 11:05:30 +0200183 .show = amd64_inject_section_show,
Doug Thompsoneb919692009-05-05 20:07:11 +0200184 .store = amd64_inject_section_store,
185 },
186 {
187 .attr = {
188 .name = "inject_word",
189 .mode = (S_IRUGO | S_IWUSR)
190 },
Borislav Petkov94baaee2009-09-24 11:05:30 +0200191 .show = amd64_inject_word_show,
Doug Thompsoneb919692009-05-05 20:07:11 +0200192 .store = amd64_inject_word_store,
193 },
194 {
195 .attr = {
196 .name = "inject_ecc_vector",
197 .mode = (S_IRUGO | S_IWUSR)
198 },
Borislav Petkov94baaee2009-09-24 11:05:30 +0200199 .show = amd64_inject_ecc_vector_show,
Doug Thompsoneb919692009-05-05 20:07:11 +0200200 .store = amd64_inject_ecc_vector_store,
201 },
202 {
203 .attr = {
204 .name = "inject_write",
205 .mode = (S_IRUGO | S_IWUSR)
206 },
207 .show = NULL,
208 .store = amd64_inject_write_store,
209 },
210 {
211 .attr = {
212 .name = "inject_read",
213 .mode = (S_IRUGO | S_IWUSR)
214 },
215 .show = NULL,
216 .store = amd64_inject_read_store,
217 },
218};