blob: d96d6116f0fb70b9275547d19a71f09662eb9400 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Doug Thompsoneb919692009-05-05 20:07:11 +02002#include "amd64_edac.h"
3
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -03004static ssize_t amd64_inject_section_show(struct device *dev,
5 struct device_attribute *mattr,
6 char *buf)
Borislav Petkov94baaee2009-09-24 11:05:30 +02007{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -03008 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkov94baaee2009-09-24 11:05:30 +02009 struct amd64_pvt *pvt = mci->pvt_info;
10 return sprintf(buf, "0x%x\n", pvt->injection.section);
11}
12
Doug Thompsoneb919692009-05-05 20:07:11 +020013/*
14 * store error injection section value which refers to one of 4 16-byte sections
15 * within a 64-byte cacheline
16 *
17 * range: 0..3
18 */
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030019static ssize_t amd64_inject_section_store(struct device *dev,
20 struct device_attribute *mattr,
Doug Thompsoneb919692009-05-05 20:07:11 +020021 const char *data, size_t count)
22{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030023 struct mem_ctl_info *mci = to_mci(dev);
Doug Thompsoneb919692009-05-05 20:07:11 +020024 struct amd64_pvt *pvt = mci->pvt_info;
25 unsigned long value;
Borislav Petkov6e71a872012-08-09 18:23:53 +020026 int ret;
Doug Thompsoneb919692009-05-05 20:07:11 +020027
Jingoo Hanc7f62fc2013-06-01 16:08:22 +090028 ret = kstrtoul(data, 10, &value);
Borislav Petkov6e71a872012-08-09 18:23:53 +020029 if (ret < 0)
30 return ret;
Borislav Petkov94baaee2009-09-24 11:05:30 +020031
Borislav Petkov6e71a872012-08-09 18:23:53 +020032 if (value > 3) {
33 amd64_warn("%s: invalid section 0x%lx\n", __func__, value);
34 return -EINVAL;
Doug Thompsoneb919692009-05-05 20:07:11 +020035 }
Borislav Petkov6e71a872012-08-09 18:23:53 +020036
37 pvt->injection.section = (u32) value;
38 return count;
Doug Thompsoneb919692009-05-05 20:07:11 +020039}
40
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030041static ssize_t amd64_inject_word_show(struct device *dev,
42 struct device_attribute *mattr,
43 char *buf)
Borislav Petkov94baaee2009-09-24 11:05:30 +020044{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030045 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkov94baaee2009-09-24 11:05:30 +020046 struct amd64_pvt *pvt = mci->pvt_info;
47 return sprintf(buf, "0x%x\n", pvt->injection.word);
48}
49
Doug Thompsoneb919692009-05-05 20:07:11 +020050/*
51 * store error injection word value which refers to one of 9 16-bit word of the
52 * 16-byte (128-bit + ECC bits) section
53 *
54 * range: 0..8
55 */
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030056static ssize_t amd64_inject_word_store(struct device *dev,
57 struct device_attribute *mattr,
58 const char *data, size_t count)
Doug Thompsoneb919692009-05-05 20:07:11 +020059{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030060 struct mem_ctl_info *mci = to_mci(dev);
Doug Thompsoneb919692009-05-05 20:07:11 +020061 struct amd64_pvt *pvt = mci->pvt_info;
62 unsigned long value;
Borislav Petkov6e71a872012-08-09 18:23:53 +020063 int ret;
Doug Thompsoneb919692009-05-05 20:07:11 +020064
Jingoo Hanc7f62fc2013-06-01 16:08:22 +090065 ret = kstrtoul(data, 10, &value);
Borislav Petkov6e71a872012-08-09 18:23:53 +020066 if (ret < 0)
67 return ret;
Doug Thompsoneb919692009-05-05 20:07:11 +020068
Borislav Petkov6e71a872012-08-09 18:23:53 +020069 if (value > 8) {
70 amd64_warn("%s: invalid word 0x%lx\n", __func__, value);
71 return -EINVAL;
Doug Thompsoneb919692009-05-05 20:07:11 +020072 }
Borislav Petkov6e71a872012-08-09 18:23:53 +020073
74 pvt->injection.word = (u32) value;
75 return count;
Doug Thompsoneb919692009-05-05 20:07:11 +020076}
77
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030078static ssize_t amd64_inject_ecc_vector_show(struct device *dev,
79 struct device_attribute *mattr,
80 char *buf)
Borislav Petkov94baaee2009-09-24 11:05:30 +020081{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030082 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkov94baaee2009-09-24 11:05:30 +020083 struct amd64_pvt *pvt = mci->pvt_info;
84 return sprintf(buf, "0x%x\n", pvt->injection.bit_map);
85}
86
Doug Thompsoneb919692009-05-05 20:07:11 +020087/*
88 * store 16 bit error injection vector which enables injecting errors to the
89 * corresponding bit within the error injection word above. When used during a
90 * DRAM ECC read, it holds the contents of the of the DRAM ECC bits.
91 */
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030092static ssize_t amd64_inject_ecc_vector_store(struct device *dev,
93 struct device_attribute *mattr,
94 const char *data, size_t count)
Doug Thompsoneb919692009-05-05 20:07:11 +020095{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -030096 struct mem_ctl_info *mci = to_mci(dev);
Doug Thompsoneb919692009-05-05 20:07:11 +020097 struct amd64_pvt *pvt = mci->pvt_info;
98 unsigned long value;
Borislav Petkov6e71a872012-08-09 18:23:53 +020099 int ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200100
Jingoo Hanc7f62fc2013-06-01 16:08:22 +0900101 ret = kstrtoul(data, 16, &value);
Borislav Petkov6e71a872012-08-09 18:23:53 +0200102 if (ret < 0)
103 return ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200104
Borislav Petkov6e71a872012-08-09 18:23:53 +0200105 if (value & 0xFFFF0000) {
106 amd64_warn("%s: invalid EccVector: 0x%lx\n", __func__, value);
107 return -EINVAL;
Doug Thompsoneb919692009-05-05 20:07:11 +0200108 }
Borislav Petkov6e71a872012-08-09 18:23:53 +0200109
110 pvt->injection.bit_map = (u32) value;
111 return count;
Doug Thompsoneb919692009-05-05 20:07:11 +0200112}
113
114/*
115 * Do a DRAM ECC read. Assemble staged values in the pvt area, format into
116 * fields needed by the injection registers and read the NB Array Data Port.
117 */
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300118static ssize_t amd64_inject_read_store(struct device *dev,
119 struct device_attribute *mattr,
120 const char *data, size_t count)
Doug Thompsoneb919692009-05-05 20:07:11 +0200121{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300122 struct mem_ctl_info *mci = to_mci(dev);
Doug Thompsoneb919692009-05-05 20:07:11 +0200123 struct amd64_pvt *pvt = mci->pvt_info;
124 unsigned long value;
125 u32 section, word_bits;
Borislav Petkov6e71a872012-08-09 18:23:53 +0200126 int ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200127
Jingoo Hanc7f62fc2013-06-01 16:08:22 +0900128 ret = kstrtoul(data, 10, &value);
Borislav Petkov6e71a872012-08-09 18:23:53 +0200129 if (ret < 0)
130 return ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200131
Borislav Petkov6e71a872012-08-09 18:23:53 +0200132 /* Form value to choose 16-byte section of cacheline */
133 section = F10_NB_ARRAY_DRAM | SET_NB_ARRAY_ADDR(pvt->injection.section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200134
Borislav Petkov6e71a872012-08-09 18:23:53 +0200135 amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_ADDR, section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200136
Borislav Petkov6e71a872012-08-09 18:23:53 +0200137 word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection);
Doug Thompsoneb919692009-05-05 20:07:11 +0200138
Borislav Petkov6e71a872012-08-09 18:23:53 +0200139 /* Issue 'word' and 'bit' along with the READ request */
140 amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_DATA, word_bits);
Doug Thompsoneb919692009-05-05 20:07:11 +0200141
Borislav Petkov6e71a872012-08-09 18:23:53 +0200142 edac_dbg(0, "section=0x%x word_bits=0x%x\n", section, word_bits);
143
144 return count;
Doug Thompsoneb919692009-05-05 20:07:11 +0200145}
146
147/*
148 * Do a DRAM ECC write. Assemble staged values in the pvt area and format into
149 * fields needed by the injection registers.
150 */
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300151static ssize_t amd64_inject_write_store(struct device *dev,
152 struct device_attribute *mattr,
Doug Thompsoneb919692009-05-05 20:07:11 +0200153 const char *data, size_t count)
154{
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300155 struct mem_ctl_info *mci = to_mci(dev);
Doug Thompsoneb919692009-05-05 20:07:11 +0200156 struct amd64_pvt *pvt = mci->pvt_info;
Borislav Petkov66fed2d2012-08-09 18:41:07 +0200157 u32 section, word_bits, tmp;
Doug Thompsoneb919692009-05-05 20:07:11 +0200158 unsigned long value;
Borislav Petkov6e71a872012-08-09 18:23:53 +0200159 int ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200160
Jingoo Hanc7f62fc2013-06-01 16:08:22 +0900161 ret = kstrtoul(data, 10, &value);
Borislav Petkov6e71a872012-08-09 18:23:53 +0200162 if (ret < 0)
163 return ret;
Doug Thompsoneb919692009-05-05 20:07:11 +0200164
Borislav Petkov6e71a872012-08-09 18:23:53 +0200165 /* Form value to choose 16-byte section of cacheline */
166 section = F10_NB_ARRAY_DRAM | SET_NB_ARRAY_ADDR(pvt->injection.section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200167
Borislav Petkov6e71a872012-08-09 18:23:53 +0200168 amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_ADDR, section);
Doug Thompsoneb919692009-05-05 20:07:11 +0200169
Borislav Petkov6e71a872012-08-09 18:23:53 +0200170 word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection);
Doug Thompsoneb919692009-05-05 20:07:11 +0200171
Borislav Petkov66fed2d2012-08-09 18:41:07 +0200172 pr_notice_once("Don't forget to decrease MCE polling interval in\n"
173 "/sys/bus/machinecheck/devices/machinecheck<CPUNUM>/check_interval\n"
174 "so that you can get the error report faster.\n");
175
176 on_each_cpu(disable_caches, NULL, 1);
177
Borislav Petkov6e71a872012-08-09 18:23:53 +0200178 /* Issue 'word' and 'bit' along with the READ request */
179 amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_DATA, word_bits);
Doug Thompsoneb919692009-05-05 20:07:11 +0200180
Borislav Petkov66fed2d2012-08-09 18:41:07 +0200181 retry:
182 /* wait until injection happens */
183 amd64_read_pci_cfg(pvt->F3, F10_NB_ARRAY_DATA, &tmp);
184 if (tmp & F10_NB_ARR_ECC_WR_REQ) {
185 cpu_relax();
186 goto retry;
187 }
188
189 on_each_cpu(enable_caches, NULL, 1);
190
Borislav Petkov6e71a872012-08-09 18:23:53 +0200191 edac_dbg(0, "section=0x%x word_bits=0x%x\n", section, word_bits);
192
193 return count;
Doug Thompsoneb919692009-05-05 20:07:11 +0200194}
195
196/*
197 * update NUM_INJ_ATTRS in case you add new members
198 */
Doug Thompsoneb919692009-05-05 20:07:11 +0200199
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300200static DEVICE_ATTR(inject_section, S_IRUGO | S_IWUSR,
201 amd64_inject_section_show, amd64_inject_section_store);
202static DEVICE_ATTR(inject_word, S_IRUGO | S_IWUSR,
203 amd64_inject_word_show, amd64_inject_word_store);
204static DEVICE_ATTR(inject_ecc_vector, S_IRUGO | S_IWUSR,
205 amd64_inject_ecc_vector_show, amd64_inject_ecc_vector_store);
Borislav Petkovbbb013b2013-05-12 13:03:56 +0200206static DEVICE_ATTR(inject_write, S_IWUSR,
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300207 NULL, amd64_inject_write_store);
Borislav Petkovbbb013b2013-05-12 13:03:56 +0200208static DEVICE_ATTR(inject_read, S_IWUSR,
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300209 NULL, amd64_inject_read_store);
210
Takashi Iwaie339f1e2015-02-04 11:48:53 +0100211static struct attribute *amd64_edac_inj_attrs[] = {
212 &dev_attr_inject_section.attr,
213 &dev_attr_inject_word.attr,
214 &dev_attr_inject_ecc_vector.attr,
215 &dev_attr_inject_write.attr,
216 &dev_attr_inject_read.attr,
217 NULL
218};
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300219
Takashi Iwaie339f1e2015-02-04 11:48:53 +0100220static umode_t amd64_edac_inj_is_visible(struct kobject *kobj,
221 struct attribute *attr, int idx)
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300222{
Takashi Iwaie339f1e2015-02-04 11:48:53 +0100223 struct device *dev = kobj_to_dev(kobj);
224 struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
225 struct amd64_pvt *pvt = mci->pvt_info;
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300226
Takashi Iwaie339f1e2015-02-04 11:48:53 +0100227 if (pvt->fam < 0x10)
228 return 0;
229 return attr->mode;
Mauro Carvalho Chehabc5608752012-03-21 14:00:44 -0300230}
231
Takashi Iwaie339f1e2015-02-04 11:48:53 +0100232const struct attribute_group amd64_edac_inj_group = {
233 .attrs = amd64_edac_inj_attrs,
234 .is_visible = amd64_edac_inj_is_visible,
235};