Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 1 | #include "amd64_edac.h" |
| 2 | |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 3 | static ssize_t amd64_inject_section_show(struct device *dev, |
| 4 | struct device_attribute *mattr, |
| 5 | char *buf) |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 6 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 7 | struct mem_ctl_info *mci = to_mci(dev); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 8 | struct amd64_pvt *pvt = mci->pvt_info; |
| 9 | return sprintf(buf, "0x%x\n", pvt->injection.section); |
| 10 | } |
| 11 | |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 12 | /* |
| 13 | * store error injection section value which refers to one of 4 16-byte sections |
| 14 | * within a 64-byte cacheline |
| 15 | * |
| 16 | * range: 0..3 |
| 17 | */ |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 18 | static ssize_t amd64_inject_section_store(struct device *dev, |
| 19 | struct device_attribute *mattr, |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 20 | const char *data, size_t count) |
| 21 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 22 | struct mem_ctl_info *mci = to_mci(dev); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 23 | struct amd64_pvt *pvt = mci->pvt_info; |
| 24 | unsigned long value; |
| 25 | int ret = 0; |
| 26 | |
| 27 | ret = strict_strtoul(data, 10, &value); |
| 28 | if (ret != -EINVAL) { |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 29 | |
| 30 | if (value > 3) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 31 | amd64_warn("%s: invalid section 0x%lx\n", __func__, value); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 32 | return -EINVAL; |
| 33 | } |
| 34 | |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 35 | pvt->injection.section = (u32) value; |
| 36 | return count; |
| 37 | } |
| 38 | return ret; |
| 39 | } |
| 40 | |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 41 | static ssize_t amd64_inject_word_show(struct device *dev, |
| 42 | struct device_attribute *mattr, |
| 43 | char *buf) |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 44 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 45 | struct mem_ctl_info *mci = to_mci(dev); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 46 | struct amd64_pvt *pvt = mci->pvt_info; |
| 47 | return sprintf(buf, "0x%x\n", pvt->injection.word); |
| 48 | } |
| 49 | |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 50 | /* |
| 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 Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 56 | static ssize_t amd64_inject_word_store(struct device *dev, |
| 57 | struct device_attribute *mattr, |
| 58 | const char *data, size_t count) |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 59 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 60 | struct mem_ctl_info *mci = to_mci(dev); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 61 | struct amd64_pvt *pvt = mci->pvt_info; |
| 62 | unsigned long value; |
| 63 | int ret = 0; |
| 64 | |
| 65 | ret = strict_strtoul(data, 10, &value); |
| 66 | if (ret != -EINVAL) { |
| 67 | |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 68 | if (value > 8) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 69 | amd64_warn("%s: invalid word 0x%lx\n", __func__, value); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 70 | return -EINVAL; |
| 71 | } |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 72 | |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 73 | pvt->injection.word = (u32) value; |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 74 | return count; |
| 75 | } |
| 76 | return ret; |
| 77 | } |
| 78 | |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 79 | static ssize_t amd64_inject_ecc_vector_show(struct device *dev, |
| 80 | struct device_attribute *mattr, |
| 81 | char *buf) |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 82 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 83 | struct mem_ctl_info *mci = to_mci(dev); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 84 | struct amd64_pvt *pvt = mci->pvt_info; |
| 85 | return sprintf(buf, "0x%x\n", pvt->injection.bit_map); |
| 86 | } |
| 87 | |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 88 | /* |
| 89 | * store 16 bit error injection vector which enables injecting errors to the |
| 90 | * corresponding bit within the error injection word above. When used during a |
| 91 | * DRAM ECC read, it holds the contents of the of the DRAM ECC bits. |
| 92 | */ |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 93 | static ssize_t amd64_inject_ecc_vector_store(struct device *dev, |
| 94 | struct device_attribute *mattr, |
| 95 | const char *data, size_t count) |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 96 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 97 | struct mem_ctl_info *mci = to_mci(dev); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 98 | struct amd64_pvt *pvt = mci->pvt_info; |
| 99 | unsigned long value; |
| 100 | int ret = 0; |
| 101 | |
| 102 | ret = strict_strtoul(data, 16, &value); |
| 103 | if (ret != -EINVAL) { |
| 104 | |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 105 | if (value & 0xFFFF0000) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 106 | amd64_warn("%s: invalid EccVector: 0x%lx\n", |
| 107 | __func__, value); |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 108 | return -EINVAL; |
| 109 | } |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 110 | |
Borislav Petkov | 94baaee | 2009-09-24 11:05:30 +0200 | [diff] [blame] | 111 | pvt->injection.bit_map = (u32) value; |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 112 | return count; |
| 113 | } |
| 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Do a DRAM ECC read. Assemble staged values in the pvt area, format into |
| 119 | * fields needed by the injection registers and read the NB Array Data Port. |
| 120 | */ |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 121 | static ssize_t amd64_inject_read_store(struct device *dev, |
| 122 | struct device_attribute *mattr, |
| 123 | const char *data, size_t count) |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 124 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 125 | struct mem_ctl_info *mci = to_mci(dev); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 126 | struct amd64_pvt *pvt = mci->pvt_info; |
| 127 | unsigned long value; |
| 128 | u32 section, word_bits; |
| 129 | int ret = 0; |
| 130 | |
| 131 | ret = strict_strtoul(data, 10, &value); |
| 132 | if (ret != -EINVAL) { |
| 133 | |
| 134 | /* Form value to choose 16-byte section of cacheline */ |
| 135 | section = F10_NB_ARRAY_DRAM_ECC | |
| 136 | SET_NB_ARRAY_ADDRESS(pvt->injection.section); |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 137 | amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_ADDR, section); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 138 | |
| 139 | word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word, |
| 140 | pvt->injection.bit_map); |
| 141 | |
| 142 | /* Issue 'word' and 'bit' along with the READ request */ |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 143 | amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_DATA, word_bits); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 144 | |
| 145 | debugf0("section=0x%x word_bits=0x%x\n", section, word_bits); |
| 146 | |
| 147 | return count; |
| 148 | } |
| 149 | return ret; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * Do a DRAM ECC write. Assemble staged values in the pvt area and format into |
| 154 | * fields needed by the injection registers. |
| 155 | */ |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 156 | static ssize_t amd64_inject_write_store(struct device *dev, |
| 157 | struct device_attribute *mattr, |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 158 | const char *data, size_t count) |
| 159 | { |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 160 | struct mem_ctl_info *mci = to_mci(dev); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 161 | struct amd64_pvt *pvt = mci->pvt_info; |
| 162 | unsigned long value; |
| 163 | u32 section, word_bits; |
| 164 | int ret = 0; |
| 165 | |
| 166 | ret = strict_strtoul(data, 10, &value); |
| 167 | if (ret != -EINVAL) { |
| 168 | |
| 169 | /* Form value to choose 16-byte section of cacheline */ |
| 170 | section = F10_NB_ARRAY_DRAM_ECC | |
| 171 | SET_NB_ARRAY_ADDRESS(pvt->injection.section); |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 172 | amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_ADDR, section); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 173 | |
| 174 | word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word, |
| 175 | pvt->injection.bit_map); |
| 176 | |
| 177 | /* Issue 'word' and 'bit' along with the READ request */ |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 178 | amd64_write_pci_cfg(pvt->F3, F10_NB_ARRAY_DATA, word_bits); |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 179 | |
| 180 | debugf0("section=0x%x word_bits=0x%x\n", section, word_bits); |
| 181 | |
| 182 | return count; |
| 183 | } |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * update NUM_INJ_ATTRS in case you add new members |
| 189 | */ |
Doug Thompson | eb91969 | 2009-05-05 20:07:11 +0200 | [diff] [blame] | 190 | |
Mauro Carvalho Chehab | c560875 | 2012-03-21 14:00:44 -0300 | [diff] [blame^] | 191 | static DEVICE_ATTR(inject_section, S_IRUGO | S_IWUSR, |
| 192 | amd64_inject_section_show, amd64_inject_section_store); |
| 193 | static DEVICE_ATTR(inject_word, S_IRUGO | S_IWUSR, |
| 194 | amd64_inject_word_show, amd64_inject_word_store); |
| 195 | static DEVICE_ATTR(inject_ecc_vector, S_IRUGO | S_IWUSR, |
| 196 | amd64_inject_ecc_vector_show, amd64_inject_ecc_vector_store); |
| 197 | static DEVICE_ATTR(inject_write, S_IRUGO | S_IWUSR, |
| 198 | NULL, amd64_inject_write_store); |
| 199 | static DEVICE_ATTR(inject_read, S_IRUGO | S_IWUSR, |
| 200 | NULL, amd64_inject_read_store); |
| 201 | |
| 202 | |
| 203 | int amd64_create_sysfs_inject_files(struct mem_ctl_info *mci) |
| 204 | { |
| 205 | int rc; |
| 206 | |
| 207 | rc = device_create_file(&mci->dev, &dev_attr_inject_section); |
| 208 | if (rc < 0) |
| 209 | return rc; |
| 210 | rc = device_create_file(&mci->dev, &dev_attr_inject_word); |
| 211 | if (rc < 0) |
| 212 | return rc; |
| 213 | rc = device_create_file(&mci->dev, &dev_attr_inject_ecc_vector); |
| 214 | if (rc < 0) |
| 215 | return rc; |
| 216 | rc = device_create_file(&mci->dev, &dev_attr_inject_write); |
| 217 | if (rc < 0) |
| 218 | return rc; |
| 219 | rc = device_create_file(&mci->dev, &dev_attr_inject_read); |
| 220 | if (rc < 0) |
| 221 | return rc; |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | void amd64_remove_sysfs_inject_files(struct mem_ctl_info *mci) |
| 227 | { |
| 228 | device_remove_file(&mci->dev, &dev_attr_inject_section); |
| 229 | device_remove_file(&mci->dev, &dev_attr_inject_word); |
| 230 | device_remove_file(&mci->dev, &dev_attr_inject_ecc_vector); |
| 231 | device_remove_file(&mci->dev, &dev_attr_inject_write); |
| 232 | device_remove_file(&mci->dev, &dev_attr_inject_read); |
| 233 | } |