15 #include <linux/ctype.h>
16 #include <linux/slab.h>
26 static int edac_mc_log_ue = 1;
27 static int edac_mc_log_ce = 1;
28 static int edac_mc_panic_on_ue;
29 static int edac_mc_poll_msec = 1000;
34 return edac_mc_log_ue;
39 return edac_mc_log_ce;
44 return edac_mc_panic_on_ue;
50 return edac_mc_poll_msec;
62 if (ret == -
EINVAL || ((
int)l != l))
64 *((
int *)kp->
arg) =
l;
74 MODULE_PARM_DESC(edac_mc_panic_on_ue,
"Panic on uncorrected error: 0=off 1=on");
77 "Log uncorrectable error to console: 0=off 1=on");
80 "Log correctable error to console: 0=off 1=on");
82 &edac_mc_poll_msec, 0644);
85 static struct device *mci_pdev;
90 static const char *mem_types[] = {
110 static const char *dev_types[] = {
121 static const char *edac_caps[] = {
134 #ifdef CONFIG_EDAC_LEGACY_SYSFS
139 #define to_csrow(k) container_of(k, struct csrow_info, dev)
145 #define DEVICE_ATTR_LEGACY(_name, _mode, _show, _store) \
146 struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store)
148 struct dev_ch_attribute {
153 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
154 struct dev_ch_attribute dev_attr_legacy_##_name = \
155 { __ATTR(_name, _mode, _show, _store), (_var) }
157 #define to_channel(k) (container_of(k, struct dev_ch_attribute, attr)->channel)
184 nr_pages += csrow->
channels[i]->dimm->nr_pages;
193 return sprintf(data,
"%s\n", mem_types[csrow->
channels[0]->dimm->mtype]);
201 return sprintf(data,
"%s\n", dev_types[csrow->
channels[0]->dimm->dtype]);
210 return sprintf(data,
"%s\n", edac_caps[csrow->
channels[0]->dimm->edac_mode]);
223 if (!rank->
dimm->label[0])
232 const char *data,
size_t count)
259 DEVICE_ATTR_LEGACY(size_mb,
S_IRUGO, csrow_size_show,
NULL);
262 DEVICE_ATTR_LEGACY(edac_mode,
S_IRUGO, csrow_edac_mode_show,
NULL);
263 DEVICE_ATTR_LEGACY(ue_count,
S_IRUGO, csrow_ue_count_show,
NULL);
267 static struct attribute *csrow_attrs[] = {
268 &dev_attr_legacy_dev_type.attr,
269 &dev_attr_legacy_mem_type.attr,
270 &dev_attr_legacy_edac_mode.attr,
271 &dev_attr_legacy_size_mb.attr,
272 &dev_attr_legacy_ue_count.attr,
273 &dev_attr_legacy_ce_count.attr,
278 .
attrs = csrow_attrs,
286 static void csrow_attr_release(
struct device *dev)
290 edac_dbg(1,
"Releasing csrow device %s\n", dev_name(dev));
295 .
groups = csrow_attr_groups,
296 .release = csrow_attr_release,
304 #define EDAC_NR_CHANNELS 6
307 channel_dimm_label_show, channel_dimm_label_store, 0);
309 channel_dimm_label_show, channel_dimm_label_store, 1);
311 channel_dimm_label_show, channel_dimm_label_store, 2);
313 channel_dimm_label_show, channel_dimm_label_store, 3);
315 channel_dimm_label_show, channel_dimm_label_store, 4);
317 channel_dimm_label_show, channel_dimm_label_store, 5);
321 &dev_attr_legacy_ch0_dimm_label.
attr,
322 &dev_attr_legacy_ch1_dimm_label.attr,
323 &dev_attr_legacy_ch2_dimm_label.attr,
324 &dev_attr_legacy_ch3_dimm_label.attr,
325 &dev_attr_legacy_ch4_dimm_label.attr,
326 &dev_attr_legacy_ch5_dimm_label.attr
331 channel_ce_count_show,
NULL, 0);
333 channel_ce_count_show,
NULL, 1);
335 channel_ce_count_show,
NULL, 2);
337 channel_ce_count_show,
NULL, 3);
339 channel_ce_count_show,
NULL, 4);
341 channel_ce_count_show,
NULL, 5);
345 &dev_attr_legacy_ch0_ce_count.
attr,
346 &dev_attr_legacy_ch1_ce_count.attr,
347 &dev_attr_legacy_ch2_ce_count.attr,
348 &dev_attr_legacy_ch3_ce_count.attr,
349 &dev_attr_legacy_ch4_ce_count.attr,
350 &dev_attr_legacy_ch5_ce_count.attr
353 static inline int nr_pages_per_csrow(
struct csrow_info *csrow)
355 int chan, nr_pages = 0;
358 nr_pages += csrow->
channels[chan]->dimm->nr_pages;
372 csrow->
dev.type = &csrow_attr_type;
373 csrow->
dev.bus = &mci->
bus;
375 csrow->
dev.parent = &mci->
dev;
379 edac_dbg(0,
"creating (virtual) csrow node %s\n",
380 dev_name(&csrow->
dev));
386 for (chan = 0; chan < csrow->
nr_channels; chan++) {
388 if (!csrow->
channels[chan]->dimm->nr_pages)
391 dynamic_csrow_dimm_attr[chan]);
395 dynamic_csrow_ce_count_attr[chan]);
398 dynamic_csrow_dimm_attr[chan]);
406 for (--chan; chan >= 0; chan--) {
408 dynamic_csrow_dimm_attr[chan]);
410 dynamic_csrow_ce_count_attr[chan]);
418 static int edac_create_csrow_objects(
struct mem_ctl_info *mci)
425 if (!nr_pages_per_csrow(csrow))
427 err = edac_create_csrow_object(mci, mci->
csrows[i], i);
434 for (--i; i >= 0; i--) {
436 if (!nr_pages_per_csrow(csrow))
438 for (chan = csrow->
nr_channels - 1; chan >= 0; chan--) {
439 if (!csrow->
channels[chan]->dimm->nr_pages)
442 dynamic_csrow_dimm_attr[chan]);
444 dynamic_csrow_ce_count_attr[chan]);
452 static void edac_delete_csrow_objects(
struct mem_ctl_info *mci)
457 for (i = mci->
nr_csrows - 1; i >= 0; i--) {
459 if (!nr_pages_per_csrow(csrow))
461 for (chan = csrow->
nr_channels - 1; chan >= 0; chan--) {
462 if (!csrow->
channels[chan]->dimm->nr_pages)
464 edac_dbg(1,
"Removing csrow %d channel %d sysfs nodes\n",
467 dynamic_csrow_dimm_attr[chan]);
469 dynamic_csrow_ce_count_attr[chan]);
481 #define to_dimm(k) container_of(k, struct dimm_info, dev)
555 dimmdev_label_show, dimmdev_label_store);
563 static struct attribute *dimm_attrs[] = {
564 &dev_attr_dimm_label.attr,
565 &dev_attr_dimm_location.attr,
567 &dev_attr_dimm_mem_type.attr,
568 &dev_attr_dimm_dev_type.attr,
569 &dev_attr_dimm_edac_mode.attr,
582 static void dimm_attr_release(
struct device *dev)
586 edac_dbg(1,
"Releasing dimm device %s\n", dev_name(dev));
591 .groups = dimm_attr_groups,
592 .release = dimm_attr_release,
596 static int edac_create_dimm_object(
struct mem_ctl_info *mci,
603 dimm->
dev.type = &dimm_attr_type;
604 dimm->
dev.bus = &mci->
bus;
607 dimm->
dev.parent = &mci->
dev;
617 edac_dbg(0,
"creating rank/dimm device %s\n", dev_name(&dimm->
dev));
626 #define to_mci(k) container_of(k, struct mem_ctl_info, dev)
630 const char *data,
size_t count)
633 int cnt, row, chan,
i;
639 for (row = 0; row < mci->
nr_csrows; row++) {
650 for (i = 0; i < mci->
n_layers; i++) {
669 static ssize_t mci_sdram_scrub_rate_store(
struct device *dev,
671 const char *data,
size_t count)
686 "Error setting scrub rate to: %lu\n", bandwidth);
712 return sprintf(data,
"%d\n", bandwidth);
775 int total_pages = 0, csrow_idx,
j;
777 for (csrow_idx = 0; csrow_idx < mci->
nr_csrows; csrow_idx++) {
798 for (i = 0; i < mci->
n_layers; i++) {
807 #ifdef CONFIG_EDAC_DEBUG
809 const char __user *data,
810 size_t count, loff_t *ppos)
815 u16 errcount = mci->fake_inject_count;
824 "Generating %d %s fake error%s to %d.%d.%d to test core handling. NOTE: this won't test the driver-specific decoding logic.\n",
827 errcount > 1 ?
"s" :
"",
828 mci->fake_inject_layer[0],
829 mci->fake_inject_layer[1],
830 mci->fake_inject_layer[2]
833 mci->fake_inject_layer[0],
834 mci->fake_inject_layer[1],
835 mci->fake_inject_layer[2],
836 "FAKE ERROR",
"for EDAC testing only");
841 static int debugfs_open(
struct inode *
inode,
struct file *file)
848 .
open = debugfs_open,
849 .write = edac_fake_inject_write,
869 mci_sdram_scrub_rate_store);
872 &dev_attr_reset_counters.attr,
873 &dev_attr_mc_name.attr,
874 &dev_attr_size_mb.attr,
875 &dev_attr_seconds_since_reset.attr,
876 &dev_attr_ue_noinfo_count.attr,
877 &dev_attr_ce_noinfo_count.attr,
878 &dev_attr_ue_count.attr,
879 &dev_attr_ce_count.attr,
880 &dev_attr_sdram_scrub_rate.attr,
881 &dev_attr_max_location.attr,
894 static void mci_attr_release(
struct device *dev)
903 .groups = mci_attr_groups,
904 .release = mci_attr_release,
907 #ifdef CONFIG_EDAC_DEBUG
908 static struct dentry *edac_debugfs;
910 int __init edac_debugfs_init(
void)
913 if (IS_ERR(edac_debugfs)) {
920 void __exit edac_debugfs_exit(
void)
939 for (i = 0; i < mci->
n_layers; i++) {
940 sprintf(name,
"fake_inject_%s",
943 &mci->fake_inject_layer[i]);
949 &mci->fake_inject_ue);
954 &mci->fake_inject_count);
960 &debug_fake_inject_fops);
964 mci->debugfs = parent;
997 mci->
dev.type = &mci_attr_type;
1000 mci->
dev.parent = mci_pdev;
1001 mci->
dev.bus = &mci->
bus;
1006 edac_dbg(0,
"creating device %s\n", dev_name(&mci->
dev));
1022 #ifdef CONFIG_EDAC_DEBUG
1023 edac_dbg(1,
"creating dimm%d, located at ", i);
1024 if (edac_debug_level >= 1) {
1026 for (lay = 0; lay < mci->
n_layers; lay++)
1033 err = edac_create_dimm_object(mci, dimm, i);
1035 edac_dbg(1,
"failure: create dimm %d obj\n", i);
1040 #ifdef CONFIG_EDAC_LEGACY_SYSFS
1041 err = edac_create_csrow_objects(mci);
1046 #ifdef CONFIG_EDAC_DEBUG
1047 edac_create_debug_nodes(mci);
1052 for (i--; i >= 0; i--) {
1075 #ifdef CONFIG_EDAC_DEBUG
1078 #ifdef CONFIG_EDAC_LEGACY_SYSFS
1079 edac_delete_csrow_objects(mci);
1086 edac_dbg(0,
"removing device %s\n", dev_name(&dimm->
dev));
1094 edac_dbg(1,
"Unregistering device %s\n", dev_name(&mci->
dev));
1101 static void mc_attr_release(
struct device *dev)
1108 edac_dbg(1,
"Releasing device %s\n", dev_name(dev));
1113 .release = mc_attr_release,
1125 if (edac_subsys ==
NULL) {
1130 mci_pdev = kzalloc(
sizeof(*mci_pdev),
GFP_KERNEL);
1133 mci_pdev->
type = &mc_attr_type;