blob: 7bb9c1532b90b853f19243676374bd030de4ef16 [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
Arthur Jones096846e2008-07-25 01:49:09 -070047static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
48{
49 long l;
50 int ret;
51
52 if (!val)
53 return -EINVAL;
54
55 ret = strict_strtol(val, 0, &l);
56 if (ret == -EINVAL || ((int)l != l))
57 return -EINVAL;
58 *((int *)kp->arg) = l;
59
60 /* notify edac_mc engine to reset the poll period */
61 edac_mc_reset_delay_period(l);
62
63 return 0;
64}
65
Douglas Thompson7c9281d2007-07-19 01:49:33 -070066/* Parameter declarations for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070067module_param(edac_mc_panic_on_ue, int, 0644);
68MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
69module_param(edac_mc_log_ue, int, 0644);
70MODULE_PARM_DESC(edac_mc_log_ue,
Douglas Thompson079708b2007-07-19 01:49:58 -070071 "Log uncorrectable error to console: 0=off 1=on");
Dave Jiang4de78c62007-07-19 01:49:54 -070072module_param(edac_mc_log_ce, int, 0644);
73MODULE_PARM_DESC(edac_mc_log_ce,
Douglas Thompson079708b2007-07-19 01:49:58 -070074 "Log correctable error to console: 0=off 1=on");
Arthur Jones096846e2008-07-25 01:49:09 -070075module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int,
76 &edac_mc_poll_msec, 0644);
Dave Jiang4de78c62007-07-19 01:49:54 -070077MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070078
Douglas Thompson7c9281d2007-07-19 01:49:33 -070079/*
80 * various constants for Memory Controllers
81 */
82static const char *mem_types[] = {
83 [MEM_EMPTY] = "Empty",
84 [MEM_RESERVED] = "Reserved",
85 [MEM_UNKNOWN] = "Unknown",
86 [MEM_FPM] = "FPM",
87 [MEM_EDO] = "EDO",
88 [MEM_BEDO] = "BEDO",
89 [MEM_SDR] = "Unbuffered-SDR",
90 [MEM_RDR] = "Registered-SDR",
91 [MEM_DDR] = "Unbuffered-DDR",
92 [MEM_RDDR] = "Registered-DDR",
Dave Jiang1a9b85e2007-07-19 01:49:38 -070093 [MEM_RMBS] = "RMBS",
94 [MEM_DDR2] = "Unbuffered-DDR2",
95 [MEM_FB_DDR2] = "FullyBuffered-DDR2",
Benjamin Herrenschmidt1d5f7262008-02-07 00:14:52 -080096 [MEM_RDDR2] = "Registered-DDR2",
97 [MEM_XDR] = "XDR"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070098};
99
100static const char *dev_types[] = {
101 [DEV_UNKNOWN] = "Unknown",
102 [DEV_X1] = "x1",
103 [DEV_X2] = "x2",
104 [DEV_X4] = "x4",
105 [DEV_X8] = "x8",
106 [DEV_X16] = "x16",
107 [DEV_X32] = "x32",
108 [DEV_X64] = "x64"
109};
110
111static const char *edac_caps[] = {
112 [EDAC_UNKNOWN] = "Unknown",
113 [EDAC_NONE] = "None",
114 [EDAC_RESERVED] = "Reserved",
115 [EDAC_PARITY] = "PARITY",
116 [EDAC_EC] = "EC",
117 [EDAC_SECDED] = "SECDED",
118 [EDAC_S2ECD2ED] = "S2ECD2ED",
119 [EDAC_S4ECD4ED] = "S4ECD4ED",
120 [EDAC_S8ECD8ED] = "S8ECD8ED",
121 [EDAC_S16ECD16ED] = "S16ECD16ED"
122};
123
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700124
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700125
126/*
127 * /sys/devices/system/edac/mc;
128 * data structures and methods
129 */
130static ssize_t memctrl_int_show(void *ptr, char *buffer)
131{
Douglas Thompson079708b2007-07-19 01:49:58 -0700132 int *value = (int *)ptr;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700133 return sprintf(buffer, "%u\n", *value);
134}
135
136static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count)
137{
Douglas Thompson079708b2007-07-19 01:49:58 -0700138 int *value = (int *)ptr;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700139
140 if (isdigit(*buffer))
141 *value = simple_strtoul(buffer, NULL, 0);
142
143 return count;
144}
145
Doug Thompsonbce19682007-07-26 10:41:14 -0700146/*
147 * mc poll_msec time value
148 */
149static ssize_t poll_msec_int_store(void *ptr, const char *buffer, size_t count)
150{
151 int *value = (int *)ptr;
152
153 if (isdigit(*buffer)) {
154 *value = simple_strtoul(buffer, NULL, 0);
155
156 /* notify edac_mc engine to reset the poll period */
157 edac_mc_reset_delay_period(*value);
158 }
159
160 return count;
161}
162
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700163
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700164/* EDAC sysfs CSROW data structures and methods
165 */
166
167/* Set of more default csrow<id> attribute show/store functions */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700168static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700169 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700170{
Douglas Thompson079708b2007-07-19 01:49:58 -0700171 return sprintf(data, "%u\n", csrow->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700172}
173
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700174static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700175 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700176{
Douglas Thompson079708b2007-07-19 01:49:58 -0700177 return sprintf(data, "%u\n", csrow->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700178}
179
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700180static ssize_t csrow_size_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700181 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700182{
Douglas Thompson079708b2007-07-19 01:49:58 -0700183 return sprintf(data, "%u\n", PAGES_TO_MiB(csrow->nr_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700184}
185
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700186static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700187 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700188{
Douglas Thompson079708b2007-07-19 01:49:58 -0700189 return sprintf(data, "%s\n", mem_types[csrow->mtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700190}
191
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700192static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700193 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700194{
Douglas Thompson079708b2007-07-19 01:49:58 -0700195 return sprintf(data, "%s\n", dev_types[csrow->dtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700196}
197
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700198static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700199 int private)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700200{
Douglas Thompson079708b2007-07-19 01:49:58 -0700201 return sprintf(data, "%s\n", edac_caps[csrow->edac_mode]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700202}
203
204/* show/store functions for DIMM Label attributes */
205static ssize_t channel_dimm_label_show(struct csrow_info *csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700206 char *data, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700207{
Douglas Thompson079708b2007-07-19 01:49:58 -0700208 return snprintf(data, EDAC_MC_LABEL_LEN, "%s",
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700209 csrow->channels[channel].label);
210}
211
212static ssize_t channel_dimm_label_store(struct csrow_info *csrow,
Douglas Thompson079708b2007-07-19 01:49:58 -0700213 const char *data,
214 size_t count, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700215{
216 ssize_t max_size = 0;
217
Douglas Thompson079708b2007-07-19 01:49:58 -0700218 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700219 strncpy(csrow->channels[channel].label, data, max_size);
220 csrow->channels[channel].label[max_size] = '\0';
221
222 return max_size;
223}
224
225/* show function for dynamic chX_ce_count attribute */
226static ssize_t channel_ce_count_show(struct csrow_info *csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700227 char *data, int channel)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700228{
229 return sprintf(data, "%u\n", csrow->channels[channel].ce_count);
230}
231
232/* csrow specific attribute structure */
233struct csrowdev_attribute {
234 struct attribute attr;
Douglas Thompson079708b2007-07-19 01:49:58 -0700235 ssize_t(*show) (struct csrow_info *, char *, int);
236 ssize_t(*store) (struct csrow_info *, const char *, size_t, int);
237 int private;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700238};
239
240#define to_csrow(k) container_of(k, struct csrow_info, kobj)
241#define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr)
242
243/* Set of show/store higher level functions for default csrow attributes */
244static ssize_t csrowdev_show(struct kobject *kobj,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700245 struct attribute *attr, char *buffer)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700246{
247 struct csrow_info *csrow = to_csrow(kobj);
248 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
249
250 if (csrowdev_attr->show)
251 return csrowdev_attr->show(csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700252 buffer, csrowdev_attr->private);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700253 return -EIO;
254}
255
256static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700257 const char *buffer, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700258{
259 struct csrow_info *csrow = to_csrow(kobj);
Douglas Thompson079708b2007-07-19 01:49:58 -0700260 struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700261
262 if (csrowdev_attr->store)
263 return csrowdev_attr->store(csrow,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700264 buffer,
265 count, csrowdev_attr->private);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700266 return -EIO;
267}
268
269static struct sysfs_ops csrowfs_ops = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700270 .show = csrowdev_show,
271 .store = csrowdev_store
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700272};
273
274#define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \
275static struct csrowdev_attribute attr_##_name = { \
276 .attr = {.name = __stringify(_name), .mode = _mode }, \
277 .show = _show, \
278 .store = _store, \
279 .private = _private, \
280};
281
282/* default cwrow<id>/attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700283CSROWDEV_ATTR(size_mb, S_IRUGO, csrow_size_show, NULL, 0);
284CSROWDEV_ATTR(dev_type, S_IRUGO, csrow_dev_type_show, NULL, 0);
285CSROWDEV_ATTR(mem_type, S_IRUGO, csrow_mem_type_show, NULL, 0);
286CSROWDEV_ATTR(edac_mode, S_IRUGO, csrow_edac_mode_show, NULL, 0);
287CSROWDEV_ATTR(ue_count, S_IRUGO, csrow_ue_count_show, NULL, 0);
288CSROWDEV_ATTR(ce_count, S_IRUGO, csrow_ce_count_show, NULL, 0);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700289
290/* default attributes of the CSROW<id> object */
291static struct csrowdev_attribute *default_csrow_attr[] = {
292 &attr_dev_type,
293 &attr_mem_type,
294 &attr_edac_mode,
295 &attr_size_mb,
296 &attr_ue_count,
297 &attr_ce_count,
298 NULL,
299};
300
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700301/* possible dynamic channel DIMM Label attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700302CSROWDEV_ATTR(ch0_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700303 channel_dimm_label_show, channel_dimm_label_store, 0);
Douglas Thompson079708b2007-07-19 01:49:58 -0700304CSROWDEV_ATTR(ch1_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700305 channel_dimm_label_show, channel_dimm_label_store, 1);
Douglas Thompson079708b2007-07-19 01:49:58 -0700306CSROWDEV_ATTR(ch2_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700307 channel_dimm_label_show, channel_dimm_label_store, 2);
Douglas Thompson079708b2007-07-19 01:49:58 -0700308CSROWDEV_ATTR(ch3_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700309 channel_dimm_label_show, channel_dimm_label_store, 3);
Douglas Thompson079708b2007-07-19 01:49:58 -0700310CSROWDEV_ATTR(ch4_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700311 channel_dimm_label_show, channel_dimm_label_store, 4);
Douglas Thompson079708b2007-07-19 01:49:58 -0700312CSROWDEV_ATTR(ch5_dimm_label, S_IRUGO | S_IWUSR,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700313 channel_dimm_label_show, channel_dimm_label_store, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700314
315/* Total possible dynamic DIMM Label attribute file table */
316static struct csrowdev_attribute *dynamic_csrow_dimm_attr[] = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700317 &attr_ch0_dimm_label,
318 &attr_ch1_dimm_label,
319 &attr_ch2_dimm_label,
320 &attr_ch3_dimm_label,
321 &attr_ch4_dimm_label,
322 &attr_ch5_dimm_label
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700323};
324
325/* possible dynamic channel ce_count attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700326CSROWDEV_ATTR(ch0_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 0);
327CSROWDEV_ATTR(ch1_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 1);
328CSROWDEV_ATTR(ch2_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 2);
329CSROWDEV_ATTR(ch3_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 3);
330CSROWDEV_ATTR(ch4_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 4);
331CSROWDEV_ATTR(ch5_ce_count, S_IRUGO | S_IWUSR, channel_ce_count_show, NULL, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700332
333/* Total possible dynamic ce_count attribute file table */
334static struct csrowdev_attribute *dynamic_csrow_ce_count_attr[] = {
Douglas Thompson079708b2007-07-19 01:49:58 -0700335 &attr_ch0_ce_count,
336 &attr_ch1_ce_count,
337 &attr_ch2_ce_count,
338 &attr_ch3_ce_count,
339 &attr_ch4_ce_count,
340 &attr_ch5_ce_count
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700341};
342
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700343#define EDAC_NR_CHANNELS 6
344
345/* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */
346static int edac_create_channel_files(struct kobject *kobj, int chan)
347{
Douglas Thompson079708b2007-07-19 01:49:58 -0700348 int err = -ENODEV;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700349
350 if (chan >= EDAC_NR_CHANNELS)
351 return err;
352
353 /* create the DIMM label attribute file */
354 err = sysfs_create_file(kobj,
Douglas Thompson079708b2007-07-19 01:49:58 -0700355 (struct attribute *)
356 dynamic_csrow_dimm_attr[chan]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700357
358 if (!err) {
359 /* create the CE Count attribute file */
360 err = sysfs_create_file(kobj,
Douglas Thompson079708b2007-07-19 01:49:58 -0700361 (struct attribute *)
362 dynamic_csrow_ce_count_attr[chan]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700363 } else {
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700364 debugf1("%s() dimm labels and ce_count files created",
365 __func__);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700366 }
367
368 return err;
369}
370
371/* No memory to release for this kobj */
372static void edac_csrow_instance_release(struct kobject *kobj)
373{
Doug Thompson8096cfa2007-07-19 01:50:27 -0700374 struct mem_ctl_info *mci;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700375 struct csrow_info *cs;
376
Doug Thompson8096cfa2007-07-19 01:50:27 -0700377 debugf1("%s()\n", __func__);
378
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700379 cs = container_of(kobj, struct csrow_info, kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700380 mci = cs->mci;
381
382 kobject_put(&mci->edac_mci_kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700383}
384
385/* the kobj_type instance for a CSROW */
386static struct kobj_type ktype_csrow = {
387 .release = edac_csrow_instance_release,
388 .sysfs_ops = &csrowfs_ops,
Douglas Thompson079708b2007-07-19 01:49:58 -0700389 .default_attrs = (struct attribute **)default_csrow_attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700390};
391
392/* Create a CSROW object under specifed edac_mc_device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700393static int edac_create_csrow_object(struct mem_ctl_info *mci,
394 struct csrow_info *csrow, int index)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700395{
Doug Thompson8096cfa2007-07-19 01:50:27 -0700396 struct kobject *kobj_mci = &mci->edac_mci_kobj;
397 struct kobject *kobj;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700398 int chan;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700399 int err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700400
401 /* generate ..../edac/mc/mc<id>/csrow<index> */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700402 memset(&csrow->kobj, 0, sizeof(csrow->kobj));
403 csrow->mci = mci; /* include container up link */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700404
405 /* bump the mci instance's kobject's ref count */
406 kobj = kobject_get(&mci->edac_mci_kobj);
407 if (!kobj) {
408 err = -ENODEV;
409 goto err_out;
410 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700411
412 /* Instanstiate the csrow object */
Greg Kroah-Hartmanb2ed2152007-12-17 15:54:39 -0400413 err = kobject_init_and_add(&csrow->kobj, &ktype_csrow, kobj_mci,
414 "csrow%d", index);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700415 if (err)
416 goto err_release_top_kobj;
417
418 /* At this point, to release a csrow kobj, one must
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800419 * call the kobject_put and allow that tear down
Doug Thompson8096cfa2007-07-19 01:50:27 -0700420 * to work the releasing
421 */
422
423 /* Create the dyanmic attribute files on this csrow,
424 * namely, the DIMM labels and the channel ce_count
425 */
426 for (chan = 0; chan < csrow->nr_channels; chan++) {
427 err = edac_create_channel_files(&csrow->kobj, chan);
428 if (err) {
429 /* special case the unregister here */
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800430 kobject_put(&csrow->kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700431 goto err_out;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700432 }
433 }
Greg Kroah-Hartmanb2ed2152007-12-17 15:54:39 -0400434 kobject_uevent(&csrow->kobj, KOBJ_ADD);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700435 return 0;
436
437 /* error unwind stack */
438err_release_top_kobj:
439 kobject_put(&mci->edac_mci_kobj);
440
441err_out:
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700442 return err;
443}
444
445/* default sysfs methods and data structures for the main MCI kobject */
446
447static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
Douglas Thompson079708b2007-07-19 01:49:58 -0700448 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700449{
450 int row, chan;
451
452 mci->ue_noinfo_count = 0;
453 mci->ce_noinfo_count = 0;
454 mci->ue_count = 0;
455 mci->ce_count = 0;
456
457 for (row = 0; row < mci->nr_csrows; row++) {
458 struct csrow_info *ri = &mci->csrows[row];
459
460 ri->ue_count = 0;
461 ri->ce_count = 0;
462
463 for (chan = 0; chan < ri->nr_channels; chan++)
464 ri->channels[chan].ce_count = 0;
465 }
466
467 mci->start_time = jiffies;
468 return count;
469}
470
471/* memory scrubbing */
472static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700473 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700474{
475 u32 bandwidth = -1;
476
477 if (mci->set_sdram_scrub_rate) {
478
479 memctrl_int_store(&bandwidth, data, count);
480
Douglas Thompson079708b2007-07-19 01:49:58 -0700481 if (!(*mci->set_sdram_scrub_rate) (mci, &bandwidth)) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700482 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700483 "Scrub rate set successfully, applied: %d\n",
484 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700485 } else {
486 /* FIXME: error codes maybe? */
487 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700488 "Scrub rate set FAILED, could not apply: %d\n",
489 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700490 }
491 } else {
492 /* FIXME: produce "not implemented" ERROR for user-side. */
493 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700494 "Memory scrubbing 'set'control is not implemented!\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700495 }
496 return count;
497}
498
499static ssize_t mci_sdram_scrub_rate_show(struct mem_ctl_info *mci, char *data)
500{
501 u32 bandwidth = -1;
502
503 if (mci->get_sdram_scrub_rate) {
Douglas Thompson079708b2007-07-19 01:49:58 -0700504 if (!(*mci->get_sdram_scrub_rate) (mci, &bandwidth)) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700505 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700506 "Scrub rate successfully, fetched: %d\n",
507 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700508 } else {
509 /* FIXME: error codes maybe? */
510 edac_printk(KERN_DEBUG, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700511 "Scrub rate fetch FAILED, got: %d\n",
512 bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700513 }
514 } else {
515 /* FIXME: produce "not implemented" ERROR for user-side. */
516 edac_printk(KERN_WARNING, EDAC_MC,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700517 "Memory scrubbing 'get' control is not implemented\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700518 }
519 return sprintf(data, "%d\n", bandwidth);
520}
521
522/* default attribute files for the MCI object */
523static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
524{
Douglas Thompson079708b2007-07-19 01:49:58 -0700525 return sprintf(data, "%d\n", mci->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700526}
527
528static ssize_t mci_ce_count_show(struct mem_ctl_info *mci, char *data)
529{
Douglas Thompson079708b2007-07-19 01:49:58 -0700530 return sprintf(data, "%d\n", mci->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700531}
532
533static ssize_t mci_ce_noinfo_show(struct mem_ctl_info *mci, char *data)
534{
Douglas Thompson079708b2007-07-19 01:49:58 -0700535 return sprintf(data, "%d\n", mci->ce_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700536}
537
538static ssize_t mci_ue_noinfo_show(struct mem_ctl_info *mci, char *data)
539{
Douglas Thompson079708b2007-07-19 01:49:58 -0700540 return sprintf(data, "%d\n", mci->ue_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700541}
542
543static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data)
544{
Douglas Thompson079708b2007-07-19 01:49:58 -0700545 return sprintf(data, "%ld\n", (jiffies - mci->start_time) / HZ);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700546}
547
548static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data)
549{
Douglas Thompson079708b2007-07-19 01:49:58 -0700550 return sprintf(data, "%s\n", mci->ctl_name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700551}
552
553static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data)
554{
555 int total_pages, csrow_idx;
556
557 for (total_pages = csrow_idx = 0; csrow_idx < mci->nr_csrows;
Douglas Thompson052dfb42007-07-19 01:50:13 -0700558 csrow_idx++) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700559 struct csrow_info *csrow = &mci->csrows[csrow_idx];
560
561 if (!csrow->nr_pages)
562 continue;
563
564 total_pages += csrow->nr_pages;
565 }
566
Douglas Thompson079708b2007-07-19 01:49:58 -0700567 return sprintf(data, "%u\n", PAGES_TO_MiB(total_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700568}
569
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700570#define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj)
Douglas Thompson42a8e392007-07-19 01:50:10 -0700571#define to_mcidev_attr(a) container_of(a,struct mcidev_sysfs_attribute,attr)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700572
573/* MCI show/store functions for top most object */
574static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700575 char *buffer)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700576{
577 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700578 struct mcidev_sysfs_attribute *mcidev_attr = to_mcidev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700579
580 if (mcidev_attr->show)
581 return mcidev_attr->show(mem_ctl_info, buffer);
582
583 return -EIO;
584}
585
586static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700587 const char *buffer, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700588{
589 struct mem_ctl_info *mem_ctl_info = to_mci(kobj);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700590 struct mcidev_sysfs_attribute *mcidev_attr = to_mcidev_attr(attr);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700591
592 if (mcidev_attr->store)
593 return mcidev_attr->store(mem_ctl_info, buffer, count);
594
595 return -EIO;
596}
597
Doug Thompson8096cfa2007-07-19 01:50:27 -0700598/* Intermediate show/store table */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700599static struct sysfs_ops mci_ops = {
600 .show = mcidev_show,
601 .store = mcidev_store
602};
603
604#define MCIDEV_ATTR(_name,_mode,_show,_store) \
Douglas Thompson42a8e392007-07-19 01:50:10 -0700605static struct mcidev_sysfs_attribute mci_attr_##_name = { \
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700606 .attr = {.name = __stringify(_name), .mode = _mode }, \
607 .show = _show, \
608 .store = _store, \
609};
610
611/* default Control file */
Douglas Thompson079708b2007-07-19 01:49:58 -0700612MCIDEV_ATTR(reset_counters, S_IWUSR, NULL, mci_reset_counters_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700613
614/* default Attribute files */
Douglas Thompson079708b2007-07-19 01:49:58 -0700615MCIDEV_ATTR(mc_name, S_IRUGO, mci_ctl_name_show, NULL);
616MCIDEV_ATTR(size_mb, S_IRUGO, mci_size_mb_show, NULL);
617MCIDEV_ATTR(seconds_since_reset, S_IRUGO, mci_seconds_show, NULL);
618MCIDEV_ATTR(ue_noinfo_count, S_IRUGO, mci_ue_noinfo_show, NULL);
619MCIDEV_ATTR(ce_noinfo_count, S_IRUGO, mci_ce_noinfo_show, NULL);
620MCIDEV_ATTR(ue_count, S_IRUGO, mci_ue_count_show, NULL);
621MCIDEV_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700622
623/* memory scrubber attribute file */
Douglas Thompson079708b2007-07-19 01:49:58 -0700624MCIDEV_ATTR(sdram_scrub_rate, S_IRUGO | S_IWUSR, mci_sdram_scrub_rate_show,
Douglas Thompson052dfb42007-07-19 01:50:13 -0700625 mci_sdram_scrub_rate_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700626
Douglas Thompson42a8e392007-07-19 01:50:10 -0700627static struct mcidev_sysfs_attribute *mci_attr[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700628 &mci_attr_reset_counters,
629 &mci_attr_mc_name,
630 &mci_attr_size_mb,
631 &mci_attr_seconds_since_reset,
632 &mci_attr_ue_noinfo_count,
633 &mci_attr_ce_noinfo_count,
634 &mci_attr_ue_count,
635 &mci_attr_ce_count,
636 &mci_attr_sdram_scrub_rate,
637 NULL
638};
639
Doug Thompson8096cfa2007-07-19 01:50:27 -0700640
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700641/*
642 * Release of a MC controlling instance
Doug Thompson8096cfa2007-07-19 01:50:27 -0700643 *
644 * each MC control instance has the following resources upon entry:
645 * a) a ref count on the top memctl kobj
646 * b) a ref count on this module
647 *
648 * this function must decrement those ref counts and then
649 * issue a free on the instance's memory
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700650 */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700651static void edac_mci_control_release(struct kobject *kobj)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700652{
653 struct mem_ctl_info *mci;
654
655 mci = to_mci(kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700656
657 debugf0("%s() mci instance idx=%d releasing\n", __func__, mci->mc_idx);
658
659 /* decrement the module ref count */
660 module_put(mci->owner);
661
662 /* free the mci instance memory here */
663 kfree(mci);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700664}
665
666static struct kobj_type ktype_mci = {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700667 .release = edac_mci_control_release,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700668 .sysfs_ops = &mci_ops,
Douglas Thompson079708b2007-07-19 01:49:58 -0700669 .default_attrs = (struct attribute **)mci_attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700670};
671
Doug Thompson8096cfa2007-07-19 01:50:27 -0700672/* show/store, tables, etc for the MC kset */
673
674
675struct memctrl_dev_attribute {
676 struct attribute attr;
677 void *value;
678 ssize_t(*show) (void *, char *);
679 ssize_t(*store) (void *, const char *, size_t);
680};
681
682/* Set of show/store abstract level functions for memory control object */
683static ssize_t memctrl_dev_show(struct kobject *kobj,
684 struct attribute *attr, char *buffer)
685{
686 struct memctrl_dev_attribute *memctrl_dev;
687 memctrl_dev = (struct memctrl_dev_attribute *)attr;
688
689 if (memctrl_dev->show)
690 return memctrl_dev->show(memctrl_dev->value, buffer);
691
692 return -EIO;
693}
694
695static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr,
696 const char *buffer, size_t count)
697{
698 struct memctrl_dev_attribute *memctrl_dev;
699 memctrl_dev = (struct memctrl_dev_attribute *)attr;
700
701 if (memctrl_dev->store)
702 return memctrl_dev->store(memctrl_dev->value, buffer, count);
703
704 return -EIO;
705}
706
707static struct sysfs_ops memctrlfs_ops = {
708 .show = memctrl_dev_show,
709 .store = memctrl_dev_store
710};
711
712#define MEMCTRL_ATTR(_name, _mode, _show, _store) \
713static struct memctrl_dev_attribute attr_##_name = { \
714 .attr = {.name = __stringify(_name), .mode = _mode }, \
715 .value = &_name, \
716 .show = _show, \
717 .store = _store, \
718};
719
720#define MEMCTRL_STRING_ATTR(_name, _data, _mode, _show, _store) \
721static struct memctrl_dev_attribute attr_##_name = { \
722 .attr = {.name = __stringify(_name), .mode = _mode }, \
723 .value = _data, \
724 .show = _show, \
725 .store = _store, \
726};
727
728/* csrow<id> control files */
729MEMCTRL_ATTR(edac_mc_panic_on_ue,
730 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
731
732MEMCTRL_ATTR(edac_mc_log_ue,
733 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
734
735MEMCTRL_ATTR(edac_mc_log_ce,
736 S_IRUGO | S_IWUSR, memctrl_int_show, memctrl_int_store);
737
738MEMCTRL_ATTR(edac_mc_poll_msec,
Doug Thompsonbce19682007-07-26 10:41:14 -0700739 S_IRUGO | S_IWUSR, memctrl_int_show, poll_msec_int_store);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700740
741/* Base Attributes of the memory ECC object */
742static struct memctrl_dev_attribute *memctrl_attr[] = {
743 &attr_edac_mc_panic_on_ue,
744 &attr_edac_mc_log_ue,
745 &attr_edac_mc_log_ce,
746 &attr_edac_mc_poll_msec,
747 NULL,
748};
749
750
751/* the ktype for the mc_kset internal kobj */
752static struct kobj_type ktype_mc_set_attribs = {
753 .sysfs_ops = &memctrlfs_ops,
754 .default_attrs = (struct attribute **)memctrl_attr,
755};
756
757/* EDAC memory controller sysfs kset:
758 * /sys/devices/system/edac/mc
759 */
760static struct kset mc_kset = {
Greg Kroah-Hartman34980ca2007-09-12 15:06:57 -0700761 .kobj = {.ktype = &ktype_mc_set_attribs },
Doug Thompson8096cfa2007-07-19 01:50:27 -0700762};
763
764
765/*
766 * edac_mc_register_sysfs_main_kobj
767 *
768 * setups and registers the main kobject for each mci
769 */
770int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
771{
772 struct kobject *kobj_mci;
773 int err;
774
775 debugf1("%s()\n", __func__);
776
777 kobj_mci = &mci->edac_mci_kobj;
778
779 /* Init the mci's kobject */
780 memset(kobj_mci, 0, sizeof(*kobj_mci));
781
Doug Thompson8096cfa2007-07-19 01:50:27 -0700782 /* Record which module 'owns' this control structure
783 * and bump the ref count of the module
784 */
785 mci->owner = THIS_MODULE;
786
787 /* bump ref count on this module */
788 if (!try_module_get(mci->owner)) {
789 err = -ENODEV;
790 goto fail_out;
791 }
792
Greg Kroah-Hartmanb2ed2152007-12-17 15:54:39 -0400793 /* this instance become part of the mc_kset */
794 kobj_mci->kset = &mc_kset;
795
Doug Thompson8096cfa2007-07-19 01:50:27 -0700796 /* register the mc<id> kobject to the mc_kset */
Greg Kroah-Hartmanb2ed2152007-12-17 15:54:39 -0400797 err = kobject_init_and_add(kobj_mci, &ktype_mci, NULL,
798 "mc%d", mci->mc_idx);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700799 if (err) {
800 debugf1("%s()Failed to register '.../edac/mc%d'\n",
801 __func__, mci->mc_idx);
802 goto kobj_reg_fail;
803 }
Greg Kroah-Hartmanb2ed2152007-12-17 15:54:39 -0400804 kobject_uevent(kobj_mci, KOBJ_ADD);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700805
806 /* At this point, to 'free' the control struct,
807 * edac_mc_unregister_sysfs_main_kobj() must be used
808 */
809
810 debugf1("%s() Registered '.../edac/mc%d' kobject\n",
811 __func__, mci->mc_idx);
812
813 return 0;
814
815 /* Error exit stack */
816
817kobj_reg_fail:
818 module_put(mci->owner);
819
820fail_out:
821 return err;
822}
823
824/*
825 * edac_mc_register_sysfs_main_kobj
826 *
827 * tears down and the main mci kobject from the mc_kset
828 */
829void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci)
830{
831 /* delete the kobj from the mc_kset */
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800832 kobject_put(&mci->edac_mci_kobj);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700833}
834
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700835#define EDAC_DEVICE_SYMLINK "device"
836
837/*
Doug Thompson8096cfa2007-07-19 01:50:27 -0700838 * edac_create_mci_instance_attributes
Douglas Thompson42a8e392007-07-19 01:50:10 -0700839 * create MC driver specific attributes at the topmost level
840 * directory of this mci instance.
841 */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700842static int edac_create_mci_instance_attributes(struct mem_ctl_info *mci)
Douglas Thompson42a8e392007-07-19 01:50:10 -0700843{
844 int err;
845 struct mcidev_sysfs_attribute *sysfs_attrib;
846
847 /* point to the start of the array and iterate over it
848 * adding each attribute listed to this mci instance's kobject
849 */
850 sysfs_attrib = mci->mc_driver_sysfs_attributes;
851
Doug Thompson8096cfa2007-07-19 01:50:27 -0700852 while (sysfs_attrib && sysfs_attrib->attr.name) {
Douglas Thompson42a8e392007-07-19 01:50:10 -0700853 err = sysfs_create_file(&mci->edac_mci_kobj,
854 (struct attribute*) sysfs_attrib);
855 if (err) {
856 return err;
857 }
858
859 sysfs_attrib++;
860 }
861
862 return 0;
863}
864
865/*
Doug Thompson8096cfa2007-07-19 01:50:27 -0700866 * edac_remove_mci_instance_attributes
867 * remove MC driver specific attributes at the topmost level
868 * directory of this mci instance.
869 */
870static void edac_remove_mci_instance_attributes(struct mem_ctl_info *mci)
871{
872 struct mcidev_sysfs_attribute *sysfs_attrib;
873
874 /* point to the start of the array and iterate over it
875 * adding each attribute listed to this mci instance's kobject
876 */
877 sysfs_attrib = mci->mc_driver_sysfs_attributes;
878
879 /* loop if there are attributes and until we hit a NULL entry */
880 while (sysfs_attrib && sysfs_attrib->attr.name) {
881 sysfs_remove_file(&mci->edac_mci_kobj,
882 (struct attribute *) sysfs_attrib);
883 sysfs_attrib++;
884 }
885}
886
887
888/*
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700889 * Create a new Memory Controller kobject instance,
890 * mc<id> under the 'mc' directory
891 *
892 * Return:
893 * 0 Success
894 * !0 Failure
895 */
896int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
897{
898 int i;
899 int err;
900 struct csrow_info *csrow;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700901 struct kobject *kobj_mci = &mci->edac_mci_kobj;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700902
903 debugf0("%s() idx=%d\n", __func__, mci->mc_idx);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700904
905 /* create a symlink for the device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700906 err = sysfs_create_link(kobj_mci, &mci->dev->kobj,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700907 EDAC_DEVICE_SYMLINK);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700908 if (err) {
909 debugf1("%s() failure to create symlink\n", __func__);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700910 goto fail0;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700911 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700912
Douglas Thompson42a8e392007-07-19 01:50:10 -0700913 /* If the low level driver desires some attributes,
914 * then create them now for the driver.
915 */
916 if (mci->mc_driver_sysfs_attributes) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700917 err = edac_create_mci_instance_attributes(mci);
918 if (err) {
919 debugf1("%s() failure to create mci attributes\n",
920 __func__);
Douglas Thompson42a8e392007-07-19 01:50:10 -0700921 goto fail0;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700922 }
Douglas Thompson42a8e392007-07-19 01:50:10 -0700923 }
924
Doug Thompson8096cfa2007-07-19 01:50:27 -0700925 /* Make directories for each CSROW object under the mc<id> kobject
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700926 */
927 for (i = 0; i < mci->nr_csrows; i++) {
928 csrow = &mci->csrows[i];
929
930 /* Only expose populated CSROWs */
931 if (csrow->nr_pages > 0) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700932 err = edac_create_csrow_object(mci, csrow, i);
933 if (err) {
934 debugf1("%s() failure: create csrow %d obj\n",
935 __func__, i);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700936 goto fail1;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700937 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700938 }
939 }
940
941 return 0;
942
943 /* CSROW error: backout what has already been registered, */
Douglas Thompson052dfb42007-07-19 01:50:13 -0700944fail1:
Douglas Thompson079708b2007-07-19 01:49:58 -0700945 for (i--; i >= 0; i--) {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700946 if (csrow->nr_pages > 0) {
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800947 kobject_put(&mci->csrows[i].kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700948 }
949 }
950
Doug Thompson8096cfa2007-07-19 01:50:27 -0700951 /* remove the mci instance's attributes, if any */
952 edac_remove_mci_instance_attributes(mci);
953
954 /* remove the symlink */
955 sysfs_remove_link(kobj_mci, EDAC_DEVICE_SYMLINK);
956
Douglas Thompson052dfb42007-07-19 01:50:13 -0700957fail0:
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700958 return err;
959}
960
961/*
962 * remove a Memory Controller instance
963 */
964void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
965{
966 int i;
967
968 debugf0("%s()\n", __func__);
969
970 /* remove all csrow kobjects */
971 for (i = 0; i < mci->nr_csrows; i++) {
972 if (mci->csrows[i].nr_pages > 0) {
Doug Thompson8096cfa2007-07-19 01:50:27 -0700973 debugf0("%s() unreg csrow-%d\n", __func__, i);
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800974 kobject_put(&mci->csrows[i].kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700975 }
976 }
977
Doug Thompson8096cfa2007-07-19 01:50:27 -0700978 debugf0("%s() remove_link\n", __func__);
979
980 /* remove the symlink */
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700981 sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700982
983 debugf0("%s() remove_mci_instance\n", __func__);
984
985 /* remove this mci instance's attribtes */
986 edac_remove_mci_instance_attributes(mci);
987
988 debugf0("%s() unregister this mci kobj\n", __func__);
989
990 /* unregister this instance's kobject */
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800991 kobject_put(&mci->edac_mci_kobj);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700992}
Doug Thompson8096cfa2007-07-19 01:50:27 -0700993
994
995
996
997/*
998 * edac_setup_sysfs_mc_kset(void)
999 *
1000 * Initialize the mc_kset for the 'mc' entry
1001 * This requires creating the top 'mc' directory with a kset
1002 * and its controls/attributes.
1003 *
1004 * To this 'mc' kset, instance 'mci' will be grouped as children.
1005 *
1006 * Return: 0 SUCCESS
1007 * !0 FAILURE error code
1008 */
1009int edac_sysfs_setup_mc_kset(void)
1010{
1011 int err = 0;
1012 struct sysdev_class *edac_class;
1013
1014 debugf1("%s()\n", __func__);
1015
1016 /* get the /sys/devices/system/edac class reference */
1017 edac_class = edac_get_edac_class();
1018 if (edac_class == NULL) {
1019 debugf1("%s() no edac_class error=%d\n", __func__, err);
1020 goto fail_out;
1021 }
1022
1023 /* Init the MC's kobject */
Greg Kroah-Hartman34980ca2007-09-12 15:06:57 -07001024 kobject_set_name(&mc_kset.kobj, "mc");
Doug Thompson8096cfa2007-07-19 01:50:27 -07001025 mc_kset.kobj.parent = &edac_class->kset.kobj;
1026
1027 /* register the mc_kset */
1028 err = kset_register(&mc_kset);
1029 if (err) {
1030 debugf1("%s() Failed to register '.../edac/mc'\n", __func__);
1031 goto fail_out;
1032 }
1033
1034 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__);
1035
1036 return 0;
1037
1038
1039 /* error unwind stack */
1040fail_out:
1041 return err;
1042}
1043
1044/*
1045 * edac_sysfs_teardown_mc_kset
1046 *
1047 * deconstruct the mc_ket for memory controllers
1048 */
1049void edac_sysfs_teardown_mc_kset(void)
1050{
1051 kset_unregister(&mc_kset);
1052}
1053