blob: 3c0d67381a34d82d1778b4073574f296da6aedda [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 *
Mauro Carvalho Chehab37e59f82014-02-07 08:03:07 -020010 * (c) 2012-2013 - Mauro Carvalho Chehab
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030011 * The entire API were re-written, and ported to use struct device
12 *
Douglas Thompson7c9281d2007-07-19 01:49:33 -070013 */
14
Douglas Thompson7c9281d2007-07-19 01:49:33 -070015#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020017#include <linux/edac.h>
Doug Thompson8096cfa2007-07-19 01:50:27 -070018#include <linux/bug.h>
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030019#include <linux/pm_runtime.h>
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -030020#include <linux/uaccess.h>
Douglas Thompson7c9281d2007-07-19 01:49:33 -070021
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070022#include "edac_core.h"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070023#include "edac_module.h"
24
25/* MC EDAC Controls, setable by module parameter, and sysfs */
Dave Jiang4de78c62007-07-19 01:49:54 -070026static int edac_mc_log_ue = 1;
27static int edac_mc_log_ce = 1;
Douglas Thompsonf0440912007-07-19 01:50:19 -070028static int edac_mc_panic_on_ue;
Dave Jiang4de78c62007-07-19 01:49:54 -070029static int edac_mc_poll_msec = 1000;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070030
31/* Getter functions for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070032int edac_mc_get_log_ue(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070033{
Dave Jiang4de78c62007-07-19 01:49:54 -070034 return edac_mc_log_ue;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070035}
36
Dave Jiang4de78c62007-07-19 01:49:54 -070037int edac_mc_get_log_ce(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070038{
Dave Jiang4de78c62007-07-19 01:49:54 -070039 return edac_mc_log_ce;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070040}
41
Dave Jiang4de78c62007-07-19 01:49:54 -070042int edac_mc_get_panic_on_ue(void)
Douglas Thompson7c9281d2007-07-19 01:49:33 -070043{
Dave Jiang4de78c62007-07-19 01:49:54 -070044 return edac_mc_panic_on_ue;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070045}
46
Dave Jiang81d87cb2007-07-19 01:49:52 -070047/* this is temporary */
48int edac_mc_get_poll_msec(void)
49{
Dave Jiang4de78c62007-07-19 01:49:54 -070050 return edac_mc_poll_msec;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070051}
52
Arthur Jones096846e2008-07-25 01:49:09 -070053static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
54{
55 long l;
56 int ret;
57
58 if (!val)
59 return -EINVAL;
60
Jingoo Hanc542b532013-07-19 16:07:21 +090061 ret = kstrtol(val, 0, &l);
62 if (ret)
63 return ret;
64 if ((int)l != l)
Arthur Jones096846e2008-07-25 01:49:09 -070065 return -EINVAL;
66 *((int *)kp->arg) = l;
67
68 /* notify edac_mc engine to reset the poll period */
69 edac_mc_reset_delay_period(l);
70
71 return 0;
72}
73
Douglas Thompson7c9281d2007-07-19 01:49:33 -070074/* Parameter declarations for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070075module_param(edac_mc_panic_on_ue, int, 0644);
76MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
77module_param(edac_mc_log_ue, int, 0644);
78MODULE_PARM_DESC(edac_mc_log_ue,
Douglas Thompson079708b2007-07-19 01:49:58 -070079 "Log uncorrectable error to console: 0=off 1=on");
Dave Jiang4de78c62007-07-19 01:49:54 -070080module_param(edac_mc_log_ce, int, 0644);
81MODULE_PARM_DESC(edac_mc_log_ce,
Douglas Thompson079708b2007-07-19 01:49:58 -070082 "Log correctable error to console: 0=off 1=on");
Arthur Jones096846e2008-07-25 01:49:09 -070083module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int,
84 &edac_mc_poll_msec, 0644);
Dave Jiang4de78c62007-07-19 01:49:54 -070085MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070086
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -030087static struct device *mci_pdev;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030088
Douglas Thompson7c9281d2007-07-19 01:49:33 -070089/*
90 * various constants for Memory Controllers
91 */
Borislav Petkov8b7719e2013-03-25 15:41:55 +010092static const char * const mem_types[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -070093 [MEM_EMPTY] = "Empty",
94 [MEM_RESERVED] = "Reserved",
95 [MEM_UNKNOWN] = "Unknown",
96 [MEM_FPM] = "FPM",
97 [MEM_EDO] = "EDO",
98 [MEM_BEDO] = "BEDO",
99 [MEM_SDR] = "Unbuffered-SDR",
100 [MEM_RDR] = "Registered-SDR",
101 [MEM_DDR] = "Unbuffered-DDR",
102 [MEM_RDDR] = "Registered-DDR",
Dave Jiang1a9b85e2007-07-19 01:49:38 -0700103 [MEM_RMBS] = "RMBS",
104 [MEM_DDR2] = "Unbuffered-DDR2",
105 [MEM_FB_DDR2] = "FullyBuffered-DDR2",
Benjamin Herrenschmidt1d5f7262008-02-07 00:14:52 -0800106 [MEM_RDDR2] = "Registered-DDR2",
Yang Shib1cfebc2009-06-30 11:41:22 -0700107 [MEM_XDR] = "XDR",
108 [MEM_DDR3] = "Unbuffered-DDR3",
109 [MEM_RDDR3] = "Registered-DDR3"
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700110};
111
Borislav Petkov8b7719e2013-03-25 15:41:55 +0100112static const char * const dev_types[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700113 [DEV_UNKNOWN] = "Unknown",
114 [DEV_X1] = "x1",
115 [DEV_X2] = "x2",
116 [DEV_X4] = "x4",
117 [DEV_X8] = "x8",
118 [DEV_X16] = "x16",
119 [DEV_X32] = "x32",
120 [DEV_X64] = "x64"
121};
122
Borislav Petkov8b7719e2013-03-25 15:41:55 +0100123static const char * const edac_caps[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700124 [EDAC_UNKNOWN] = "Unknown",
125 [EDAC_NONE] = "None",
126 [EDAC_RESERVED] = "Reserved",
127 [EDAC_PARITY] = "PARITY",
128 [EDAC_EC] = "EC",
129 [EDAC_SECDED] = "SECDED",
130 [EDAC_S2ECD2ED] = "S2ECD2ED",
131 [EDAC_S4ECD4ED] = "S4ECD4ED",
132 [EDAC_S8ECD8ED] = "S8ECD8ED",
133 [EDAC_S16ECD16ED] = "S16ECD16ED"
134};
135
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300136#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300137/*
138 * EDAC sysfs CSROW data structures and methods
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700139 */
140
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300141#define to_csrow(k) container_of(k, struct csrow_info, dev)
142
143/*
144 * We need it to avoid namespace conflicts between the legacy API
145 * and the per-dimm/per-rank one
146 */
147#define DEVICE_ATTR_LEGACY(_name, _mode, _show, _store) \
Stephen Hemmingerfbe2d362013-02-21 21:44:17 -0800148 static struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300149
150struct dev_ch_attribute {
151 struct device_attribute attr;
152 int channel;
153};
154
155#define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
156 struct dev_ch_attribute dev_attr_legacy_##_name = \
157 { __ATTR(_name, _mode, _show, _store), (_var) }
158
159#define to_channel(k) (container_of(k, struct dev_ch_attribute, attr)->channel)
160
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700161/* Set of more default csrow<id> attribute show/store functions */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300162static ssize_t csrow_ue_count_show(struct device *dev,
163 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700164{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300165 struct csrow_info *csrow = to_csrow(dev);
166
Douglas Thompson079708b2007-07-19 01:49:58 -0700167 return sprintf(data, "%u\n", csrow->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700168}
169
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300170static ssize_t csrow_ce_count_show(struct device *dev,
171 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700172{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300173 struct csrow_info *csrow = to_csrow(dev);
174
Douglas Thompson079708b2007-07-19 01:49:58 -0700175 return sprintf(data, "%u\n", csrow->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700176}
177
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300178static ssize_t csrow_size_show(struct device *dev,
179 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700180{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300181 struct csrow_info *csrow = to_csrow(dev);
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300182 int i;
183 u32 nr_pages = 0;
184
185 for (i = 0; i < csrow->nr_channels; i++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300186 nr_pages += csrow->channels[i]->dimm->nr_pages;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300187 return sprintf(data, "%u\n", PAGES_TO_MiB(nr_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700188}
189
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300190static ssize_t csrow_mem_type_show(struct device *dev,
191 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700192{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300193 struct csrow_info *csrow = to_csrow(dev);
194
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300195 return sprintf(data, "%s\n", mem_types[csrow->channels[0]->dimm->mtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700196}
197
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300198static ssize_t csrow_dev_type_show(struct device *dev,
199 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700200{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300201 struct csrow_info *csrow = to_csrow(dev);
202
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300203 return sprintf(data, "%s\n", dev_types[csrow->channels[0]->dimm->dtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700204}
205
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300206static ssize_t csrow_edac_mode_show(struct device *dev,
207 struct device_attribute *mattr,
208 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700209{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300210 struct csrow_info *csrow = to_csrow(dev);
211
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300212 return sprintf(data, "%s\n", edac_caps[csrow->channels[0]->dimm->edac_mode]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700213}
214
215/* show/store functions for DIMM Label attributes */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300216static ssize_t channel_dimm_label_show(struct device *dev,
217 struct device_attribute *mattr,
218 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700219{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300220 struct csrow_info *csrow = to_csrow(dev);
221 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300222 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300223
Arthur Jones124682c2008-07-25 01:49:12 -0700224 /* if field has not been initialized, there is nothing to send */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300225 if (!rank->dimm->label[0])
Arthur Jones124682c2008-07-25 01:49:12 -0700226 return 0;
227
228 return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300229 rank->dimm->label);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700230}
231
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300232static ssize_t channel_dimm_label_store(struct device *dev,
233 struct device_attribute *mattr,
234 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700235{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300236 struct csrow_info *csrow = to_csrow(dev);
237 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300238 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300239
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700240 ssize_t max_size = 0;
241
Douglas Thompson079708b2007-07-19 01:49:58 -0700242 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300243 strncpy(rank->dimm->label, data, max_size);
244 rank->dimm->label[max_size] = '\0';
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700245
246 return max_size;
247}
248
249/* show function for dynamic chX_ce_count attribute */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300250static ssize_t channel_ce_count_show(struct device *dev,
251 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700252{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300253 struct csrow_info *csrow = to_csrow(dev);
254 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300255 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300256
257 return sprintf(data, "%u\n", rank->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700258}
259
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300260/* cwrow<id>/attribute files */
261DEVICE_ATTR_LEGACY(size_mb, S_IRUGO, csrow_size_show, NULL);
262DEVICE_ATTR_LEGACY(dev_type, S_IRUGO, csrow_dev_type_show, NULL);
263DEVICE_ATTR_LEGACY(mem_type, S_IRUGO, csrow_mem_type_show, NULL);
264DEVICE_ATTR_LEGACY(edac_mode, S_IRUGO, csrow_edac_mode_show, NULL);
265DEVICE_ATTR_LEGACY(ue_count, S_IRUGO, csrow_ue_count_show, NULL);
266DEVICE_ATTR_LEGACY(ce_count, S_IRUGO, csrow_ce_count_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700267
268/* default attributes of the CSROW<id> object */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300269static struct attribute *csrow_attrs[] = {
270 &dev_attr_legacy_dev_type.attr,
271 &dev_attr_legacy_mem_type.attr,
272 &dev_attr_legacy_edac_mode.attr,
273 &dev_attr_legacy_size_mb.attr,
274 &dev_attr_legacy_ue_count.attr,
275 &dev_attr_legacy_ce_count.attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700276 NULL,
277};
278
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300279static struct attribute_group csrow_attr_grp = {
280 .attrs = csrow_attrs,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700281};
282
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300283static const struct attribute_group *csrow_attr_groups[] = {
284 &csrow_attr_grp,
285 NULL
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700286};
287
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300288static void csrow_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300289{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300290 struct csrow_info *csrow = container_of(dev, struct csrow_info, dev);
291
Joe Perches956b9ba12012-04-29 17:08:39 -0300292 edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300293 kfree(csrow);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300294}
295
296static struct device_type csrow_attr_type = {
297 .groups = csrow_attr_groups,
298 .release = csrow_attr_release,
299};
300
301/*
302 * possible dynamic channel DIMM Label attribute files
303 *
304 */
305
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700306#define EDAC_NR_CHANNELS 6
307
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300308DEVICE_CHANNEL(ch0_dimm_label, S_IRUGO | S_IWUSR,
309 channel_dimm_label_show, channel_dimm_label_store, 0);
310DEVICE_CHANNEL(ch1_dimm_label, S_IRUGO | S_IWUSR,
311 channel_dimm_label_show, channel_dimm_label_store, 1);
312DEVICE_CHANNEL(ch2_dimm_label, S_IRUGO | S_IWUSR,
313 channel_dimm_label_show, channel_dimm_label_store, 2);
314DEVICE_CHANNEL(ch3_dimm_label, S_IRUGO | S_IWUSR,
315 channel_dimm_label_show, channel_dimm_label_store, 3);
316DEVICE_CHANNEL(ch4_dimm_label, S_IRUGO | S_IWUSR,
317 channel_dimm_label_show, channel_dimm_label_store, 4);
318DEVICE_CHANNEL(ch5_dimm_label, S_IRUGO | S_IWUSR,
319 channel_dimm_label_show, channel_dimm_label_store, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700320
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300321/* Total possible dynamic DIMM Label attribute file table */
322static struct device_attribute *dynamic_csrow_dimm_attr[] = {
323 &dev_attr_legacy_ch0_dimm_label.attr,
324 &dev_attr_legacy_ch1_dimm_label.attr,
325 &dev_attr_legacy_ch2_dimm_label.attr,
326 &dev_attr_legacy_ch3_dimm_label.attr,
327 &dev_attr_legacy_ch4_dimm_label.attr,
328 &dev_attr_legacy_ch5_dimm_label.attr
329};
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700330
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300331/* possible dynamic channel ce_count attribute files */
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530332DEVICE_CHANNEL(ch0_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300333 channel_ce_count_show, NULL, 0);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530334DEVICE_CHANNEL(ch1_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300335 channel_ce_count_show, NULL, 1);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530336DEVICE_CHANNEL(ch2_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300337 channel_ce_count_show, NULL, 2);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530338DEVICE_CHANNEL(ch3_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300339 channel_ce_count_show, NULL, 3);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530340DEVICE_CHANNEL(ch4_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300341 channel_ce_count_show, NULL, 4);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530342DEVICE_CHANNEL(ch5_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300343 channel_ce_count_show, NULL, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700344
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300345/* Total possible dynamic ce_count attribute file table */
346static struct device_attribute *dynamic_csrow_ce_count_attr[] = {
347 &dev_attr_legacy_ch0_ce_count.attr,
348 &dev_attr_legacy_ch1_ce_count.attr,
349 &dev_attr_legacy_ch2_ce_count.attr,
350 &dev_attr_legacy_ch3_ce_count.attr,
351 &dev_attr_legacy_ch4_ce_count.attr,
352 &dev_attr_legacy_ch5_ce_count.attr
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700353};
354
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300355static inline int nr_pages_per_csrow(struct csrow_info *csrow)
356{
357 int chan, nr_pages = 0;
358
359 for (chan = 0; chan < csrow->nr_channels; chan++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300360 nr_pages += csrow->channels[chan]->dimm->nr_pages;
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300361
362 return nr_pages;
363}
364
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700365/* Create a CSROW object under specifed edac_mc_device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700366static int edac_create_csrow_object(struct mem_ctl_info *mci,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300367 struct csrow_info *csrow, int index)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700368{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300369 int err, chan;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700370
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300371 if (csrow->nr_channels >= EDAC_NR_CHANNELS)
372 return -ENODEV;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700373
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300374 csrow->dev.type = &csrow_attr_type;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200375 csrow->dev.bus = mci->bus;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300376 device_initialize(&csrow->dev);
377 csrow->dev.parent = &mci->dev;
Borislav Petkov921a6892012-09-13 18:46:39 +0200378 csrow->mci = mci;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300379 dev_set_name(&csrow->dev, "csrow%d", index);
380 dev_set_drvdata(&csrow->dev, csrow);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700381
Joe Perches956b9ba12012-04-29 17:08:39 -0300382 edac_dbg(0, "creating (virtual) csrow node %s\n",
383 dev_name(&csrow->dev));
Doug Thompson8096cfa2007-07-19 01:50:27 -0700384
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300385 err = device_add(&csrow->dev);
386 if (err < 0)
387 return err;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700388
Doug Thompson8096cfa2007-07-19 01:50:27 -0700389 for (chan = 0; chan < csrow->nr_channels; chan++) {
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300390 /* Only expose populated DIMMs */
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300391 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300392 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300393 err = device_create_file(&csrow->dev,
394 dynamic_csrow_dimm_attr[chan]);
395 if (err < 0)
396 goto error;
397 err = device_create_file(&csrow->dev,
398 dynamic_csrow_ce_count_attr[chan]);
399 if (err < 0) {
400 device_remove_file(&csrow->dev,
401 dynamic_csrow_dimm_attr[chan]);
402 goto error;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700403 }
404 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300405
Doug Thompson8096cfa2007-07-19 01:50:27 -0700406 return 0;
407
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300408error:
409 for (--chan; chan >= 0; chan--) {
410 device_remove_file(&csrow->dev,
411 dynamic_csrow_dimm_attr[chan]);
412 device_remove_file(&csrow->dev,
413 dynamic_csrow_ce_count_attr[chan]);
414 }
415 put_device(&csrow->dev);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700416
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700417 return err;
418}
419
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300420/* Create a CSROW object under specifed edac_mc_device */
421static int edac_create_csrow_objects(struct mem_ctl_info *mci)
422{
423 int err, i, chan;
424 struct csrow_info *csrow;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700425
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300426 for (i = 0; i < mci->nr_csrows; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300427 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300428 if (!nr_pages_per_csrow(csrow))
429 continue;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300430 err = edac_create_csrow_object(mci, mci->csrows[i], i);
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -0300431 if (err < 0) {
432 edac_dbg(1,
433 "failure: create csrow objects for csrow %d\n",
434 i);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300435 goto error;
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -0300436 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300437 }
438 return 0;
439
440error:
441 for (--i; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300442 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300443 if (!nr_pages_per_csrow(csrow))
444 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300445 for (chan = csrow->nr_channels - 1; chan >= 0; chan--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300446 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300447 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300448 device_remove_file(&csrow->dev,
449 dynamic_csrow_dimm_attr[chan]);
450 device_remove_file(&csrow->dev,
451 dynamic_csrow_ce_count_attr[chan]);
452 }
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300453 put_device(&mci->csrows[i]->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300454 }
455
456 return err;
457}
458
459static void edac_delete_csrow_objects(struct mem_ctl_info *mci)
460{
461 int i, chan;
462 struct csrow_info *csrow;
463
464 for (i = mci->nr_csrows - 1; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300465 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300466 if (!nr_pages_per_csrow(csrow))
467 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300468 for (chan = csrow->nr_channels - 1; chan >= 0; chan--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300469 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300470 continue;
Joe Perches956b9ba12012-04-29 17:08:39 -0300471 edac_dbg(1, "Removing csrow %d channel %d sysfs nodes\n",
472 i, chan);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300473 device_remove_file(&csrow->dev,
474 dynamic_csrow_dimm_attr[chan]);
475 device_remove_file(&csrow->dev,
476 dynamic_csrow_ce_count_attr[chan]);
477 }
Lans Zhang44d22e22012-12-24 14:01:34 +0100478 device_unregister(&mci->csrows[i]->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300479 }
480}
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300481#endif
482
483/*
484 * Per-dimm (or per-rank) devices
485 */
486
487#define to_dimm(k) container_of(k, struct dimm_info, dev)
488
489/* show/store functions for DIMM Label attributes */
490static ssize_t dimmdev_location_show(struct device *dev,
491 struct device_attribute *mattr, char *data)
492{
493 struct dimm_info *dimm = to_dimm(dev);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300494
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -0300495 return edac_dimm_info_location(dimm, data, PAGE_SIZE);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300496}
497
498static ssize_t dimmdev_label_show(struct device *dev,
499 struct device_attribute *mattr, char *data)
500{
501 struct dimm_info *dimm = to_dimm(dev);
502
503 /* if field has not been initialized, there is nothing to send */
504 if (!dimm->label[0])
505 return 0;
506
507 return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", dimm->label);
508}
509
510static ssize_t dimmdev_label_store(struct device *dev,
511 struct device_attribute *mattr,
512 const char *data,
513 size_t count)
514{
515 struct dimm_info *dimm = to_dimm(dev);
516
517 ssize_t max_size = 0;
518
519 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
520 strncpy(dimm->label, data, max_size);
521 dimm->label[max_size] = '\0';
522
523 return max_size;
524}
525
526static ssize_t dimmdev_size_show(struct device *dev,
527 struct device_attribute *mattr, char *data)
528{
529 struct dimm_info *dimm = to_dimm(dev);
530
531 return sprintf(data, "%u\n", PAGES_TO_MiB(dimm->nr_pages));
532}
533
534static ssize_t dimmdev_mem_type_show(struct device *dev,
535 struct device_attribute *mattr, char *data)
536{
537 struct dimm_info *dimm = to_dimm(dev);
538
539 return sprintf(data, "%s\n", mem_types[dimm->mtype]);
540}
541
542static ssize_t dimmdev_dev_type_show(struct device *dev,
543 struct device_attribute *mattr, char *data)
544{
545 struct dimm_info *dimm = to_dimm(dev);
546
547 return sprintf(data, "%s\n", dev_types[dimm->dtype]);
548}
549
550static ssize_t dimmdev_edac_mode_show(struct device *dev,
551 struct device_attribute *mattr,
552 char *data)
553{
554 struct dimm_info *dimm = to_dimm(dev);
555
556 return sprintf(data, "%s\n", edac_caps[dimm->edac_mode]);
557}
558
559/* dimm/rank attribute files */
560static DEVICE_ATTR(dimm_label, S_IRUGO | S_IWUSR,
561 dimmdev_label_show, dimmdev_label_store);
562static DEVICE_ATTR(dimm_location, S_IRUGO, dimmdev_location_show, NULL);
563static DEVICE_ATTR(size, S_IRUGO, dimmdev_size_show, NULL);
564static DEVICE_ATTR(dimm_mem_type, S_IRUGO, dimmdev_mem_type_show, NULL);
565static DEVICE_ATTR(dimm_dev_type, S_IRUGO, dimmdev_dev_type_show, NULL);
566static DEVICE_ATTR(dimm_edac_mode, S_IRUGO, dimmdev_edac_mode_show, NULL);
567
568/* attributes of the dimm<id>/rank<id> object */
569static struct attribute *dimm_attrs[] = {
570 &dev_attr_dimm_label.attr,
571 &dev_attr_dimm_location.attr,
572 &dev_attr_size.attr,
573 &dev_attr_dimm_mem_type.attr,
574 &dev_attr_dimm_dev_type.attr,
575 &dev_attr_dimm_edac_mode.attr,
576 NULL,
577};
578
579static struct attribute_group dimm_attr_grp = {
580 .attrs = dimm_attrs,
581};
582
583static const struct attribute_group *dimm_attr_groups[] = {
584 &dimm_attr_grp,
585 NULL
586};
587
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300588static void dimm_attr_release(struct device *dev)
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300589{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300590 struct dimm_info *dimm = container_of(dev, struct dimm_info, dev);
591
Joe Perches956b9ba12012-04-29 17:08:39 -0300592 edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300593 kfree(dimm);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300594}
595
596static struct device_type dimm_attr_type = {
597 .groups = dimm_attr_groups,
598 .release = dimm_attr_release,
599};
600
601/* Create a DIMM object under specifed memory controller device */
602static int edac_create_dimm_object(struct mem_ctl_info *mci,
603 struct dimm_info *dimm,
604 int index)
605{
606 int err;
607 dimm->mci = mci;
608
609 dimm->dev.type = &dimm_attr_type;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200610 dimm->dev.bus = mci->bus;
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300611 device_initialize(&dimm->dev);
612
613 dimm->dev.parent = &mci->dev;
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300614 if (mci->csbased)
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300615 dev_set_name(&dimm->dev, "rank%d", index);
616 else
617 dev_set_name(&dimm->dev, "dimm%d", index);
618 dev_set_drvdata(&dimm->dev, dimm);
619 pm_runtime_forbid(&mci->dev);
620
621 err = device_add(&dimm->dev);
622
Joe Perches956b9ba12012-04-29 17:08:39 -0300623 edac_dbg(0, "creating rank/dimm device %s\n", dev_name(&dimm->dev));
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300624
625 return err;
626}
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300627
628/*
629 * Memory controller device
630 */
631
632#define to_mci(k) container_of(k, struct mem_ctl_info, dev)
633
634static ssize_t mci_reset_counters_store(struct device *dev,
635 struct device_attribute *mattr,
Douglas Thompson079708b2007-07-19 01:49:58 -0700636 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700637{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300638 struct mem_ctl_info *mci = to_mci(dev);
639 int cnt, row, chan, i;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300640 mci->ue_mc = 0;
641 mci->ce_mc = 0;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300642 mci->ue_noinfo_count = 0;
643 mci->ce_noinfo_count = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700644
645 for (row = 0; row < mci->nr_csrows; row++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300646 struct csrow_info *ri = mci->csrows[row];
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700647
648 ri->ue_count = 0;
649 ri->ce_count = 0;
650
651 for (chan = 0; chan < ri->nr_channels; chan++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300652 ri->channels[chan]->ce_count = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700653 }
654
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300655 cnt = 1;
656 for (i = 0; i < mci->n_layers; i++) {
657 cnt *= mci->layers[i].size;
658 memset(mci->ce_per_layer[i], 0, cnt * sizeof(u32));
659 memset(mci->ue_per_layer[i], 0, cnt * sizeof(u32));
660 }
661
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700662 mci->start_time = jiffies;
663 return count;
664}
665
Borislav Petkov39094442010-11-24 19:52:09 +0100666/* Memory scrubbing interface:
667 *
668 * A MC driver can limit the scrubbing bandwidth based on the CPU type.
669 * Therefore, ->set_sdram_scrub_rate should be made to return the actual
670 * bandwidth that is accepted or 0 when scrubbing is to be disabled.
671 *
672 * Negative value still means that an error has occurred while setting
673 * the scrub rate.
674 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300675static ssize_t mci_sdram_scrub_rate_store(struct device *dev,
676 struct device_attribute *mattr,
Borislav Petkoveba042a2010-05-25 18:21:07 +0200677 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700678{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300679 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkoveba042a2010-05-25 18:21:07 +0200680 unsigned long bandwidth = 0;
Borislav Petkov39094442010-11-24 19:52:09 +0100681 int new_bw = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700682
Jingoo Hanc7f62fc2013-06-01 16:08:22 +0900683 if (kstrtoul(data, 10, &bandwidth) < 0)
Borislav Petkoveba042a2010-05-25 18:21:07 +0200684 return -EINVAL;
685
Borislav Petkov39094442010-11-24 19:52:09 +0100686 new_bw = mci->set_sdram_scrub_rate(mci, bandwidth);
Markus Trippelsdorf49496032011-04-20 14:28:45 -0400687 if (new_bw < 0) {
688 edac_printk(KERN_WARNING, EDAC_MC,
689 "Error setting scrub rate to: %lu\n", bandwidth);
690 return -EINVAL;
Borislav Petkoveba042a2010-05-25 18:21:07 +0200691 }
Borislav Petkov39094442010-11-24 19:52:09 +0100692
Markus Trippelsdorf49496032011-04-20 14:28:45 -0400693 return count;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700694}
695
Borislav Petkov39094442010-11-24 19:52:09 +0100696/*
697 * ->get_sdram_scrub_rate() return value semantics same as above.
698 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300699static ssize_t mci_sdram_scrub_rate_show(struct device *dev,
700 struct device_attribute *mattr,
701 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700702{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300703 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkov39094442010-11-24 19:52:09 +0100704 int bandwidth = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700705
Borislav Petkov39094442010-11-24 19:52:09 +0100706 bandwidth = mci->get_sdram_scrub_rate(mci);
707 if (bandwidth < 0) {
708 edac_printk(KERN_DEBUG, EDAC_MC, "Error reading scrub rate\n");
709 return bandwidth;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700710 }
Borislav Petkoveba042a2010-05-25 18:21:07 +0200711
Borislav Petkov39094442010-11-24 19:52:09 +0100712 return sprintf(data, "%d\n", bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700713}
714
715/* default attribute files for the MCI object */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300716static ssize_t mci_ue_count_show(struct device *dev,
717 struct device_attribute *mattr,
718 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700719{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300720 struct mem_ctl_info *mci = to_mci(dev);
721
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300722 return sprintf(data, "%d\n", mci->ue_mc);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700723}
724
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300725static ssize_t mci_ce_count_show(struct device *dev,
726 struct device_attribute *mattr,
727 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700728{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300729 struct mem_ctl_info *mci = to_mci(dev);
730
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300731 return sprintf(data, "%d\n", mci->ce_mc);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700732}
733
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300734static ssize_t mci_ce_noinfo_show(struct device *dev,
735 struct device_attribute *mattr,
736 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700737{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300738 struct mem_ctl_info *mci = to_mci(dev);
739
Douglas Thompson079708b2007-07-19 01:49:58 -0700740 return sprintf(data, "%d\n", mci->ce_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700741}
742
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300743static ssize_t mci_ue_noinfo_show(struct device *dev,
744 struct device_attribute *mattr,
745 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700746{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300747 struct mem_ctl_info *mci = to_mci(dev);
748
Douglas Thompson079708b2007-07-19 01:49:58 -0700749 return sprintf(data, "%d\n", mci->ue_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700750}
751
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300752static ssize_t mci_seconds_show(struct device *dev,
753 struct device_attribute *mattr,
754 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700755{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300756 struct mem_ctl_info *mci = to_mci(dev);
757
Douglas Thompson079708b2007-07-19 01:49:58 -0700758 return sprintf(data, "%ld\n", (jiffies - mci->start_time) / HZ);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700759}
760
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300761static ssize_t mci_ctl_name_show(struct device *dev,
762 struct device_attribute *mattr,
763 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700764{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300765 struct mem_ctl_info *mci = to_mci(dev);
766
Douglas Thompson079708b2007-07-19 01:49:58 -0700767 return sprintf(data, "%s\n", mci->ctl_name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700768}
769
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300770static ssize_t mci_size_mb_show(struct device *dev,
771 struct device_attribute *mattr,
772 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700773{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300774 struct mem_ctl_info *mci = to_mci(dev);
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300775 int total_pages = 0, csrow_idx, j;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700776
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300777 for (csrow_idx = 0; csrow_idx < mci->nr_csrows; csrow_idx++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300778 struct csrow_info *csrow = mci->csrows[csrow_idx];
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700779
Mauro Carvalho Chehab1eef1282013-03-11 09:07:46 -0300780 for (j = 0; j < csrow->nr_channels; j++) {
781 struct dimm_info *dimm = csrow->channels[j]->dimm;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700782
Mauro Carvalho Chehab1eef1282013-03-11 09:07:46 -0300783 total_pages += dimm->nr_pages;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300784 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700785 }
786
Douglas Thompson079708b2007-07-19 01:49:58 -0700787 return sprintf(data, "%u\n", PAGES_TO_MiB(total_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700788}
789
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300790static ssize_t mci_max_location_show(struct device *dev,
791 struct device_attribute *mattr,
792 char *data)
793{
794 struct mem_ctl_info *mci = to_mci(dev);
795 int i;
796 char *p = data;
797
798 for (i = 0; i < mci->n_layers; i++) {
799 p += sprintf(p, "%s %d ",
800 edac_layer_name[mci->layers[i].type],
801 mci->layers[i].size - 1);
802 }
803
804 return p - data;
805}
806
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300807#ifdef CONFIG_EDAC_DEBUG
808static ssize_t edac_fake_inject_write(struct file *file,
809 const char __user *data,
810 size_t count, loff_t *ppos)
811{
812 struct device *dev = file->private_data;
813 struct mem_ctl_info *mci = to_mci(dev);
814 static enum hw_event_mc_err_type type;
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300815 u16 errcount = mci->fake_inject_count;
816
817 if (!errcount)
818 errcount = 1;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300819
820 type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED
821 : HW_EVENT_ERR_CORRECTED;
822
823 printk(KERN_DEBUG
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300824 "Generating %d %s fake error%s to %d.%d.%d to test core handling. NOTE: this won't test the driver-specific decoding logic.\n",
825 errcount,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300826 (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE",
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300827 errcount > 1 ? "s" : "",
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300828 mci->fake_inject_layer[0],
829 mci->fake_inject_layer[1],
830 mci->fake_inject_layer[2]
831 );
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300832 edac_mc_handle_error(type, mci, errcount, 0, 0, 0,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300833 mci->fake_inject_layer[0],
834 mci->fake_inject_layer[1],
835 mci->fake_inject_layer[2],
Mauro Carvalho Chehab03f7eae2012-06-04 11:29:25 -0300836 "FAKE ERROR", "for EDAC testing only");
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300837
838 return count;
839}
840
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300841static const struct file_operations debug_fake_inject_fops = {
Wei Yongjundb7312a2012-10-17 16:32:01 +0800842 .open = simple_open,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300843 .write = edac_fake_inject_write,
844 .llseek = generic_file_llseek,
845};
846#endif
847
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700848/* default Control file */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300849DEVICE_ATTR(reset_counters, S_IWUSR, NULL, mci_reset_counters_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700850
851/* default Attribute files */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300852DEVICE_ATTR(mc_name, S_IRUGO, mci_ctl_name_show, NULL);
853DEVICE_ATTR(size_mb, S_IRUGO, mci_size_mb_show, NULL);
854DEVICE_ATTR(seconds_since_reset, S_IRUGO, mci_seconds_show, NULL);
855DEVICE_ATTR(ue_noinfo_count, S_IRUGO, mci_ue_noinfo_show, NULL);
856DEVICE_ATTR(ce_noinfo_count, S_IRUGO, mci_ce_noinfo_show, NULL);
857DEVICE_ATTR(ue_count, S_IRUGO, mci_ue_count_show, NULL);
858DEVICE_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL);
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300859DEVICE_ATTR(max_location, S_IRUGO, mci_max_location_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700860
861/* memory scrubber attribute file */
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -0300862DEVICE_ATTR(sdram_scrub_rate, 0, NULL, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700863
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300864static struct attribute *mci_attrs[] = {
865 &dev_attr_reset_counters.attr,
866 &dev_attr_mc_name.attr,
867 &dev_attr_size_mb.attr,
868 &dev_attr_seconds_since_reset.attr,
869 &dev_attr_ue_noinfo_count.attr,
870 &dev_attr_ce_noinfo_count.attr,
871 &dev_attr_ue_count.attr,
872 &dev_attr_ce_count.attr,
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300873 &dev_attr_max_location.attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700874 NULL
875};
876
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300877static struct attribute_group mci_attr_grp = {
878 .attrs = mci_attrs,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700879};
880
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300881static const struct attribute_group *mci_attr_groups[] = {
882 &mci_attr_grp,
883 NULL
Mauro Carvalho Chehabcc301b32009-09-24 16:23:42 -0300884};
885
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300886static void mci_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300887{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300888 struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
889
Joe Perches956b9ba12012-04-29 17:08:39 -0300890 edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300891 kfree(mci);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300892}
893
894static struct device_type mci_attr_type = {
895 .groups = mci_attr_groups,
896 .release = mci_attr_release,
Mauro Carvalho Chehabcc301b32009-09-24 16:23:42 -0300897};
898
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300899#ifdef CONFIG_EDAC_DEBUG
Rob Herringe7930ba2012-06-11 21:32:12 -0500900static struct dentry *edac_debugfs;
901
902int __init edac_debugfs_init(void)
903{
904 edac_debugfs = debugfs_create_dir("edac", NULL);
905 if (IS_ERR(edac_debugfs)) {
906 edac_debugfs = NULL;
907 return -ENOMEM;
908 }
909 return 0;
910}
911
912void __exit edac_debugfs_exit(void)
913{
914 debugfs_remove(edac_debugfs);
915}
916
Rashika Kheria95285932013-12-14 19:30:11 +0530917static int edac_create_debug_nodes(struct mem_ctl_info *mci)
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300918{
919 struct dentry *d, *parent;
920 char name[80];
921 int i;
922
Rob Herringe7930ba2012-06-11 21:32:12 -0500923 if (!edac_debugfs)
924 return -ENODEV;
925
926 d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300927 if (!d)
928 return -ENOMEM;
929 parent = d;
930
931 for (i = 0; i < mci->n_layers; i++) {
932 sprintf(name, "fake_inject_%s",
933 edac_layer_name[mci->layers[i].type]);
934 d = debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent,
935 &mci->fake_inject_layer[i]);
936 if (!d)
937 goto nomem;
938 }
939
940 d = debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent,
941 &mci->fake_inject_ue);
942 if (!d)
943 goto nomem;
944
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300945 d = debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent,
946 &mci->fake_inject_count);
947 if (!d)
948 goto nomem;
949
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300950 d = debugfs_create_file("fake_inject", S_IWUSR, parent,
951 &mci->dev,
952 &debug_fake_inject_fops);
953 if (!d)
954 goto nomem;
955
Rob Herringe7930ba2012-06-11 21:32:12 -0500956 mci->debugfs = parent;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300957 return 0;
958nomem:
959 debugfs_remove(mci->debugfs);
960 return -ENOMEM;
961}
962#endif
963
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700964/*
965 * Create a new Memory Controller kobject instance,
966 * mc<id> under the 'mc' directory
967 *
968 * Return:
969 * 0 Success
970 * !0 Failure
971 */
972int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
973{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300974 int i, err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700975
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300976 /*
977 * The memory controller needs its own bus, in order to avoid
978 * namespace conflicts at /sys/bus/edac.
Douglas Thompson42a8e392007-07-19 01:50:10 -0700979 */
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200980 mci->bus->name = kasprintf(GFP_KERNEL, "mc%d", mci->mc_idx);
981 if (!mci->bus->name)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300982 return -ENOMEM;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200983
984 edac_dbg(0, "creating bus %s\n", mci->bus->name);
985
986 err = bus_register(mci->bus);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300987 if (err < 0)
988 return err;
989
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300990 /* get the /sys/devices/system/edac subsys reference */
991 mci->dev.type = &mci_attr_type;
992 device_initialize(&mci->dev);
993
994 mci->dev.parent = mci_pdev;
Borislav Petkov88d84ac2013-07-19 12:28:25 +0200995 mci->dev.bus = mci->bus;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300996 dev_set_name(&mci->dev, "mc%d", mci->mc_idx);
997 dev_set_drvdata(&mci->dev, mci);
998 pm_runtime_forbid(&mci->dev);
999
Joe Perches956b9ba12012-04-29 17:08:39 -03001000 edac_dbg(0, "creating device %s\n", dev_name(&mci->dev));
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001001 err = device_add(&mci->dev);
1002 if (err < 0) {
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -03001003 edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev));
Borislav Petkov88d84ac2013-07-19 12:28:25 +02001004 bus_unregister(mci->bus);
1005 kfree(mci->bus->name);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001006 return err;
Douglas Thompson42a8e392007-07-19 01:50:10 -07001007 }
1008
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -03001009 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
1010 if (mci->get_sdram_scrub_rate) {
1011 dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
1012 dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
1013 }
1014 if (mci->set_sdram_scrub_rate) {
1015 dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
1016 dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
1017 }
1018 err = device_create_file(&mci->dev,
1019 &dev_attr_sdram_scrub_rate);
1020 if (err) {
1021 edac_dbg(1, "failure: create sdram_scrub_rate\n");
1022 goto fail2;
1023 }
1024 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001025 /*
1026 * Create the dimm/rank devices
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001027 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001028 for (i = 0; i < mci->tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001029 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001030 /* Only expose populated DIMMs */
1031 if (dimm->nr_pages == 0)
1032 continue;
1033#ifdef CONFIG_EDAC_DEBUG
Joe Perches956b9ba12012-04-29 17:08:39 -03001034 edac_dbg(1, "creating dimm%d, located at ", i);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001035 if (edac_debug_level >= 1) {
1036 int lay;
1037 for (lay = 0; lay < mci->n_layers; lay++)
1038 printk(KERN_CONT "%s %d ",
1039 edac_layer_name[mci->layers[lay].type],
1040 dimm->location[lay]);
1041 printk(KERN_CONT "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001042 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001043#endif
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001044 err = edac_create_dimm_object(mci, dimm, i);
1045 if (err) {
Joe Perches956b9ba12012-04-29 17:08:39 -03001046 edac_dbg(1, "failure: create dimm %d obj\n", i);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001047 goto fail;
1048 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001049 }
1050
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001051#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001052 err = edac_create_csrow_objects(mci);
1053 if (err < 0)
1054 goto fail;
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001055#endif
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001056
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -03001057#ifdef CONFIG_EDAC_DEBUG
1058 edac_create_debug_nodes(mci);
1059#endif
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001060 return 0;
1061
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001062fail:
Douglas Thompson079708b2007-07-19 01:49:58 -07001063 for (i--; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001064 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001065 if (dimm->nr_pages == 0)
1066 continue;
Lans Zhang44d22e22012-12-24 14:01:34 +01001067 device_unregister(&dimm->dev);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001068 }
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -03001069fail2:
Lans Zhang44d22e22012-12-24 14:01:34 +01001070 device_unregister(&mci->dev);
Borislav Petkov88d84ac2013-07-19 12:28:25 +02001071 bus_unregister(mci->bus);
1072 kfree(mci->bus->name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001073 return err;
1074}
1075
1076/*
1077 * remove a Memory Controller instance
1078 */
1079void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1080{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001081 int i;
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001082
Joe Perches956b9ba12012-04-29 17:08:39 -03001083 edac_dbg(0, "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001084
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -03001085#ifdef CONFIG_EDAC_DEBUG
1086 debugfs_remove(mci->debugfs);
1087#endif
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001088#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001089 edac_delete_csrow_objects(mci);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001090#endif
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001091
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001092 for (i = 0; i < mci->tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001093 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001094 if (dimm->nr_pages == 0)
1095 continue;
Joe Perches956b9ba12012-04-29 17:08:39 -03001096 edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev));
Lans Zhang44d22e22012-12-24 14:01:34 +01001097 device_unregister(&dimm->dev);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001098 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001099}
Doug Thompson8096cfa2007-07-19 01:50:27 -07001100
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001101void edac_unregister_sysfs(struct mem_ctl_info *mci)
Doug Thompson8096cfa2007-07-19 01:50:27 -07001102{
Joe Perches956b9ba12012-04-29 17:08:39 -03001103 edac_dbg(1, "Unregistering device %s\n", dev_name(&mci->dev));
Lans Zhang44d22e22012-12-24 14:01:34 +01001104 device_unregister(&mci->dev);
Borislav Petkov88d84ac2013-07-19 12:28:25 +02001105 bus_unregister(mci->bus);
1106 kfree(mci->bus->name);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001107}
Doug Thompson8096cfa2007-07-19 01:50:27 -07001108
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001109static void mc_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001110{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001111 /*
1112 * There's no container structure here, as this is just the mci
1113 * parent device, used to create the /sys/devices/mc sysfs node.
1114 * So, there are no attributes on it.
1115 */
Joe Perches956b9ba12012-04-29 17:08:39 -03001116 edac_dbg(1, "Releasing device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001117 kfree(dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001118}
1119
1120static struct device_type mc_attr_type = {
1121 .release = mc_attr_release,
1122};
1123/*
1124 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
1125 */
1126int __init edac_mc_sysfs_init(void)
1127{
1128 struct bus_type *edac_subsys;
1129 int err;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001130
Kay Sieversfe5ff8b2011-12-14 15:21:07 -08001131 /* get the /sys/devices/system/edac subsys reference */
1132 edac_subsys = edac_get_sysfs_subsys();
1133 if (edac_subsys == NULL) {
Joe Perches956b9ba12012-04-29 17:08:39 -03001134 edac_dbg(1, "no edac_subsys\n");
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001135 err = -EINVAL;
1136 goto out;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001137 }
1138
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001139 mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001140 if (!mci_pdev) {
1141 err = -ENOMEM;
1142 goto out_put_sysfs;
1143 }
Doug Thompson8096cfa2007-07-19 01:50:27 -07001144
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001145 mci_pdev->bus = edac_subsys;
1146 mci_pdev->type = &mc_attr_type;
1147 device_initialize(mci_pdev);
1148 dev_set_name(mci_pdev, "mc");
1149
1150 err = device_add(mci_pdev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001151 if (err < 0)
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001152 goto out_dev_free;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001153
Joe Perches956b9ba12012-04-29 17:08:39 -03001154 edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001155
Doug Thompson8096cfa2007-07-19 01:50:27 -07001156 return 0;
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001157
1158 out_dev_free:
1159 kfree(mci_pdev);
1160 out_put_sysfs:
1161 edac_put_sysfs_subsys();
1162 out:
1163 return err;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001164}
1165
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001166void __exit edac_mc_sysfs_exit(void)
Doug Thompson8096cfa2007-07-19 01:50:27 -07001167{
Lans Zhang44d22e22012-12-24 14:01:34 +01001168 device_unregister(mci_pdev);
Kay Sieversfe5ff8b2011-12-14 15:21:07 -08001169 edac_put_sysfs_subsys();
Doug Thompson8096cfa2007-07-19 01:50:27 -07001170}