blob: cd090b0677a78b2606f09aa2e694357003f42a2c [file] [log] [blame]
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001/*
2 * edac_mc kernel module
Douglas Thompson42a8e392007-07-19 01:50:10 -07003 * (C) 2005-2007 Linux Networx (http://lnxi.com)
4 *
Douglas Thompson7c9281d2007-07-19 01:49:33 -07005 * This file may be distributed under the terms of the
6 * GNU General Public License.
7 *
Douglas Thompson42a8e392007-07-19 01:50:10 -07008 * Written Doug Thompson <norsk5@xmission.com> www.softwarebitmaker.com
Douglas Thompson7c9281d2007-07-19 01:49:33 -07009 *
10 */
11
Douglas Thompson7c9281d2007-07-19 01:49:33 -070012#include <linux/ctype.h>
Doug Thompson8096cfa2007-07-19 01:50:27 -070013#include <linux/bug.h>
Douglas Thompson7c9281d2007-07-19 01:49:33 -070014
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070015#include "edac_core.h"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070016#include "edac_module.h"
17
Doug Thompson8096cfa2007-07-19 01:50:27 -070018
Douglas Thompson7c9281d2007-07-19 01:49:33 -070019/* MC EDAC Controls, setable by module parameter, and sysfs */
Dave Jiang4de78c62007-07-19 01:49:54 -070020static int edac_mc_log_ue = 1;
21static int edac_mc_log_ce = 1;
Douglas Thompsonf0440912007-07-19 01:50:19 -070022static int edac_mc_panic_on_ue;
Dave Jiang4de78c62007-07-19 01:49:54 -070023static int edac_mc_poll_msec = 1000;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070024
25/* Getter functions for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070026int edac_mc_get_log_ue(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070027{
Dave Jiang4de78c62007-07-19 01:49:54 -070028 return edac_mc_log_ue;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070029}
30
Dave Jiang4de78c62007-07-19 01:49:54 -070031int edac_mc_get_log_ce(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070032{
Dave Jiang4de78c62007-07-19 01:49:54 -070033 return edac_mc_log_ce;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070034}
35
Dave Jiang4de78c62007-07-19 01:49:54 -070036int edac_mc_get_panic_on_ue(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070037{
Dave Jiang4de78c62007-07-19 01:49:54 -070038 return edac_mc_panic_on_ue;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070039}
40
Dave Jiang81d87cb2007-07-19 01:49:52 -070041/* this is temporary */
42int edac_mc_get_poll_msec(void)
43{
Dave Jiang4de78c62007-07-19 01:49:54 -070044 return edac_mc_poll_msec;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070045}
46
47/* Parameter declarations for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070048module_param(edac_mc_panic_on_ue, int, 0644);
49MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
50module_param(edac_mc_log_ue, int, 0644);
51MODULE_PARM_DESC(edac_mc_log_ue,
Douglas Thompson079708b2007-07-19 01:49:58 -070052 "Log uncorrectable error to console: 0=off 1=on");
Dave Jiang4de78c62007-07-19 01:49:54 -070053module_param(edac_mc_log_ce, int, 0644);
54MODULE_PARM_DESC(edac_mc_log_ce,
Douglas Thompson079708b2007-07-19 01:49:58 -070055 "Log correctable error to console: 0=off 1=on");
Dave Jiang4de78c62007-07-19 01:49:54 -070056module_param(edac_mc_poll_msec, int, 0644);
57MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070058
Douglas Thompson7c9281d2007-07-19 01:49:33 -070059/*
60 * various constants for Memory Controllers
61 */
62static const char *mem_types[] = {
63 [MEM_EMPTY] = "Empty",
64 [MEM_RESERVED] = "Reserved",
65 [MEM_UNKNOWN] = "Unknown",
66 [MEM_FPM] = "FPM",
67 [MEM_EDO] = "EDO",
68 [MEM_BEDO] = "BEDO",
69 [MEM_SDR] = "Unbuffered-SDR",
70 [MEM_RDR] = "Registered-SDR",
71 [MEM_DDR] = "Unbuffered-DDR",
72 [MEM_RDDR] = "Registered-DDR",
Dave Jiang1a9b85e2007-07-19 01:49:38 -070073 [MEM_RMBS] = "RMBS",
74 [MEM_DDR2] = "Unbuffered-DDR2",
75 [MEM_FB_DDR2] = "FullyBuffered-DDR2",
76 [MEM_RDDR2] = "Registered-DDR2"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070077};
78
79static const char *dev_types[] = {
80 [DEV_UNKNOWN] = "Unknown",
81 [DEV_X1] = "x1",
82 [DEV_X2] = "x2",
83 [DEV_X4] = "x4",
84 [DEV_X8] = "x8",
85 [DEV_X16] = "x16",
86 [DEV_X32] = "x32",
87 [DEV_X64] = "x64"
88};
89
90static const char *edac_caps[] = {
91 [EDAC_UNKNOWN] = "Unknown",
92 [EDAC_NONE] = "None",
93 [EDAC_RESERVED] = "Reserved",
94 [EDAC_PARITY] = "PARITY",
95 [EDAC_EC] = "EC",
96 [EDAC_SECDED] = "SECDED",
97 [EDAC_S2ECD2ED] = "S2ECD2ED",
98 [EDAC_S4ECD4ED] = "S4ECD4ED",
99 [EDAC_S8ECD8ED] = "S8ECD8ED",
100 [EDAC_S16ECD16ED] = "S16ECD16ED"
101};
102
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700103
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700104
105/*
106 * /sys/devices/system/edac/mc;
107 * data structures and methods
108 */
109static ssize_t memctrl_int_show(void *ptr, char *buffer)
110{
Douglas Thompson079708b2007-07-19 01:49:58 -0700111 int *value = (int *)ptr;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700112 return sprintf(buffer, "%u\n", *value);
113}
114
115static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
116{
Douglas Thompson079708b2007-07-19 01:49:58 -0700117 int *value = (int *)ptr;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700118
119 if (isdigit(*buffer))
120 *value = simple_strtoul(buffer, NULL, 0);
121
122 return count;
123}
124
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700125
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700126/* EDAC sysfs CSROW data structures and methods
127 */
128
129/* Set of more default csrow<id> attribute show/store functions */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700130static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700131 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700132{
Douglas Thompson079708b2007-07-19 01:49:58 -0700133 return sprintf(data, "%u\n", csrow->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700134}
135
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700136static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700137 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700138{
Douglas Thompson079708b2007-07-19 01:49:58 -0700139 return sprintf(data, "%u\n", csrow->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700140}
141
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700142static ssize_t csrow_size_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700143 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700144{
Douglas Thompson079708b2007-07-19 01:49:58 -0700145 return sprintf(data, "%u\n", PAGES_TO_MiB(csrow->nr_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700146}
147
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700148static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700149 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700150{
Douglas Thompson079708b2007-07-19 01:49:58 -0700151 return sprintf(data, "%s\n", mem_types[csrow->mtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700152}
153
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700154static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700155 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700156{
Douglas Thompson079708b2007-07-19 01:49:58 -0700157 return sprintf(data, "%s\n", dev_types[csrow->dtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700158}
159
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700160static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700161 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700162{
Douglas Thompson079708b2007-07-19 01:49:58 -0700163 return sprintf(data, "%s\n", edac_caps[csrow->edac_mode]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700164}
165
166/* show/store functions for DIMM Label attributes */
167static ssize_t channel_dimm_label_show(struct csrow_info *csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700168 char *data, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700169{
Douglas Thompson079708b2007-07-19 01:49:58 -0700170 return snprintf(data, EDAC_MC_LABEL_LEN, "%s",
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700171 csrow->channels[channel].label);
172}
173
174static ssize_t channel_dimm_label_store(struct csrow_info *csrow,
Douglas Thompson079708b2007-07-19 01:49:58 -0700175 const char *data,
176 size_t count, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700177{
178 ssize_t max_size = 0;
179
Douglas Thompson079708b2007-07-19 01:49:58 -0700180 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700181 strncpy(csrow->channels[channel].label, data, max_size);
182 csrow->channels[channel].label[max_size] = '\0';
183
184 return max_size;
185}
186
187/* show function for dynamic chX_ce_count attribute */
188static ssize_t channel_ce_count_show(struct csrow_info *csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700189 char *data, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700190{
191 return sprintf(data, "%u\n", csrow->channels[channel].ce_count);
192}
193
194/* csrow specific attribute structure */
195struct csrowdev_attribute {
196 struct attribute attr;
Douglas Thompson079708b2007-07-19 01:49:58 -0700197 ssize_t(*show) (struct csrow_info *, char *, int);
198 ssize_t(*store) (struct csrow_info *, const char *, size_t, int);
199 int private;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700200};
201
202#define to_csrow(k) container_of(k, struct csrow_info, kobj)
203#define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
204
205/* Set of show/store higher level functions for default csrow attributes */
206static ssize_t csrowdev_show(struct kobject *kobj,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700207 struct attribute *attr, char *buffer)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700208{
209 struct csrow_info *csrow = to_csrow(kobj);
210 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
211
212 if (csrowdev_attr->show)
213 return csrowdev_attr->show(csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700214 buffer, csrowdev_attr->private);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700215 return -EIO;
216}
217
218static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700219 const char *buffer, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700220{
221 struct csrow_info *csrow = to_csrow(kobj);
Douglas Thompson079708b2007-07-19 01:49:58 -0700222 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700223
224 if (csrowdev_attr->store)
225 return csrowdev_attr->store(csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700226 buffer,
227 count, csrowdev_attr->private);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700228 return -EIO;
229}
230
231static struct sysfs_ops csrowfs_ops = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700232 .show = csrowdev_show,
233 .store = csrowdev_store
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700234};
235
236#define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
237static struct csrowdev_attribute attr_##_name = { \
238 .attr = {.name = __stringify(_name), .mode = _mode }, \
239 .show = _show, \
240 .store = _store, \
241 .private = _private, \
242};
243
244/* default cwrow<id>/attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700245CSROWDEV_ATTR(size_mb, S_IRUGO, csrow_size_show, NULL, 0);
246CSROWDEV_ATTR(dev_type, S_IRUGO, csrow_dev_type_show, NULL, 0);
247CSROWDEV_ATTR(mem_type, S_IRUGO, csrow_mem_type_show, NULL, 0);
248CSROWDEV_ATTR(edac_mode, S_IRUGO, csrow_edac_mode_show, NULL, 0);
249CSROWDEV_ATTR(ue_count, S_IRUGO, csrow_ue_count_show, NULL, 0);
250CSROWDEV_ATTR(ce_count, S_IRUGO, csrow_ce_count_show, NULL, 0);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700251
252/* default attributes of the CSROW<id> object */
253static struct csrowdev_attribute *default_csrow_attr[] = {
254 &attr_dev_type,
255 &attr_mem_type,
256 &attr_edac_mode,
257 &attr_size_mb,
258 &attr_ue_count,
259 &attr_ce_count,
260 NULL,
261};
262
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700263/* possible dynamic channel DIMM Label attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700264CSROWDEV_ATTR(ch0_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700265 channel_dimm_label_show, channel_dimm_label_store, 0);
Douglas Thompson079708b2007-07-19 01:49:58 -0700266CSROWDEV_ATTR(ch1_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700267 channel_dimm_label_show, channel_dimm_label_store, 1);
Douglas Thompson079708b2007-07-19 01:49:58 -0700268CSROWDEV_ATTR(ch2_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700269 channel_dimm_label_show, channel_dimm_label_store, 2);
Douglas Thompson079708b2007-07-19 01:49:58 -0700270CSROWDEV_ATTR(ch3_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700271 channel_dimm_label_show, channel_dimm_label_store, 3);
Douglas Thompson079708b2007-07-19 01:49:58 -0700272CSROWDEV_ATTR(ch4_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700273 channel_dimm_label_show, channel_dimm_label_store, 4);
Douglas Thompson079708b2007-07-19 01:49:58 -0700274CSROWDEV_ATTR(ch5_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700275 channel_dimm_label_show, channel_dimm_label_store, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700276
277/* Total possible dynamic DIMM Label attribute file table */
278static struct csrowdev_attribute *dynamic_csrow_dimm_attr[] = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700279 &attr_ch0_dimm_label,
280 &attr_ch1_dimm_label,
281 &attr_ch2_dimm_label,
282 &attr_ch3_dimm_label,
283 &attr_ch4_dimm_label,
284 &attr_ch5_dimm_label
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700285};
286
287/* possible dynamic channel ce_count attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700288CSROWDEV_ATTR(ch0_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 0);
289CSROWDEV_ATTR(ch1_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 1);
290CSROWDEV_ATTR(ch2_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 2);
291CSROWDEV_ATTR(ch3_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 3);
292CSROWDEV_ATTR(ch4_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 4);
293CSROWDEV_ATTR(ch5_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700294
295/* Total possible dynamic ce_count attribute file table */
296static struct csrowdev_attribute *dynamic_csrow_ce_count_attr[] = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700297 &attr_ch0_ce_count,
298 &attr_ch1_ce_count,
299 &attr_ch2_ce_count,
300 &attr_ch3_ce_count,
301 &attr_ch4_ce_count,
302 &attr_ch5_ce_count
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700303};
304
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700305#define EDAC_NR_CHANNELS 6
306
307/* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
308static int edac_create_channel_files(struct kobject *kobj, int chan)
309{
Douglas Thompson079708b2007-07-19 01:49:58 -0700310 int err = -ENODEV;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700311
312 if (chan >= EDAC_NR_CHANNELS)
313 return err;
314
315 /* create the DIMM label attribute file */
316 err = sysfs_create_file(kobj,
Douglas Thompson079708b2007-07-19 01:49:58 -0700317 (struct attribute *)
318 dynamic_csrow_dimm_attr[chan]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700319
320 if (!err) {
321 /* create the CE Count attribute file */
322 err = sysfs_create_file(kobj,
Douglas Thompson079708b2007-07-19 01:49:58 -0700323 (struct attribute *)
324 dynamic_csrow_ce_count_attr[chan]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700325 } else {
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700326 debugf1("%s() dimm labels and ce_count files created",
327 __func__);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700328 }
329
330 return err;
331}
332
333/* No memory to release for this kobj */
334static void edac_csrow_instance_release(struct kobject *kobj)
335{
Doug Thompson8096cfa2007-07-19 01:50:27 -0700336 struct mem_ctl_info *mci;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700337 struct csrow_info *cs;
338
Doug Thompson8096cfa2007-07-19 01:50:27 -0700339 debugf1("%s()\n", __func__);
340
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700341 cs = container_of(kobj, struct csrow_info, kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700342 mci = cs->mci;
343
344 kobject_put(&mci->edac_mci_kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700345}
346
347/* the kobj_type instance for a CSROW */
348static struct kobj_type ktype_csrow = {
349 .release = edac_csrow_instance_release,
350 .sysfs_ops = &csrowfs_ops,
Douglas Thompson079708b2007-07-19 01:49:58 -0700351 .default_attrs = (struct attribute **)default_csrow_attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700352};
353
354/* Create a CSROW object under specifed edac_mc_device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700355static int edac_create_csrow_object(struct mem_ctl_info *mci,
356 struct csrow_info *csrow, int index)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700357{
Doug Thompson8096cfa2007-07-19 01:50:27 -0700358 struct kobject *kobj_mci = &mci->edac_mci_kobj;
359 struct kobject *kobj;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700360 int chan;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700361 int err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700362
363 /* generate ..../edac/mc/mc<id>/csrow<index> */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700364 memset(&csrow->kobj, 0, sizeof(csrow->kobj));
365 csrow->mci = mci; /* include container up link */
366 csrow->kobj.parent = kobj_mci;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700367 csrow->kobj.ktype = &ktype_csrow;
368
369 /* name this instance of csrow<id> */
Douglas Thompson079708b2007-07-19 01:49:58 -0700370 err = kobject_set_name(&csrow->kobj, "csrow%d", index);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700371 if (err)
Doug Thompson8096cfa2007-07-19 01:50:27 -0700372 goto err_out;
373
374 /* bump the mci instance's kobject's ref count */
375 kobj = kobject_get(&mci->edac_mci_kobj);
376 if (!kobj) {
377 err = -ENODEV;
378 goto err_out;
379 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700380
381 /* Instanstiate the csrow object */
382 err = kobject_register(&csrow->kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700383 if (err)
384 goto err_release_top_kobj;
385
386 /* At this point, to release a csrow kobj, one must
387 * call the kobject_unregister and allow that tear down
388 * to work the releasing
389 */
390
391 /* Create the dyanmic attribute files on this csrow,
392 * namely, the DIMM labels and the channel ce_count
393 */
394 for (chan = 0; chan < csrow->nr_channels; chan++) {
395 err = edac_create_channel_files(&csrow->kobj, chan);
396 if (err) {
397 /* special case the unregister here */
398 kobject_unregister(&csrow->kobj);
399 goto err_out;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700400 }
401 }
402
Doug Thompson8096cfa2007-07-19 01:50:27 -0700403 return 0;
404
405 /* error unwind stack */
406err_release_top_kobj:
407 kobject_put(&mci->edac_mci_kobj);
408
409err_out:
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700410 return err;
411}
412
413/* default sysfs methods and data structures for the main MCI kobject */
414
415static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
Douglas Thompson079708b2007-07-19 01:49:58 -0700416 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700417{
418 int row, chan;
419
420 mci->ue_noinfo_count = 0;
421 mci->ce_noinfo_count = 0;
422 mci->ue_count = 0;
423 mci->ce_count = 0;
424
425 for (row = 0; row < mci->nr_csrows; row++) {
426 struct csrow_info *ri = &mci->csrows[row];
427
428 ri->ue_count = 0;
429 ri->ce_count = 0;
430
431 for (chan = 0; chan < ri->nr_channels; chan++)
432 ri->channels[chan].ce_count = 0;
433 }
434
435 mci->start_time = jiffies;
436 return count;
437}
438
439/* memory scrubbing */
440static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700441 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700442{
443 u32 bandwidth = -1;
444
445 if (mci->set_sdram_scrub_rate) {
446
447 memctrl_int_store(&bandwidth, data, count);
448
Douglas Thompson079708b2007-07-19 01:49:58 -0700449 if (!(*mci->set_sdram_scrub_rate) (mci, &bandwidth)) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700450 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700451 "Scrub rate set successfully, applied: %d\n",
452 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700453 } else {
454 /* FIXME: error codes maybe? */
455 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700456 "Scrub rate set FAILED, could not apply: %d\n",
457 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700458 }
459 } else {
460 /* FIXME: produce "not implemented" ERROR for user-side. */
461 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700462 "Memory scrubbing 'set'control is not implemented!\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700463 }
464 return count;
465}
466
467static ssize_t mci_sdram_scrub_rate_show(struct mem_ctl_info *mci, char *data)
468{
469 u32 bandwidth = -1;
470
471 if (mci->get_sdram_scrub_rate) {
Douglas Thompson079708b2007-07-19 01:49:58 -0700472 if (!(*mci->get_sdram_scrub_rate) (mci, &bandwidth)) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700473 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700474 "Scrub rate successfully, fetched: %d\n",
475 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700476 } else {
477 /* FIXME: error codes maybe? */
478 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700479 "Scrub rate fetch FAILED, got: %d\n",
480 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700481 }
482 } else {
483 /* FIXME: produce "not implemented" ERROR for user-side. */
484 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700485 "Memory scrubbing 'get' control is not implemented\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700486 }
487 return sprintf(data, "%d\n", bandwidth);
488}
489
490/* default attribute files for the MCI object */
491static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
492{
Douglas Thompson079708b2007-07-19 01:49:58 -0700493 return sprintf(data, "%d\n", mci->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700494}
495
496static ssize_t mci_ce_count_show(struct mem_ctl_info *mci, char *data)
497{
Douglas Thompson079708b2007-07-19 01:49:58 -0700498 return sprintf(data, "%d\n", mci->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700499}
500
501static ssize_t mci_ce_noinfo_show(struct mem_ctl_info *mci, char *data)
502{
Douglas Thompson079708b2007-07-19 01:49:58 -0700503 return sprintf(data, "%d\n", mci->ce_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700504}
505
506static ssize_t mci_ue_noinfo_show(struct mem_ctl_info *mci, char *data)
507{
Douglas Thompson079708b2007-07-19 01:49:58 -0700508 return sprintf(data, "%d\n", mci->ue_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700509}
510
511static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data)
512{
Douglas Thompson079708b2007-07-19 01:49:58 -0700513 return sprintf(data, "%ld\n", (jiffies - mci->start_time) / HZ);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700514}
515
516static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data)
517{
Douglas Thompson079708b2007-07-19 01:49:58 -0700518 return sprintf(data, "%s\n", mci->ctl_name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700519}
520
521static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
522{
523 int total_pages, csrow_idx;
524
525 for (total_pages = csrow_idx = 0; csrow_idx < mci->nr_csrows;
Douglas Thompson052dfb42007-07-19 01:50:13 -0700526 csrow_idx++) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700527 struct csrow_info *csrow = &mci->csrows[csrow_idx];
528
529 if (!csrow->nr_pages)
530 continue;
531
532 total_pages += csrow->nr_pages;
533 }
534
Douglas Thompson079708b2007-07-19 01:49:58 -0700535 return sprintf(data, "%u\n", PAGES_TO_MiB(total_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700536}
537
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700538#define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
Douglas Thompson42a8e392007-07-19 01:50:10 -0700539#define to_mcidev_attr(a) container_of(a,struct mcidev_sysfs_attribute,attr)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700540
541/* MCI show/store functions for top most object */
542static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700543 char *buffer)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700544{
545 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700546 struct mcidev_sysfs_attribute *mcidev_attr = to_mcidev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700547
548 if (mcidev_attr->show)
549 return mcidev_attr->show(mem_ctl_info, buffer);
550
551 return -EIO;
552}
553
554static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700555 const char *buffer, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700556{
557 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700558 struct mcidev_sysfs_attribute *mcidev_attr = to_mcidev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700559
560 if (mcidev_attr->store)
561 return mcidev_attr->store(mem_ctl_info, buffer, count);
562
563 return -EIO;
564}
565
Doug Thompson8096cfa2007-07-19 01:50:27 -0700566/* Intermediate show/store table */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700567static struct sysfs_ops mci_ops = {
568 .show = mcidev_show,
569 .store = mcidev_store
570};
571
572#define MCIDEV_ATTR(_name,_mode,_show,_store) \
Douglas Thompson42a8e392007-07-19 01:50:10 -0700573static struct mcidev_sysfs_attribute mci_attr_##_name = { \
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700574 .attr = {.name = __stringify(_name), .mode = _mode }, \
575 .show = _show, \
576 .store = _store, \
577};
578
579/* default Control file */
Douglas Thompson079708b2007-07-19 01:49:58 -0700580MCIDEV_ATTR(reset_counters, S_IWUSR, NULL, mci_reset_counters_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700581
582/* default Attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700583MCIDEV_ATTR(mc_name, S_IRUGO, mci_ctl_name_show, NULL);
584MCIDEV_ATTR(size_mb, S_IRUGO, mci_size_mb_show, NULL);
585MCIDEV_ATTR(seconds_since_reset, S_IRUGO, mci_seconds_show, NULL);
586MCIDEV_ATTR(ue_noinfo_count, S_IRUGO, mci_ue_noinfo_show, NULL);
587MCIDEV_ATTR(ce_noinfo_count, S_IRUGO, mci_ce_noinfo_show, NULL);
588MCIDEV_ATTR(ue_count, S_IRUGO, mci_ue_count_show, NULL);
589MCIDEV_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700590
591/* memory scrubber attribute file */
Douglas Thompson079708b2007-07-19 01:49:58 -0700592MCIDEV_ATTR(sdram_scrub_rate, S_IRUGO | S_IWUSR, mci_sdram_scrub_rate_show,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700593 mci_sdram_scrub_rate_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700594
Douglas Thompson42a8e392007-07-19 01:50:10 -0700595static struct mcidev_sysfs_attribute *mci_attr[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700596 &mci_attr_reset_counters,
597 &mci_attr_mc_name,
598 &mci_attr_size_mb,
599 &mci_attr_seconds_since_reset,
600 &mci_attr_ue_noinfo_count,
601 &mci_attr_ce_noinfo_count,
602 &mci_attr_ue_count,
603 &mci_attr_ce_count,
604 &mci_attr_sdram_scrub_rate,
605 NULL
606};
607
Doug Thompson8096cfa2007-07-19 01:50:27 -0700608
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700609/*
610 * Release of a MC controlling instance
Doug Thompson8096cfa2007-07-19 01:50:27 -0700611 *
612 * each MC control instance has the following resources upon entry:
613 * a) a ref count on the top memctl kobj
614 * b) a ref count on this module
615 *
616 * this function must decrement those ref counts and then
617 * issue a free on the instance's memory
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700618 */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700619static void edac_mci_control_release(struct kobject *kobj)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700620{
621 struct mem_ctl_info *mci;
622
623 mci = to_mci(kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700624
625 debugf0("%s() mci instance idx=%d releasing\n", __func__, mci->mc_idx);
626
627 /* decrement the module ref count */
628 module_put(mci->owner);
629
630 /* free the mci instance memory here */
631 kfree(mci);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700632}
633
634static struct kobj_type ktype_mci = {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700635 .release = edac_mci_control_release,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700636 .sysfs_ops = &mci_ops,
Douglas Thompson079708b2007-07-19 01:49:58 -0700637 .default_attrs = (struct attribute **)mci_attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700638};
639
Doug Thompson8096cfa2007-07-19 01:50:27 -0700640/* show/store, tables, etc for the MC kset */
641
642
643struct memctrl_dev_attribute {
644 struct attribute attr;
645 void *value;
646 ssize_t(*show) (void *, char *);
647 ssize_t(*store) (void *, const char *, size_t);
648};
649
650/* Set of show/store abstract level functions for memory control object */
651static ssize_t memctrl_dev_show(struct kobject *kobj,
652 struct attribute *attr, char *buffer)
653{
654 struct memctrl_dev_attribute *memctrl_dev;
655 memctrl_dev = (struct memctrl_dev_attribute *)attr;
656
657 if (memctrl_dev->show)
658 return memctrl_dev->show(memctrl_dev->value, buffer);
659
660 return -EIO;
661}
662
663static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
664 const char *buffer, size_t count)
665{
666 struct memctrl_dev_attribute *memctrl_dev;
667 memctrl_dev = (struct memctrl_dev_attribute *)attr;
668
669 if (memctrl_dev->store)
670 return memctrl_dev->store(memctrl_dev->value, buffer, count);
671
672 return -EIO;
673}
674
675static struct sysfs_ops memctrlfs_ops = {
676 .show = memctrl_dev_show,
677 .store = memctrl_dev_store
678};
679
680#define MEMCTRL_ATTR(_name, _mode, _show, _store) \
681static struct memctrl_dev_attribute attr_##_name = { \
682 .attr = {.name = __stringify(_name), .mode = _mode }, \
683 .value = &_name, \
684 .show = _show, \
685 .store = _store, \
686};
687
688#define MEMCTRL_STRING_ATTR(_name, _data, _mode, _show, _store) \
689static struct memctrl_dev_attribute attr_##_name = { \
690 .attr = {.name = __stringify(_name), .mode = _mode }, \
691 .value = _data, \
692 .show = _show, \
693 .store = _store, \
694};
695
696/* csrow<id> control files */
697MEMCTRL_ATTR(edac_mc_panic_on_ue,
698 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
699
700MEMCTRL_ATTR(edac_mc_log_ue,
701 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
702
703MEMCTRL_ATTR(edac_mc_log_ce,
704 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
705
706MEMCTRL_ATTR(edac_mc_poll_msec,
707 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
708
709/* Base Attributes of the memory ECC object */
710static struct memctrl_dev_attribute *memctrl_attr[] = {
711 &attr_edac_mc_panic_on_ue,
712 &attr_edac_mc_log_ue,
713 &attr_edac_mc_log_ce,
714 &attr_edac_mc_poll_msec,
715 NULL,
716};
717
718
719/* the ktype for the mc_kset internal kobj */
720static struct kobj_type ktype_mc_set_attribs = {
721 .sysfs_ops = &memctrlfs_ops,
722 .default_attrs = (struct attribute **)memctrl_attr,
723};
724
725/* EDAC memory controller sysfs kset:
726 * /sys/devices/system/edac/mc
727 */
728static struct kset mc_kset = {
729 .kobj = {.name = "mc", .ktype = &ktype_mc_set_attribs },
730 .ktype = &ktype_mci,
731};
732
733
734/*
735 * edac_mc_register_sysfs_main_kobj
736 *
737 * setups and registers the main kobject for each mci
738 */
739int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
740{
741 struct kobject *kobj_mci;
742 int err;
743
744 debugf1("%s()\n", __func__);
745
746 kobj_mci = &mci->edac_mci_kobj;
747
748 /* Init the mci's kobject */
749 memset(kobj_mci, 0, sizeof(*kobj_mci));
750
751 /* this instance become part of the mc_kset */
752 kobj_mci->kset = &mc_kset;
753
754 /* set the name of the mc<id> object */
755 err = kobject_set_name(kobj_mci, "mc%d", mci->mc_idx);
756 if (err)
757 goto fail_out;
758
759 /* Record which module 'owns' this control structure
760 * and bump the ref count of the module
761 */
762 mci->owner = THIS_MODULE;
763
764 /* bump ref count on this module */
765 if (!try_module_get(mci->owner)) {
766 err = -ENODEV;
767 goto fail_out;
768 }
769
770 /* register the mc<id> kobject to the mc_kset */
771 err = kobject_register(kobj_mci);
772 if (err) {
773 debugf1("%s()Failed to register '.../edac/mc%d'\n",
774 __func__, mci->mc_idx);
775 goto kobj_reg_fail;
776 }
777
778 /* At this point, to 'free' the control struct,
779 * edac_mc_unregister_sysfs_main_kobj() must be used
780 */
781
782 debugf1("%s() Registered '.../edac/mc%d' kobject\n",
783 __func__, mci->mc_idx);
784
785 return 0;
786
787 /* Error exit stack */
788
789kobj_reg_fail:
790 module_put(mci->owner);
791
792fail_out:
793 return err;
794}
795
796/*
797 * edac_mc_register_sysfs_main_kobj
798 *
799 * tears down and the main mci kobject from the mc_kset
800 */
801void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci)
802{
803 /* delete the kobj from the mc_kset */
804 kobject_unregister(&mci->edac_mci_kobj);
805}
806
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700807#define EDAC_DEVICE_SYMLINK "device"
808
809/*
Doug Thompson8096cfa2007-07-19 01:50:27 -0700810 * edac_create_mci_instance_attributes
Douglas Thompson42a8e392007-07-19 01:50:10 -0700811 * create MC driver specific attributes at the topmost level
812 * directory of this mci instance.
813 */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700814static int edac_create_mci_instance_attributes(struct mem_ctl_info *mci)
Douglas Thompson42a8e392007-07-19 01:50:10 -0700815{
816 int err;
817 struct mcidev_sysfs_attribute *sysfs_attrib;
818
819 /* point to the start of the array and iterate over it
820 * adding each attribute listed to this mci instance's kobject
821 */
822 sysfs_attrib = mci->mc_driver_sysfs_attributes;
823
Doug Thompson8096cfa2007-07-19 01:50:27 -0700824 while (sysfs_attrib && sysfs_attrib->attr.name) {
Douglas Thompson42a8e392007-07-19 01:50:10 -0700825 err = sysfs_create_file(&mci->edac_mci_kobj,
826 (struct attribute*) sysfs_attrib);
827 if (err) {
828 return err;
829 }
830
831 sysfs_attrib++;
832 }
833
834 return 0;
835}
836
837/*
Doug Thompson8096cfa2007-07-19 01:50:27 -0700838 * edac_remove_mci_instance_attributes
839 * remove MC driver specific attributes at the topmost level
840 * directory of this mci instance.
841 */
842static void edac_remove_mci_instance_attributes(struct mem_ctl_info *mci)
843{
844 struct mcidev_sysfs_attribute *sysfs_attrib;
845
846 /* point to the start of the array and iterate over it
847 * adding each attribute listed to this mci instance's kobject
848 */
849 sysfs_attrib = mci->mc_driver_sysfs_attributes;
850
851 /* loop if there are attributes and until we hit a NULL entry */
852 while (sysfs_attrib && sysfs_attrib->attr.name) {
853 sysfs_remove_file(&mci->edac_mci_kobj,
854 (struct attribute *) sysfs_attrib);
855 sysfs_attrib++;
856 }
857}
858
859
860/*
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700861 * Create a new Memory Controller kobject instance,
862 * mc<id> under the 'mc' directory
863 *
864 * Return:
865 * 0 Success
866 * !0 Failure
867 */
868int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
869{
870 int i;
871 int err;
872 struct csrow_info *csrow;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700873 struct kobject *kobj_mci = &mci->edac_mci_kobj;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700874
875 debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700876
877 /* create a symlink for the device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700878 err = sysfs_create_link(kobj_mci, &mci->dev->kobj,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700879 EDAC_DEVICE_SYMLINK);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700880 if (err) {
881 debugf1("%s() failure to create symlink\n", __func__);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700882 goto fail0;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700883 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700884
Douglas Thompson42a8e392007-07-19 01:50:10 -0700885 /* If the low level driver desires some attributes,
886 * then create them now for the driver.
887 */
888 if (mci->mc_driver_sysfs_attributes) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700889 err = edac_create_mci_instance_attributes(mci);
890 if (err) {
891 debugf1("%s() failure to create mci attributes\n",
892 __func__);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700893 goto fail0;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700894 }
Douglas Thompson42a8e392007-07-19 01:50:10 -0700895 }
896
Doug Thompson8096cfa2007-07-19 01:50:27 -0700897 /* Make directories for each CSROW object under the mc<id> kobject
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700898 */
899 for (i = 0; i < mci->nr_csrows; i++) {
900 csrow = &mci->csrows[i];
901
902 /* Only expose populated CSROWs */
903 if (csrow->nr_pages > 0) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700904 err = edac_create_csrow_object(mci, csrow, i);
905 if (err) {
906 debugf1("%s() failure: create csrow %d obj\n",
907 __func__, i);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700908 goto fail1;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700909 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700910 }
911 }
912
913 return 0;
914
915 /* CSROW error: backout what has already been registered, */
Douglas Thompson052dfb42007-07-19 01:50:13 -0700916fail1:
Douglas Thompson079708b2007-07-19 01:49:58 -0700917 for (i--; i >= 0; i--) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700918 if (csrow->nr_pages > 0) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700919 kobject_unregister(&mci->csrows[i].kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700920 }
921 }
922
Doug Thompson8096cfa2007-07-19 01:50:27 -0700923 /* remove the mci instance's attributes, if any */
924 edac_remove_mci_instance_attributes(mci);
925
926 /* remove the symlink */
927 sysfs_remove_link(kobj_mci, EDAC_DEVICE_SYMLINK);
928
Douglas Thompson052dfb42007-07-19 01:50:13 -0700929fail0:
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700930 return err;
931}
932
933/*
934 * remove a Memory Controller instance
935 */
936void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
937{
938 int i;
939
940 debugf0("%s()\n", __func__);
941
942 /* remove all csrow kobjects */
943 for (i = 0; i < mci->nr_csrows; i++) {
944 if (mci->csrows[i].nr_pages > 0) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700945 debugf0("%s() unreg csrow-%d\n", __func__, i);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700946 kobject_unregister(&mci->csrows[i].kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700947 }
948 }
949
Doug Thompson8096cfa2007-07-19 01:50:27 -0700950 debugf0("%s() remove_link\n", __func__);
951
952 /* remove the symlink */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700953 sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700954
955 debugf0("%s() remove_mci_instance\n", __func__);
956
957 /* remove this mci instance's attribtes */
958 edac_remove_mci_instance_attributes(mci);
959
960 debugf0("%s() unregister this mci kobj\n", __func__);
961
962 /* unregister this instance's kobject */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700963 kobject_unregister(&mci->edac_mci_kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700964}
Doug Thompson8096cfa2007-07-19 01:50:27 -0700965
966
967
968
969/*
970 * edac_setup_sysfs_mc_kset(void)
971 *
972 * Initialize the mc_kset for the 'mc' entry
973 * This requires creating the top 'mc' directory with a kset
974 * and its controls/attributes.
975 *
976 * To this 'mc' kset, instance 'mci' will be grouped as children.
977 *
978 * Return: 0 SUCCESS
979 * !0 FAILURE error code
980 */
981int edac_sysfs_setup_mc_kset(void)
982{
983 int err = 0;
984 struct sysdev_class *edac_class;
985
986 debugf1("%s()\n", __func__);
987
988 /* get the /sys/devices/system/edac class reference */
989 edac_class = edac_get_edac_class();
990 if (edac_class == NULL) {
991 debugf1("%s() no edac_class error=%d\n", __func__, err);
992 goto fail_out;
993 }
994
995 /* Init the MC's kobject */
996 mc_kset.kobj.parent = &edac_class->kset.kobj;
997
998 /* register the mc_kset */
999 err = kset_register(&mc_kset);
1000 if (err) {
1001 debugf1("%s() Failed to register '.../edac/mc'\n", __func__);
1002 goto fail_out;
1003 }
1004
1005 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__);
1006
1007 return 0;
1008
1009
1010 /* error unwind stack */
1011fail_out:
1012 return err;
1013}
1014
1015/*
1016 * edac_sysfs_teardown_mc_kset
1017 *
1018 * deconstruct the mc_ket for memory controllers
1019 */
1020void edac_sysfs_teardown_mc_kset(void)
1021{
1022 kset_unregister(&mc_kset);
1023}
1024