]>
Commit | Line | Data |
---|---|---|
7c9281d7 DT |
1 | /* |
2 | * edac_mc kernel module | |
3 | * (C) 2005, 2006 Linux Networx (http://lnxi.com) | |
4 | * This file may be distributed under the terms of the | |
5 | * GNU General Public License. | |
6 | * | |
7 | * Written Doug Thompson <norsk5@xmission.com> | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/sysdev.h> | |
13 | #include <linux/ctype.h> | |
14 | ||
20bcb7a8 | 15 | #include "edac_core.h" |
7c9281d7 DT |
16 | #include "edac_module.h" |
17 | ||
18 | /* MC EDAC Controls, setable by module parameter, and sysfs */ | |
4de78c68 DJ |
19 | static int edac_mc_log_ue = 1; |
20 | static int edac_mc_log_ce = 1; | |
21 | static int edac_mc_panic_on_ue = 0; | |
22 | static int edac_mc_poll_msec = 1000; | |
7c9281d7 DT |
23 | |
24 | /* Getter functions for above */ | |
4de78c68 | 25 | int edac_mc_get_log_ue(void) |
7c9281d7 | 26 | { |
4de78c68 | 27 | return edac_mc_log_ue; |
7c9281d7 DT |
28 | } |
29 | ||
4de78c68 | 30 | int edac_mc_get_log_ce(void) |
7c9281d7 | 31 | { |
4de78c68 | 32 | return edac_mc_log_ce; |
7c9281d7 DT |
33 | } |
34 | ||
4de78c68 | 35 | int edac_mc_get_panic_on_ue(void) |
7c9281d7 | 36 | { |
4de78c68 | 37 | return edac_mc_panic_on_ue; |
7c9281d7 DT |
38 | } |
39 | ||
81d87cb1 DJ |
40 | /* this is temporary */ |
41 | int edac_mc_get_poll_msec(void) | |
42 | { | |
4de78c68 | 43 | return edac_mc_poll_msec; |
7c9281d7 DT |
44 | } |
45 | ||
46 | /* Parameter declarations for above */ | |
4de78c68 DJ |
47 | module_param(edac_mc_panic_on_ue, int, 0644); |
48 | MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on"); | |
49 | module_param(edac_mc_log_ue, int, 0644); | |
50 | MODULE_PARM_DESC(edac_mc_log_ue, | |
51 | "Log uncorrectable error to console: 0=off 1=on"); | |
52 | module_param(edac_mc_log_ce, int, 0644); | |
53 | MODULE_PARM_DESC(edac_mc_log_ce, | |
54 | "Log correctable error to console: 0=off 1=on"); | |
55 | module_param(edac_mc_poll_msec, int, 0644); | |
56 | MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds"); | |
7c9281d7 DT |
57 | |
58 | ||
59 | /* | |
60 | * various constants for Memory Controllers | |
61 | */ | |
62 | static 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", | |
1a9b85e6 DJ |
73 | [MEM_RMBS] = "RMBS", |
74 | [MEM_DDR2] = "Unbuffered-DDR2", | |
75 | [MEM_FB_DDR2] = "FullyBuffered-DDR2", | |
76 | [MEM_RDDR2] = "Registered-DDR2" | |
7c9281d7 DT |
77 | }; |
78 | ||
79 | static 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 | ||
90 | static 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 | ||
7c9281d7 DT |
103 | /* sysfs object: |
104 | * /sys/devices/system/edac/mc | |
105 | */ | |
106 | static struct kobject edac_memctrl_kobj; | |
107 | ||
108 | /* We use these to wait for the reference counts on edac_memctrl_kobj and | |
109 | * edac_pci_kobj to reach 0. | |
110 | */ | |
111 | static struct completion edac_memctrl_kobj_complete; | |
112 | ||
113 | /* | |
114 | * /sys/devices/system/edac/mc; | |
115 | * data structures and methods | |
116 | */ | |
117 | static ssize_t memctrl_int_show(void *ptr, char *buffer) | |
118 | { | |
119 | int *value = (int*) ptr; | |
120 | return sprintf(buffer, "%u\n", *value); | |
121 | } | |
122 | ||
123 | static ssize_t memctrl_int_store(void *ptr, const char *buffer, size_t count) | |
124 | { | |
125 | int *value = (int*) ptr; | |
126 | ||
127 | if (isdigit(*buffer)) | |
128 | *value = simple_strtoul(buffer, NULL, 0); | |
129 | ||
130 | return count; | |
131 | } | |
132 | ||
133 | struct memctrl_dev_attribute { | |
134 | struct attribute attr; | |
135 | void *value; | |
136 | ssize_t (*show)(void *,char *); | |
137 | ssize_t (*store)(void *, const char *, size_t); | |
138 | }; | |
139 | ||
140 | /* Set of show/store abstract level functions for memory control object */ | |
141 | static ssize_t memctrl_dev_show(struct kobject *kobj, | |
142 | struct attribute *attr, char *buffer) | |
143 | { | |
144 | struct memctrl_dev_attribute *memctrl_dev; | |
145 | memctrl_dev = (struct memctrl_dev_attribute*)attr; | |
146 | ||
147 | if (memctrl_dev->show) | |
148 | return memctrl_dev->show(memctrl_dev->value, buffer); | |
149 | ||
150 | return -EIO; | |
151 | } | |
152 | ||
153 | static ssize_t memctrl_dev_store(struct kobject *kobj, struct attribute *attr, | |
154 | const char *buffer, size_t count) | |
155 | { | |
156 | struct memctrl_dev_attribute *memctrl_dev; | |
157 | memctrl_dev = (struct memctrl_dev_attribute*)attr; | |
158 | ||
159 | if (memctrl_dev->store) | |
160 | return memctrl_dev->store(memctrl_dev->value, buffer, count); | |
161 | ||
162 | return -EIO; | |
163 | } | |
164 | ||
165 | static struct sysfs_ops memctrlfs_ops = { | |
166 | .show = memctrl_dev_show, | |
167 | .store = memctrl_dev_store | |
168 | }; | |
169 | ||
170 | #define MEMCTRL_ATTR(_name,_mode,_show,_store) \ | |
171 | static struct memctrl_dev_attribute attr_##_name = { \ | |
172 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | |
173 | .value = &_name, \ | |
174 | .show = _show, \ | |
175 | .store = _store, \ | |
176 | }; | |
177 | ||
178 | #define MEMCTRL_STRING_ATTR(_name,_data,_mode,_show,_store) \ | |
179 | static struct memctrl_dev_attribute attr_##_name = { \ | |
180 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | |
181 | .value = _data, \ | |
182 | .show = _show, \ | |
183 | .store = _store, \ | |
184 | }; | |
185 | ||
186 | /* csrow<id> control files */ | |
4de78c68 DJ |
187 | MEMCTRL_ATTR(edac_mc_panic_on_ue, |
188 | S_IRUGO | S_IWUSR, | |
189 | memctrl_int_show, | |
190 | memctrl_int_store); | |
191 | ||
192 | MEMCTRL_ATTR(edac_mc_log_ue, | |
193 | S_IRUGO|S_IWUSR, | |
194 | memctrl_int_show, | |
195 | memctrl_int_store); | |
196 | ||
197 | MEMCTRL_ATTR(edac_mc_log_ce, | |
198 | S_IRUGO|S_IWUSR, | |
199 | memctrl_int_show, | |
200 | memctrl_int_store); | |
201 | ||
202 | MEMCTRL_ATTR(edac_mc_poll_msec, | |
203 | S_IRUGO|S_IWUSR, | |
204 | memctrl_int_show, | |
205 | memctrl_int_store); | |
7c9281d7 DT |
206 | |
207 | /* Base Attributes of the memory ECC object */ | |
208 | static struct memctrl_dev_attribute *memctrl_attr[] = { | |
4de78c68 DJ |
209 | &attr_edac_mc_panic_on_ue, |
210 | &attr_edac_mc_log_ue, | |
211 | &attr_edac_mc_log_ce, | |
212 | &attr_edac_mc_poll_msec, | |
7c9281d7 DT |
213 | NULL, |
214 | }; | |
215 | ||
216 | /* Main MC kobject release() function */ | |
217 | static void edac_memctrl_master_release(struct kobject *kobj) | |
218 | { | |
219 | debugf1("%s()\n", __func__); | |
220 | complete(&edac_memctrl_kobj_complete); | |
221 | } | |
222 | ||
223 | static struct kobj_type ktype_memctrl = { | |
224 | .release = edac_memctrl_master_release, | |
225 | .sysfs_ops = &memctrlfs_ops, | |
226 | .default_attrs = (struct attribute **) memctrl_attr, | |
227 | }; | |
228 | ||
229 | /* Initialize the main sysfs entries for edac: | |
230 | * /sys/devices/system/edac | |
231 | * | |
232 | * and children | |
233 | * | |
234 | * Return: 0 SUCCESS | |
235 | * !0 FAILURE | |
236 | */ | |
237 | int edac_sysfs_memctrl_setup(void) | |
238 | { | |
239 | int err = 0; | |
e27e3dac | 240 | struct sysdev_class *edac_class; |
7c9281d7 DT |
241 | |
242 | debugf1("%s()\n", __func__); | |
243 | ||
e27e3dac DT |
244 | /* get the /sys/devices/system/edac class reference */ |
245 | edac_class = edac_get_edac_class(); | |
246 | if (edac_class == NULL) { | |
247 | debugf1("%s() no edac_class error=%d\n", __func__, err); | |
7c9281d7 DT |
248 | return err; |
249 | } | |
250 | ||
251 | /* Init the MC's kobject */ | |
252 | memset(&edac_memctrl_kobj, 0, sizeof (edac_memctrl_kobj)); | |
e27e3dac | 253 | edac_memctrl_kobj.parent = &edac_class->kset.kobj; |
7c9281d7 DT |
254 | edac_memctrl_kobj.ktype = &ktype_memctrl; |
255 | ||
256 | /* generate sysfs "..../edac/mc" */ | |
257 | err = kobject_set_name(&edac_memctrl_kobj,"mc"); | |
e27e3dac DT |
258 | if (err) { |
259 | debugf1("%s() Failed to set name '.../edac/mc'\n", __func__ ); | |
260 | return err; | |
261 | } | |
7c9281d7 DT |
262 | |
263 | /* FIXME: maybe new sysdev_create_subdir() */ | |
264 | err = kobject_register(&edac_memctrl_kobj); | |
7c9281d7 | 265 | if (err) { |
e27e3dac DT |
266 | debugf1("%s() Failed to register '.../edac/mc'\n", __func__ ); |
267 | return err; | |
7c9281d7 DT |
268 | } |
269 | ||
e27e3dac | 270 | debugf1("%s() Registered '.../edac/mc' kobject\n",__func__); |
7c9281d7 | 271 | return 0; |
7c9281d7 DT |
272 | } |
273 | ||
274 | /* | |
275 | * MC teardown: | |
276 | * the '..../edac/mc' kobject followed by '..../edac' itself | |
277 | */ | |
278 | void edac_sysfs_memctrl_teardown(void) | |
279 | { | |
280 | debugf0("MC: " __FILE__ ": %s()\n", __func__); | |
281 | ||
282 | /* Unregister the MC's kobject and wait for reference count to reach 0. | |
283 | */ | |
284 | init_completion(&edac_memctrl_kobj_complete); | |
285 | kobject_unregister(&edac_memctrl_kobj); | |
286 | wait_for_completion(&edac_memctrl_kobj_complete); | |
7c9281d7 DT |
287 | } |
288 | ||
289 | ||
290 | /* EDAC sysfs CSROW data structures and methods | |
291 | */ | |
292 | ||
293 | /* Set of more default csrow<id> attribute show/store functions */ | |
e27e3dac DT |
294 | static ssize_t csrow_ue_count_show(struct csrow_info *csrow, char *data, |
295 | int private) | |
7c9281d7 DT |
296 | { |
297 | return sprintf(data,"%u\n", csrow->ue_count); | |
298 | } | |
299 | ||
e27e3dac DT |
300 | static ssize_t csrow_ce_count_show(struct csrow_info *csrow, char *data, |
301 | int private) | |
7c9281d7 DT |
302 | { |
303 | return sprintf(data,"%u\n", csrow->ce_count); | |
304 | } | |
305 | ||
e27e3dac DT |
306 | static ssize_t csrow_size_show(struct csrow_info *csrow, char *data, |
307 | int private) | |
7c9281d7 DT |
308 | { |
309 | return sprintf(data,"%u\n", PAGES_TO_MiB(csrow->nr_pages)); | |
310 | } | |
311 | ||
e27e3dac DT |
312 | static ssize_t csrow_mem_type_show(struct csrow_info *csrow, char *data, |
313 | int private) | |
7c9281d7 DT |
314 | { |
315 | return sprintf(data,"%s\n", mem_types[csrow->mtype]); | |
316 | } | |
317 | ||
e27e3dac DT |
318 | static ssize_t csrow_dev_type_show(struct csrow_info *csrow, char *data, |
319 | int private) | |
7c9281d7 DT |
320 | { |
321 | return sprintf(data,"%s\n", dev_types[csrow->dtype]); | |
322 | } | |
323 | ||
e27e3dac DT |
324 | static ssize_t csrow_edac_mode_show(struct csrow_info *csrow, char *data, |
325 | int private) | |
7c9281d7 DT |
326 | { |
327 | return sprintf(data,"%s\n", edac_caps[csrow->edac_mode]); | |
328 | } | |
329 | ||
330 | /* show/store functions for DIMM Label attributes */ | |
331 | static ssize_t channel_dimm_label_show(struct csrow_info *csrow, | |
332 | char *data, int channel) | |
333 | { | |
334 | return snprintf(data, EDAC_MC_LABEL_LEN,"%s", | |
335 | csrow->channels[channel].label); | |
336 | } | |
337 | ||
338 | static ssize_t channel_dimm_label_store(struct csrow_info *csrow, | |
339 | const char *data, | |
340 | size_t count, | |
341 | int channel) | |
342 | { | |
343 | ssize_t max_size = 0; | |
344 | ||
345 | max_size = min((ssize_t)count,(ssize_t)EDAC_MC_LABEL_LEN-1); | |
346 | strncpy(csrow->channels[channel].label, data, max_size); | |
347 | csrow->channels[channel].label[max_size] = '\0'; | |
348 | ||
349 | return max_size; | |
350 | } | |
351 | ||
352 | /* show function for dynamic chX_ce_count attribute */ | |
353 | static ssize_t channel_ce_count_show(struct csrow_info *csrow, | |
354 | char *data, | |
355 | int channel) | |
356 | { | |
357 | return sprintf(data, "%u\n", csrow->channels[channel].ce_count); | |
358 | } | |
359 | ||
360 | /* csrow specific attribute structure */ | |
361 | struct csrowdev_attribute { | |
362 | struct attribute attr; | |
363 | ssize_t (*show)(struct csrow_info *,char *,int); | |
364 | ssize_t (*store)(struct csrow_info *, const char *,size_t,int); | |
365 | int private; | |
366 | }; | |
367 | ||
368 | #define to_csrow(k) container_of(k, struct csrow_info, kobj) | |
369 | #define to_csrowdev_attr(a) container_of(a, struct csrowdev_attribute, attr) | |
370 | ||
371 | /* Set of show/store higher level functions for default csrow attributes */ | |
372 | static ssize_t csrowdev_show(struct kobject *kobj, | |
373 | struct attribute *attr, | |
374 | char *buffer) | |
375 | { | |
376 | struct csrow_info *csrow = to_csrow(kobj); | |
377 | struct csrowdev_attribute *csrowdev_attr = to_csrowdev_attr(attr); | |
378 | ||
379 | if (csrowdev_attr->show) | |
380 | return csrowdev_attr->show(csrow, | |
381 | buffer, | |
382 | csrowdev_attr->private); | |
383 | return -EIO; | |
384 | } | |
385 | ||
386 | static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr, | |
387 | const char *buffer, size_t count) | |
388 | { | |
389 | struct csrow_info *csrow = to_csrow(kobj); | |
390 | struct csrowdev_attribute * csrowdev_attr = to_csrowdev_attr(attr); | |
391 | ||
392 | if (csrowdev_attr->store) | |
393 | return csrowdev_attr->store(csrow, | |
394 | buffer, | |
395 | count, | |
396 | csrowdev_attr->private); | |
397 | return -EIO; | |
398 | } | |
399 | ||
400 | static struct sysfs_ops csrowfs_ops = { | |
401 | .show = csrowdev_show, | |
402 | .store = csrowdev_store | |
403 | }; | |
404 | ||
405 | #define CSROWDEV_ATTR(_name,_mode,_show,_store,_private) \ | |
406 | static struct csrowdev_attribute attr_##_name = { \ | |
407 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | |
408 | .show = _show, \ | |
409 | .store = _store, \ | |
410 | .private = _private, \ | |
411 | }; | |
412 | ||
413 | /* default cwrow<id>/attribute files */ | |
414 | CSROWDEV_ATTR(size_mb,S_IRUGO,csrow_size_show,NULL,0); | |
415 | CSROWDEV_ATTR(dev_type,S_IRUGO,csrow_dev_type_show,NULL,0); | |
416 | CSROWDEV_ATTR(mem_type,S_IRUGO,csrow_mem_type_show,NULL,0); | |
417 | CSROWDEV_ATTR(edac_mode,S_IRUGO,csrow_edac_mode_show,NULL,0); | |
418 | CSROWDEV_ATTR(ue_count,S_IRUGO,csrow_ue_count_show,NULL,0); | |
419 | CSROWDEV_ATTR(ce_count,S_IRUGO,csrow_ce_count_show,NULL,0); | |
420 | ||
421 | /* default attributes of the CSROW<id> object */ | |
422 | static struct csrowdev_attribute *default_csrow_attr[] = { | |
423 | &attr_dev_type, | |
424 | &attr_mem_type, | |
425 | &attr_edac_mode, | |
426 | &attr_size_mb, | |
427 | &attr_ue_count, | |
428 | &attr_ce_count, | |
429 | NULL, | |
430 | }; | |
431 | ||
432 | ||
433 | /* possible dynamic channel DIMM Label attribute files */ | |
434 | CSROWDEV_ATTR(ch0_dimm_label,S_IRUGO|S_IWUSR, | |
435 | channel_dimm_label_show, | |
436 | channel_dimm_label_store, | |
437 | 0 ); | |
438 | CSROWDEV_ATTR(ch1_dimm_label,S_IRUGO|S_IWUSR, | |
439 | channel_dimm_label_show, | |
440 | channel_dimm_label_store, | |
441 | 1 ); | |
442 | CSROWDEV_ATTR(ch2_dimm_label,S_IRUGO|S_IWUSR, | |
443 | channel_dimm_label_show, | |
444 | channel_dimm_label_store, | |
445 | 2 ); | |
446 | CSROWDEV_ATTR(ch3_dimm_label,S_IRUGO|S_IWUSR, | |
447 | channel_dimm_label_show, | |
448 | channel_dimm_label_store, | |
449 | 3 ); | |
450 | CSROWDEV_ATTR(ch4_dimm_label,S_IRUGO|S_IWUSR, | |
451 | channel_dimm_label_show, | |
452 | channel_dimm_label_store, | |
453 | 4 ); | |
454 | CSROWDEV_ATTR(ch5_dimm_label,S_IRUGO|S_IWUSR, | |
455 | channel_dimm_label_show, | |
456 | channel_dimm_label_store, | |
457 | 5 ); | |
458 | ||
459 | /* Total possible dynamic DIMM Label attribute file table */ | |
460 | static struct csrowdev_attribute *dynamic_csrow_dimm_attr[] = { | |
461 | &attr_ch0_dimm_label, | |
462 | &attr_ch1_dimm_label, | |
463 | &attr_ch2_dimm_label, | |
464 | &attr_ch3_dimm_label, | |
465 | &attr_ch4_dimm_label, | |
466 | &attr_ch5_dimm_label | |
467 | }; | |
468 | ||
469 | /* possible dynamic channel ce_count attribute files */ | |
470 | CSROWDEV_ATTR(ch0_ce_count,S_IRUGO|S_IWUSR, | |
471 | channel_ce_count_show, | |
472 | NULL, | |
473 | 0 ); | |
474 | CSROWDEV_ATTR(ch1_ce_count,S_IRUGO|S_IWUSR, | |
475 | channel_ce_count_show, | |
476 | NULL, | |
477 | 1 ); | |
478 | CSROWDEV_ATTR(ch2_ce_count,S_IRUGO|S_IWUSR, | |
479 | channel_ce_count_show, | |
480 | NULL, | |
481 | 2 ); | |
482 | CSROWDEV_ATTR(ch3_ce_count,S_IRUGO|S_IWUSR, | |
483 | channel_ce_count_show, | |
484 | NULL, | |
485 | 3 ); | |
486 | CSROWDEV_ATTR(ch4_ce_count,S_IRUGO|S_IWUSR, | |
487 | channel_ce_count_show, | |
488 | NULL, | |
489 | 4 ); | |
490 | CSROWDEV_ATTR(ch5_ce_count,S_IRUGO|S_IWUSR, | |
491 | channel_ce_count_show, | |
492 | NULL, | |
493 | 5 ); | |
494 | ||
495 | /* Total possible dynamic ce_count attribute file table */ | |
496 | static struct csrowdev_attribute *dynamic_csrow_ce_count_attr[] = { | |
497 | &attr_ch0_ce_count, | |
498 | &attr_ch1_ce_count, | |
499 | &attr_ch2_ce_count, | |
500 | &attr_ch3_ce_count, | |
501 | &attr_ch4_ce_count, | |
502 | &attr_ch5_ce_count | |
503 | }; | |
504 | ||
505 | ||
506 | #define EDAC_NR_CHANNELS 6 | |
507 | ||
508 | /* Create dynamic CHANNEL files, indexed by 'chan', under specifed CSROW */ | |
509 | static int edac_create_channel_files(struct kobject *kobj, int chan) | |
510 | { | |
511 | int err=-ENODEV; | |
512 | ||
513 | if (chan >= EDAC_NR_CHANNELS) | |
514 | return err; | |
515 | ||
516 | /* create the DIMM label attribute file */ | |
517 | err = sysfs_create_file(kobj, | |
518 | (struct attribute *) dynamic_csrow_dimm_attr[chan]); | |
519 | ||
520 | if (!err) { | |
521 | /* create the CE Count attribute file */ | |
522 | err = sysfs_create_file(kobj, | |
e27e3dac | 523 | (struct attribute *)dynamic_csrow_ce_count_attr[chan]); |
7c9281d7 | 524 | } else { |
e27e3dac DT |
525 | debugf1("%s() dimm labels and ce_count files created", |
526 | __func__); | |
7c9281d7 DT |
527 | } |
528 | ||
529 | return err; | |
530 | } | |
531 | ||
532 | /* No memory to release for this kobj */ | |
533 | static void edac_csrow_instance_release(struct kobject *kobj) | |
534 | { | |
535 | struct csrow_info *cs; | |
536 | ||
537 | cs = container_of(kobj, struct csrow_info, kobj); | |
538 | complete(&cs->kobj_complete); | |
539 | } | |
540 | ||
541 | /* the kobj_type instance for a CSROW */ | |
542 | static struct kobj_type ktype_csrow = { | |
543 | .release = edac_csrow_instance_release, | |
544 | .sysfs_ops = &csrowfs_ops, | |
545 | .default_attrs = (struct attribute **) default_csrow_attr, | |
546 | }; | |
547 | ||
548 | /* Create a CSROW object under specifed edac_mc_device */ | |
549 | static int edac_create_csrow_object( | |
550 | struct kobject *edac_mci_kobj, | |
551 | struct csrow_info *csrow, | |
552 | int index) | |
553 | { | |
554 | int err = 0; | |
555 | int chan; | |
556 | ||
557 | memset(&csrow->kobj, 0, sizeof(csrow->kobj)); | |
558 | ||
559 | /* generate ..../edac/mc/mc<id>/csrow<index> */ | |
560 | ||
561 | csrow->kobj.parent = edac_mci_kobj; | |
562 | csrow->kobj.ktype = &ktype_csrow; | |
563 | ||
564 | /* name this instance of csrow<id> */ | |
565 | err = kobject_set_name(&csrow->kobj,"csrow%d",index); | |
566 | if (err) | |
567 | goto error_exit; | |
568 | ||
569 | /* Instanstiate the csrow object */ | |
570 | err = kobject_register(&csrow->kobj); | |
571 | if (!err) { | |
572 | /* Create the dyanmic attribute files on this csrow, | |
573 | * namely, the DIMM labels and the channel ce_count | |
574 | */ | |
575 | for (chan = 0; chan < csrow->nr_channels; chan++) { | |
576 | err = edac_create_channel_files(&csrow->kobj,chan); | |
577 | if (err) | |
578 | break; | |
579 | } | |
580 | } | |
581 | ||
582 | error_exit: | |
583 | return err; | |
584 | } | |
585 | ||
586 | /* default sysfs methods and data structures for the main MCI kobject */ | |
587 | ||
588 | static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci, | |
589 | const char *data, size_t count) | |
590 | { | |
591 | int row, chan; | |
592 | ||
593 | mci->ue_noinfo_count = 0; | |
594 | mci->ce_noinfo_count = 0; | |
595 | mci->ue_count = 0; | |
596 | mci->ce_count = 0; | |
597 | ||
598 | for (row = 0; row < mci->nr_csrows; row++) { | |
599 | struct csrow_info *ri = &mci->csrows[row]; | |
600 | ||
601 | ri->ue_count = 0; | |
602 | ri->ce_count = 0; | |
603 | ||
604 | for (chan = 0; chan < ri->nr_channels; chan++) | |
605 | ri->channels[chan].ce_count = 0; | |
606 | } | |
607 | ||
608 | mci->start_time = jiffies; | |
609 | return count; | |
610 | } | |
611 | ||
612 | /* memory scrubbing */ | |
613 | static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci, | |
614 | const char *data, size_t count) | |
615 | { | |
616 | u32 bandwidth = -1; | |
617 | ||
618 | if (mci->set_sdram_scrub_rate) { | |
619 | ||
620 | memctrl_int_store(&bandwidth, data, count); | |
621 | ||
622 | if (!(*mci->set_sdram_scrub_rate)(mci, &bandwidth)) { | |
623 | edac_printk(KERN_DEBUG, EDAC_MC, | |
624 | "Scrub rate set successfully, applied: %d\n", | |
625 | bandwidth); | |
626 | } else { | |
627 | /* FIXME: error codes maybe? */ | |
628 | edac_printk(KERN_DEBUG, EDAC_MC, | |
629 | "Scrub rate set FAILED, could not apply: %d\n", | |
630 | bandwidth); | |
631 | } | |
632 | } else { | |
633 | /* FIXME: produce "not implemented" ERROR for user-side. */ | |
634 | edac_printk(KERN_WARNING, EDAC_MC, | |
635 | "Memory scrubbing 'set'control is not implemented!\n"); | |
636 | } | |
637 | return count; | |
638 | } | |
639 | ||
640 | static ssize_t mci_sdram_scrub_rate_show(struct mem_ctl_info *mci, char *data) | |
641 | { | |
642 | u32 bandwidth = -1; | |
643 | ||
644 | if (mci->get_sdram_scrub_rate) { | |
645 | if (!(*mci->get_sdram_scrub_rate)(mci, &bandwidth)) { | |
646 | edac_printk(KERN_DEBUG, EDAC_MC, | |
647 | "Scrub rate successfully, fetched: %d\n", | |
648 | bandwidth); | |
649 | } else { | |
650 | /* FIXME: error codes maybe? */ | |
651 | edac_printk(KERN_DEBUG, EDAC_MC, | |
652 | "Scrub rate fetch FAILED, got: %d\n", | |
653 | bandwidth); | |
654 | } | |
655 | } else { | |
656 | /* FIXME: produce "not implemented" ERROR for user-side. */ | |
657 | edac_printk(KERN_WARNING, EDAC_MC, | |
e27e3dac | 658 | "Memory scrubbing 'get' control is not implemented\n"); |
7c9281d7 DT |
659 | } |
660 | return sprintf(data, "%d\n", bandwidth); | |
661 | } | |
662 | ||
663 | /* default attribute files for the MCI object */ | |
664 | static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data) | |
665 | { | |
666 | return sprintf(data,"%d\n", mci->ue_count); | |
667 | } | |
668 | ||
669 | static ssize_t mci_ce_count_show(struct mem_ctl_info *mci, char *data) | |
670 | { | |
671 | return sprintf(data,"%d\n", mci->ce_count); | |
672 | } | |
673 | ||
674 | static ssize_t mci_ce_noinfo_show(struct mem_ctl_info *mci, char *data) | |
675 | { | |
676 | return sprintf(data,"%d\n", mci->ce_noinfo_count); | |
677 | } | |
678 | ||
679 | static ssize_t mci_ue_noinfo_show(struct mem_ctl_info *mci, char *data) | |
680 | { | |
681 | return sprintf(data,"%d\n", mci->ue_noinfo_count); | |
682 | } | |
683 | ||
684 | static ssize_t mci_seconds_show(struct mem_ctl_info *mci, char *data) | |
685 | { | |
686 | return sprintf(data,"%ld\n", (jiffies - mci->start_time) / HZ); | |
687 | } | |
688 | ||
689 | static ssize_t mci_ctl_name_show(struct mem_ctl_info *mci, char *data) | |
690 | { | |
691 | return sprintf(data,"%s\n", mci->ctl_name); | |
692 | } | |
693 | ||
694 | static ssize_t mci_size_mb_show(struct mem_ctl_info *mci, char *data) | |
695 | { | |
696 | int total_pages, csrow_idx; | |
697 | ||
698 | for (total_pages = csrow_idx = 0; csrow_idx < mci->nr_csrows; | |
699 | csrow_idx++) { | |
700 | struct csrow_info *csrow = &mci->csrows[csrow_idx]; | |
701 | ||
702 | if (!csrow->nr_pages) | |
703 | continue; | |
704 | ||
705 | total_pages += csrow->nr_pages; | |
706 | } | |
707 | ||
708 | return sprintf(data,"%u\n", PAGES_TO_MiB(total_pages)); | |
709 | } | |
710 | ||
711 | struct mcidev_attribute { | |
712 | struct attribute attr; | |
713 | ssize_t (*show)(struct mem_ctl_info *,char *); | |
714 | ssize_t (*store)(struct mem_ctl_info *, const char *,size_t); | |
715 | }; | |
716 | ||
717 | #define to_mci(k) container_of(k, struct mem_ctl_info, edac_mci_kobj) | |
718 | #define to_mcidev_attr(a) container_of(a, struct mcidev_attribute, attr) | |
719 | ||
720 | /* MCI show/store functions for top most object */ | |
721 | static ssize_t mcidev_show(struct kobject *kobj, struct attribute *attr, | |
722 | char *buffer) | |
723 | { | |
724 | struct mem_ctl_info *mem_ctl_info = to_mci(kobj); | |
725 | struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr); | |
726 | ||
727 | if (mcidev_attr->show) | |
728 | return mcidev_attr->show(mem_ctl_info, buffer); | |
729 | ||
730 | return -EIO; | |
731 | } | |
732 | ||
733 | static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr, | |
734 | const char *buffer, size_t count) | |
735 | { | |
736 | struct mem_ctl_info *mem_ctl_info = to_mci(kobj); | |
737 | struct mcidev_attribute * mcidev_attr = to_mcidev_attr(attr); | |
738 | ||
739 | if (mcidev_attr->store) | |
740 | return mcidev_attr->store(mem_ctl_info, buffer, count); | |
741 | ||
742 | return -EIO; | |
743 | } | |
744 | ||
745 | static struct sysfs_ops mci_ops = { | |
746 | .show = mcidev_show, | |
747 | .store = mcidev_store | |
748 | }; | |
749 | ||
750 | #define MCIDEV_ATTR(_name,_mode,_show,_store) \ | |
751 | static struct mcidev_attribute mci_attr_##_name = { \ | |
752 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | |
753 | .show = _show, \ | |
754 | .store = _store, \ | |
755 | }; | |
756 | ||
757 | /* default Control file */ | |
758 | MCIDEV_ATTR(reset_counters,S_IWUSR,NULL,mci_reset_counters_store); | |
759 | ||
760 | /* default Attribute files */ | |
761 | MCIDEV_ATTR(mc_name,S_IRUGO,mci_ctl_name_show,NULL); | |
762 | MCIDEV_ATTR(size_mb,S_IRUGO,mci_size_mb_show,NULL); | |
763 | MCIDEV_ATTR(seconds_since_reset,S_IRUGO,mci_seconds_show,NULL); | |
764 | MCIDEV_ATTR(ue_noinfo_count,S_IRUGO,mci_ue_noinfo_show,NULL); | |
765 | MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL); | |
766 | MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL); | |
767 | MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL); | |
768 | ||
769 | /* memory scrubber attribute file */ | |
e27e3dac DT |
770 | MCIDEV_ATTR(sdram_scrub_rate,S_IRUGO|S_IWUSR,mci_sdram_scrub_rate_show,\ |
771 | mci_sdram_scrub_rate_store); | |
7c9281d7 DT |
772 | |
773 | static struct mcidev_attribute *mci_attr[] = { | |
774 | &mci_attr_reset_counters, | |
775 | &mci_attr_mc_name, | |
776 | &mci_attr_size_mb, | |
777 | &mci_attr_seconds_since_reset, | |
778 | &mci_attr_ue_noinfo_count, | |
779 | &mci_attr_ce_noinfo_count, | |
780 | &mci_attr_ue_count, | |
781 | &mci_attr_ce_count, | |
782 | &mci_attr_sdram_scrub_rate, | |
783 | NULL | |
784 | }; | |
785 | ||
786 | /* | |
787 | * Release of a MC controlling instance | |
788 | */ | |
789 | static void edac_mci_instance_release(struct kobject *kobj) | |
790 | { | |
791 | struct mem_ctl_info *mci; | |
792 | ||
793 | mci = to_mci(kobj); | |
794 | debugf0("%s() idx=%d\n", __func__, mci->mc_idx); | |
795 | complete(&mci->kobj_complete); | |
796 | } | |
797 | ||
798 | static struct kobj_type ktype_mci = { | |
799 | .release = edac_mci_instance_release, | |
800 | .sysfs_ops = &mci_ops, | |
801 | .default_attrs = (struct attribute **) mci_attr, | |
802 | }; | |
803 | ||
804 | ||
805 | #define EDAC_DEVICE_SYMLINK "device" | |
806 | ||
807 | /* | |
808 | * Create a new Memory Controller kobject instance, | |
809 | * mc<id> under the 'mc' directory | |
810 | * | |
811 | * Return: | |
812 | * 0 Success | |
813 | * !0 Failure | |
814 | */ | |
815 | int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) | |
816 | { | |
817 | int i; | |
818 | int err; | |
819 | struct csrow_info *csrow; | |
820 | struct kobject *edac_mci_kobj=&mci->edac_mci_kobj; | |
821 | ||
822 | debugf0("%s() idx=%d\n", __func__, mci->mc_idx); | |
823 | memset(edac_mci_kobj, 0, sizeof(*edac_mci_kobj)); | |
824 | ||
825 | /* set the name of the mc<id> object */ | |
826 | err = kobject_set_name(edac_mci_kobj,"mc%d",mci->mc_idx); | |
827 | if (err) | |
828 | return err; | |
829 | ||
830 | /* link to our parent the '..../edac/mc' object */ | |
831 | edac_mci_kobj->parent = &edac_memctrl_kobj; | |
832 | edac_mci_kobj->ktype = &ktype_mci; | |
833 | ||
834 | /* register the mc<id> kobject */ | |
835 | err = kobject_register(edac_mci_kobj); | |
836 | if (err) | |
837 | return err; | |
838 | ||
839 | /* create a symlink for the device */ | |
840 | err = sysfs_create_link(edac_mci_kobj, &mci->dev->kobj, | |
841 | EDAC_DEVICE_SYMLINK); | |
842 | if (err) | |
843 | goto fail0; | |
844 | ||
845 | /* Make directories for each CSROW object | |
846 | * under the mc<id> kobject | |
847 | */ | |
848 | for (i = 0; i < mci->nr_csrows; i++) { | |
849 | csrow = &mci->csrows[i]; | |
850 | ||
851 | /* Only expose populated CSROWs */ | |
852 | if (csrow->nr_pages > 0) { | |
853 | err = edac_create_csrow_object(edac_mci_kobj,csrow,i); | |
854 | if (err) | |
855 | goto fail1; | |
856 | } | |
857 | } | |
858 | ||
859 | return 0; | |
860 | ||
861 | /* CSROW error: backout what has already been registered, */ | |
862 | fail1: | |
863 | for ( i--; i >= 0; i--) { | |
864 | if (csrow->nr_pages > 0) { | |
865 | init_completion(&csrow->kobj_complete); | |
866 | kobject_unregister(&mci->csrows[i].kobj); | |
867 | wait_for_completion(&csrow->kobj_complete); | |
868 | } | |
869 | } | |
870 | ||
871 | fail0: | |
872 | init_completion(&mci->kobj_complete); | |
873 | kobject_unregister(edac_mci_kobj); | |
874 | wait_for_completion(&mci->kobj_complete); | |
875 | return err; | |
876 | } | |
877 | ||
878 | /* | |
879 | * remove a Memory Controller instance | |
880 | */ | |
881 | void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) | |
882 | { | |
883 | int i; | |
884 | ||
885 | debugf0("%s()\n", __func__); | |
886 | ||
887 | /* remove all csrow kobjects */ | |
888 | for (i = 0; i < mci->nr_csrows; i++) { | |
889 | if (mci->csrows[i].nr_pages > 0) { | |
890 | init_completion(&mci->csrows[i].kobj_complete); | |
891 | kobject_unregister(&mci->csrows[i].kobj); | |
892 | wait_for_completion(&mci->csrows[i].kobj_complete); | |
893 | } | |
894 | } | |
895 | ||
896 | sysfs_remove_link(&mci->edac_mci_kobj, EDAC_DEVICE_SYMLINK); | |
897 | init_completion(&mci->kobj_complete); | |
898 | kobject_unregister(&mci->edac_mci_kobj); | |
899 | wait_for_completion(&mci->kobj_complete); | |
900 | } | |
901 | ||
902 |