blob: 67610a6ebf875765682cb50bec4226b42f956fc3 [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 Chehabe7100472013-02-19 08:04:55 -030010 * (c) 2012-2013 - Mauro Carvalho Chehab <mchehab@redhat.com>
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
61 ret = strict_strtol(val, 0, &l);
62 if (ret == -EINVAL || ((int)l != l))
63 return -EINVAL;
64 *((int *)kp->arg) = l;
65
66 /* notify edac_mc engine to reset the poll period */
67 edac_mc_reset_delay_period(l);
68
69 return 0;
70}
71
Douglas Thompson7c9281d2007-07-19 01:49:33 -070072/* Parameter declarations for above */
Dave Jiang4de78c62007-07-19 01:49:54 -070073module_param(edac_mc_panic_on_ue, int, 0644);
74MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on");
75module_param(edac_mc_log_ue, int, 0644);
76MODULE_PARM_DESC(edac_mc_log_ue,
Douglas Thompson079708b2007-07-19 01:49:58 -070077 "Log uncorrectable error to console: 0=off 1=on");
Dave Jiang4de78c62007-07-19 01:49:54 -070078module_param(edac_mc_log_ce, int, 0644);
79MODULE_PARM_DESC(edac_mc_log_ce,
Douglas Thompson079708b2007-07-19 01:49:58 -070080 "Log correctable error to console: 0=off 1=on");
Arthur Jones096846e2008-07-25 01:49:09 -070081module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int,
82 &edac_mc_poll_msec, 0644);
Dave Jiang4de78c62007-07-19 01:49:54 -070083MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070084
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -030085static struct device *mci_pdev;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030086
Douglas Thompson7c9281d2007-07-19 01:49:33 -070087/*
88 * various constants for Memory Controllers
89 */
Borislav Petkov8b7719e2013-03-25 15:41:55 +010090static const char * const mem_types[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -070091 [MEM_EMPTY] = "Empty",
92 [MEM_RESERVED] = "Reserved",
93 [MEM_UNKNOWN] = "Unknown",
94 [MEM_FPM] = "FPM",
95 [MEM_EDO] = "EDO",
96 [MEM_BEDO] = "BEDO",
97 [MEM_SDR] = "Unbuffered-SDR",
98 [MEM_RDR] = "Registered-SDR",
99 [MEM_DDR] = "Unbuffered-DDR",
100 [MEM_RDDR] = "Registered-DDR",
Dave Jiang1a9b85e2007-07-19 01:49:38 -0700101 [MEM_RMBS] = "RMBS",
102 [MEM_DDR2] = "Unbuffered-DDR2",
103 [MEM_FB_DDR2] = "FullyBuffered-DDR2",
Benjamin Herrenschmidt1d5f7262008-02-07 00:14:52 -0800104 [MEM_RDDR2] = "Registered-DDR2",
Yang Shib1cfebc2009-06-30 11:41:22 -0700105 [MEM_XDR] = "XDR",
106 [MEM_DDR3] = "Unbuffered-DDR3",
107 [MEM_RDDR3] = "Registered-DDR3"
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700108};
109
Borislav Petkov8b7719e2013-03-25 15:41:55 +0100110static const char * const dev_types[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700111 [DEV_UNKNOWN] = "Unknown",
112 [DEV_X1] = "x1",
113 [DEV_X2] = "x2",
114 [DEV_X4] = "x4",
115 [DEV_X8] = "x8",
116 [DEV_X16] = "x16",
117 [DEV_X32] = "x32",
118 [DEV_X64] = "x64"
119};
120
Borislav Petkov8b7719e2013-03-25 15:41:55 +0100121static const char * const edac_caps[] = {
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700122 [EDAC_UNKNOWN] = "Unknown",
123 [EDAC_NONE] = "None",
124 [EDAC_RESERVED] = "Reserved",
125 [EDAC_PARITY] = "PARITY",
126 [EDAC_EC] = "EC",
127 [EDAC_SECDED] = "SECDED",
128 [EDAC_S2ECD2ED] = "S2ECD2ED",
129 [EDAC_S4ECD4ED] = "S4ECD4ED",
130 [EDAC_S8ECD8ED] = "S8ECD8ED",
131 [EDAC_S16ECD16ED] = "S16ECD16ED"
132};
133
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300134#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300135/*
136 * EDAC sysfs CSROW data structures and methods
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700137 */
138
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300139#define to_csrow(k) container_of(k, struct csrow_info, dev)
140
141/*
142 * We need it to avoid namespace conflicts between the legacy API
143 * and the per-dimm/per-rank one
144 */
145#define DEVICE_ATTR_LEGACY(_name, _mode, _show, _store) \
Stephen Hemmingerfbe2d362013-02-21 21:44:17 -0800146 static struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300147
148struct dev_ch_attribute {
149 struct device_attribute attr;
150 int channel;
151};
152
153#define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
154 struct dev_ch_attribute dev_attr_legacy_##_name = \
155 { __ATTR(_name, _mode, _show, _store), (_var) }
156
157#define to_channel(k) (container_of(k, struct dev_ch_attribute, attr)->channel)
158
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700159/* Set of more default csrow<id> attribute show/store functions */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300160static ssize_t csrow_ue_count_show(struct device *dev,
161 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700162{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300163 struct csrow_info *csrow = to_csrow(dev);
164
Douglas Thompson079708b2007-07-19 01:49:58 -0700165 return sprintf(data, "%u\n", csrow->ue_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700166}
167
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300168static ssize_t csrow_ce_count_show(struct device *dev,
169 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700170{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300171 struct csrow_info *csrow = to_csrow(dev);
172
Douglas Thompson079708b2007-07-19 01:49:58 -0700173 return sprintf(data, "%u\n", csrow->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700174}
175
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300176static ssize_t csrow_size_show(struct device *dev,
177 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700178{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300179 struct csrow_info *csrow = to_csrow(dev);
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300180 int i;
181 u32 nr_pages = 0;
182
183 for (i = 0; i < csrow->nr_channels; i++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300184 nr_pages += csrow->channels[i]->dimm->nr_pages;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300185 return sprintf(data, "%u\n", PAGES_TO_MiB(nr_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700186}
187
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300188static ssize_t csrow_mem_type_show(struct device *dev,
189 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700190{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300191 struct csrow_info *csrow = to_csrow(dev);
192
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300193 return sprintf(data, "%s\n", mem_types[csrow->channels[0]->dimm->mtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700194}
195
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300196static ssize_t csrow_dev_type_show(struct device *dev,
197 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700198{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300199 struct csrow_info *csrow = to_csrow(dev);
200
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300201 return sprintf(data, "%s\n", dev_types[csrow->channels[0]->dimm->dtype]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700202}
203
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300204static ssize_t csrow_edac_mode_show(struct device *dev,
205 struct device_attribute *mattr,
206 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700207{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300208 struct csrow_info *csrow = to_csrow(dev);
209
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300210 return sprintf(data, "%s\n", edac_caps[csrow->channels[0]->dimm->edac_mode]);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700211}
212
213/* show/store functions for DIMM Label attributes */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300214static ssize_t channel_dimm_label_show(struct device *dev,
215 struct device_attribute *mattr,
216 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700217{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300218 struct csrow_info *csrow = to_csrow(dev);
219 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300220 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300221
Arthur Jones124682c2008-07-25 01:49:12 -0700222 /* if field has not been initialized, there is nothing to send */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300223 if (!rank->dimm->label[0])
Arthur Jones124682c2008-07-25 01:49:12 -0700224 return 0;
225
226 return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n",
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300227 rank->dimm->label);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700228}
229
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300230static ssize_t channel_dimm_label_store(struct device *dev,
231 struct device_attribute *mattr,
232 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700233{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300234 struct csrow_info *csrow = to_csrow(dev);
235 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300236 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300237
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700238 ssize_t max_size = 0;
239
Douglas Thompson079708b2007-07-19 01:49:58 -0700240 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300241 strncpy(rank->dimm->label, data, max_size);
242 rank->dimm->label[max_size] = '\0';
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700243
244 return max_size;
245}
246
247/* show function for dynamic chX_ce_count attribute */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300248static ssize_t channel_ce_count_show(struct device *dev,
249 struct device_attribute *mattr, char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700250{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300251 struct csrow_info *csrow = to_csrow(dev);
252 unsigned chan = to_channel(mattr);
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300253 struct rank_info *rank = csrow->channels[chan];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300254
255 return sprintf(data, "%u\n", rank->ce_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700256}
257
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300258/* cwrow<id>/attribute files */
259DEVICE_ATTR_LEGACY(size_mb, S_IRUGO, csrow_size_show, NULL);
260DEVICE_ATTR_LEGACY(dev_type, S_IRUGO, csrow_dev_type_show, NULL);
261DEVICE_ATTR_LEGACY(mem_type, S_IRUGO, csrow_mem_type_show, NULL);
262DEVICE_ATTR_LEGACY(edac_mode, S_IRUGO, csrow_edac_mode_show, NULL);
263DEVICE_ATTR_LEGACY(ue_count, S_IRUGO, csrow_ue_count_show, NULL);
264DEVICE_ATTR_LEGACY(ce_count, S_IRUGO, csrow_ce_count_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700265
266/* default attributes of the CSROW<id> object */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300267static struct attribute *csrow_attrs[] = {
268 &dev_attr_legacy_dev_type.attr,
269 &dev_attr_legacy_mem_type.attr,
270 &dev_attr_legacy_edac_mode.attr,
271 &dev_attr_legacy_size_mb.attr,
272 &dev_attr_legacy_ue_count.attr,
273 &dev_attr_legacy_ce_count.attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700274 NULL,
275};
276
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300277static struct attribute_group csrow_attr_grp = {
278 .attrs = csrow_attrs,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700279};
280
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300281static const struct attribute_group *csrow_attr_groups[] = {
282 &csrow_attr_grp,
283 NULL
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700284};
285
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300286static void csrow_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300287{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300288 struct csrow_info *csrow = container_of(dev, struct csrow_info, dev);
289
Joe Perches956b9ba2012-04-29 17:08:39 -0300290 edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300291 kfree(csrow);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300292}
293
294static struct device_type csrow_attr_type = {
295 .groups = csrow_attr_groups,
296 .release = csrow_attr_release,
297};
298
299/*
300 * possible dynamic channel DIMM Label attribute files
301 *
302 */
303
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700304#define EDAC_NR_CHANNELS 6
305
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300306DEVICE_CHANNEL(ch0_dimm_label, S_IRUGO | S_IWUSR,
307 channel_dimm_label_show, channel_dimm_label_store, 0);
308DEVICE_CHANNEL(ch1_dimm_label, S_IRUGO | S_IWUSR,
309 channel_dimm_label_show, channel_dimm_label_store, 1);
310DEVICE_CHANNEL(ch2_dimm_label, S_IRUGO | S_IWUSR,
311 channel_dimm_label_show, channel_dimm_label_store, 2);
312DEVICE_CHANNEL(ch3_dimm_label, S_IRUGO | S_IWUSR,
313 channel_dimm_label_show, channel_dimm_label_store, 3);
314DEVICE_CHANNEL(ch4_dimm_label, S_IRUGO | S_IWUSR,
315 channel_dimm_label_show, channel_dimm_label_store, 4);
316DEVICE_CHANNEL(ch5_dimm_label, S_IRUGO | S_IWUSR,
317 channel_dimm_label_show, channel_dimm_label_store, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700318
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300319/* Total possible dynamic DIMM Label attribute file table */
320static struct device_attribute *dynamic_csrow_dimm_attr[] = {
321 &dev_attr_legacy_ch0_dimm_label.attr,
322 &dev_attr_legacy_ch1_dimm_label.attr,
323 &dev_attr_legacy_ch2_dimm_label.attr,
324 &dev_attr_legacy_ch3_dimm_label.attr,
325 &dev_attr_legacy_ch4_dimm_label.attr,
326 &dev_attr_legacy_ch5_dimm_label.attr
327};
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700328
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300329/* possible dynamic channel ce_count attribute files */
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530330DEVICE_CHANNEL(ch0_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300331 channel_ce_count_show, NULL, 0);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530332DEVICE_CHANNEL(ch1_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300333 channel_ce_count_show, NULL, 1);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530334DEVICE_CHANNEL(ch2_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300335 channel_ce_count_show, NULL, 2);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530336DEVICE_CHANNEL(ch3_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300337 channel_ce_count_show, NULL, 3);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530338DEVICE_CHANNEL(ch4_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300339 channel_ce_count_show, NULL, 4);
Srivatsa S. Bhatc8c64d12013-04-30 15:17:16 +0530340DEVICE_CHANNEL(ch5_ce_count, S_IRUGO,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300341 channel_ce_count_show, NULL, 5);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700342
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300343/* Total possible dynamic ce_count attribute file table */
344static struct device_attribute *dynamic_csrow_ce_count_attr[] = {
345 &dev_attr_legacy_ch0_ce_count.attr,
346 &dev_attr_legacy_ch1_ce_count.attr,
347 &dev_attr_legacy_ch2_ce_count.attr,
348 &dev_attr_legacy_ch3_ce_count.attr,
349 &dev_attr_legacy_ch4_ce_count.attr,
350 &dev_attr_legacy_ch5_ce_count.attr
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700351};
352
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300353static inline int nr_pages_per_csrow(struct csrow_info *csrow)
354{
355 int chan, nr_pages = 0;
356
357 for (chan = 0; chan < csrow->nr_channels; chan++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300358 nr_pages += csrow->channels[chan]->dimm->nr_pages;
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300359
360 return nr_pages;
361}
362
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700363/* Create a CSROW object under specifed edac_mc_device */
Doug Thompson8096cfa2007-07-19 01:50:27 -0700364static int edac_create_csrow_object(struct mem_ctl_info *mci,
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300365 struct csrow_info *csrow, int index)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700366{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300367 int err, chan;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700368
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300369 if (csrow->nr_channels >= EDAC_NR_CHANNELS)
370 return -ENODEV;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700371
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300372 csrow->dev.type = &csrow_attr_type;
373 csrow->dev.bus = &mci->bus;
374 device_initialize(&csrow->dev);
375 csrow->dev.parent = &mci->dev;
Borislav Petkov921a6892012-09-13 18:46:39 +0200376 csrow->mci = mci;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300377 dev_set_name(&csrow->dev, "csrow%d", index);
378 dev_set_drvdata(&csrow->dev, csrow);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700379
Joe Perches956b9ba2012-04-29 17:08:39 -0300380 edac_dbg(0, "creating (virtual) csrow node %s\n",
381 dev_name(&csrow->dev));
Doug Thompson8096cfa2007-07-19 01:50:27 -0700382
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300383 err = device_add(&csrow->dev);
384 if (err < 0)
385 return err;
Doug Thompson8096cfa2007-07-19 01:50:27 -0700386
Doug Thompson8096cfa2007-07-19 01:50:27 -0700387 for (chan = 0; chan < csrow->nr_channels; chan++) {
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300388 /* Only expose populated DIMMs */
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300389 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300390 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300391 err = device_create_file(&csrow->dev,
392 dynamic_csrow_dimm_attr[chan]);
393 if (err < 0)
394 goto error;
395 err = device_create_file(&csrow->dev,
396 dynamic_csrow_ce_count_attr[chan]);
397 if (err < 0) {
398 device_remove_file(&csrow->dev,
399 dynamic_csrow_dimm_attr[chan]);
400 goto error;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700401 }
402 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300403
Doug Thompson8096cfa2007-07-19 01:50:27 -0700404 return 0;
405
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300406error:
407 for (--chan; chan >= 0; chan--) {
408 device_remove_file(&csrow->dev,
409 dynamic_csrow_dimm_attr[chan]);
410 device_remove_file(&csrow->dev,
411 dynamic_csrow_ce_count_attr[chan]);
412 }
413 put_device(&csrow->dev);
Doug Thompson8096cfa2007-07-19 01:50:27 -0700414
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700415 return err;
416}
417
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300418/* Create a CSROW object under specifed edac_mc_device */
419static int edac_create_csrow_objects(struct mem_ctl_info *mci)
420{
421 int err, i, chan;
422 struct csrow_info *csrow;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700423
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300424 for (i = 0; i < mci->nr_csrows; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300425 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300426 if (!nr_pages_per_csrow(csrow))
427 continue;
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300428 err = edac_create_csrow_object(mci, mci->csrows[i], i);
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -0300429 if (err < 0) {
430 edac_dbg(1,
431 "failure: create csrow objects for csrow %d\n",
432 i);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300433 goto error;
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -0300434 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300435 }
436 return 0;
437
438error:
439 for (--i; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300440 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300441 if (!nr_pages_per_csrow(csrow))
442 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300443 for (chan = csrow->nr_channels - 1; chan >= 0; chan--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300444 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300445 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300446 device_remove_file(&csrow->dev,
447 dynamic_csrow_dimm_attr[chan]);
448 device_remove_file(&csrow->dev,
449 dynamic_csrow_ce_count_attr[chan]);
450 }
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300451 put_device(&mci->csrows[i]->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300452 }
453
454 return err;
455}
456
457static void edac_delete_csrow_objects(struct mem_ctl_info *mci)
458{
459 int i, chan;
460 struct csrow_info *csrow;
461
462 for (i = mci->nr_csrows - 1; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300463 csrow = mci->csrows[i];
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300464 if (!nr_pages_per_csrow(csrow))
465 continue;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300466 for (chan = csrow->nr_channels - 1; chan >= 0; chan--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300467 if (!csrow->channels[chan]->dimm->nr_pages)
Mauro Carvalho Chehabe39f4ea2012-03-29 12:20:22 -0300468 continue;
Joe Perches956b9ba2012-04-29 17:08:39 -0300469 edac_dbg(1, "Removing csrow %d channel %d sysfs nodes\n",
470 i, chan);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300471 device_remove_file(&csrow->dev,
472 dynamic_csrow_dimm_attr[chan]);
473 device_remove_file(&csrow->dev,
474 dynamic_csrow_ce_count_attr[chan]);
475 }
Lans Zhang44d22e22012-12-24 14:01:34 +0100476 device_unregister(&mci->csrows[i]->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300477 }
478}
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300479#endif
480
481/*
482 * Per-dimm (or per-rank) devices
483 */
484
485#define to_dimm(k) container_of(k, struct dimm_info, dev)
486
487/* show/store functions for DIMM Label attributes */
488static ssize_t dimmdev_location_show(struct device *dev,
489 struct device_attribute *mattr, char *data)
490{
491 struct dimm_info *dimm = to_dimm(dev);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300492
Mauro Carvalho Chehab6e84d352012-04-30 10:24:43 -0300493 return edac_dimm_info_location(dimm, data, PAGE_SIZE);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300494}
495
496static ssize_t dimmdev_label_show(struct device *dev,
497 struct device_attribute *mattr, char *data)
498{
499 struct dimm_info *dimm = to_dimm(dev);
500
501 /* if field has not been initialized, there is nothing to send */
502 if (!dimm->label[0])
503 return 0;
504
505 return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", dimm->label);
506}
507
508static ssize_t dimmdev_label_store(struct device *dev,
509 struct device_attribute *mattr,
510 const char *data,
511 size_t count)
512{
513 struct dimm_info *dimm = to_dimm(dev);
514
515 ssize_t max_size = 0;
516
517 max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1);
518 strncpy(dimm->label, data, max_size);
519 dimm->label[max_size] = '\0';
520
521 return max_size;
522}
523
524static ssize_t dimmdev_size_show(struct device *dev,
525 struct device_attribute *mattr, char *data)
526{
527 struct dimm_info *dimm = to_dimm(dev);
528
529 return sprintf(data, "%u\n", PAGES_TO_MiB(dimm->nr_pages));
530}
531
532static ssize_t dimmdev_mem_type_show(struct device *dev,
533 struct device_attribute *mattr, char *data)
534{
535 struct dimm_info *dimm = to_dimm(dev);
536
537 return sprintf(data, "%s\n", mem_types[dimm->mtype]);
538}
539
540static ssize_t dimmdev_dev_type_show(struct device *dev,
541 struct device_attribute *mattr, char *data)
542{
543 struct dimm_info *dimm = to_dimm(dev);
544
545 return sprintf(data, "%s\n", dev_types[dimm->dtype]);
546}
547
548static ssize_t dimmdev_edac_mode_show(struct device *dev,
549 struct device_attribute *mattr,
550 char *data)
551{
552 struct dimm_info *dimm = to_dimm(dev);
553
554 return sprintf(data, "%s\n", edac_caps[dimm->edac_mode]);
555}
556
557/* dimm/rank attribute files */
558static DEVICE_ATTR(dimm_label, S_IRUGO | S_IWUSR,
559 dimmdev_label_show, dimmdev_label_store);
560static DEVICE_ATTR(dimm_location, S_IRUGO, dimmdev_location_show, NULL);
561static DEVICE_ATTR(size, S_IRUGO, dimmdev_size_show, NULL);
562static DEVICE_ATTR(dimm_mem_type, S_IRUGO, dimmdev_mem_type_show, NULL);
563static DEVICE_ATTR(dimm_dev_type, S_IRUGO, dimmdev_dev_type_show, NULL);
564static DEVICE_ATTR(dimm_edac_mode, S_IRUGO, dimmdev_edac_mode_show, NULL);
565
566/* attributes of the dimm<id>/rank<id> object */
567static struct attribute *dimm_attrs[] = {
568 &dev_attr_dimm_label.attr,
569 &dev_attr_dimm_location.attr,
570 &dev_attr_size.attr,
571 &dev_attr_dimm_mem_type.attr,
572 &dev_attr_dimm_dev_type.attr,
573 &dev_attr_dimm_edac_mode.attr,
574 NULL,
575};
576
577static struct attribute_group dimm_attr_grp = {
578 .attrs = dimm_attrs,
579};
580
581static const struct attribute_group *dimm_attr_groups[] = {
582 &dimm_attr_grp,
583 NULL
584};
585
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300586static void dimm_attr_release(struct device *dev)
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300587{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300588 struct dimm_info *dimm = container_of(dev, struct dimm_info, dev);
589
Joe Perches956b9ba2012-04-29 17:08:39 -0300590 edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300591 kfree(dimm);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300592}
593
594static struct device_type dimm_attr_type = {
595 .groups = dimm_attr_groups,
596 .release = dimm_attr_release,
597};
598
599/* Create a DIMM object under specifed memory controller device */
600static int edac_create_dimm_object(struct mem_ctl_info *mci,
601 struct dimm_info *dimm,
602 int index)
603{
604 int err;
605 dimm->mci = mci;
606
607 dimm->dev.type = &dimm_attr_type;
608 dimm->dev.bus = &mci->bus;
609 device_initialize(&dimm->dev);
610
611 dimm->dev.parent = &mci->dev;
Mauro Carvalho Chehab9713fae2013-03-11 09:28:48 -0300612 if (mci->csbased)
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300613 dev_set_name(&dimm->dev, "rank%d", index);
614 else
615 dev_set_name(&dimm->dev, "dimm%d", index);
616 dev_set_drvdata(&dimm->dev, dimm);
617 pm_runtime_forbid(&mci->dev);
618
619 err = device_add(&dimm->dev);
620
Joe Perches956b9ba2012-04-29 17:08:39 -0300621 edac_dbg(0, "creating rank/dimm device %s\n", dev_name(&dimm->dev));
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -0300622
623 return err;
624}
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300625
626/*
627 * Memory controller device
628 */
629
630#define to_mci(k) container_of(k, struct mem_ctl_info, dev)
631
632static ssize_t mci_reset_counters_store(struct device *dev,
633 struct device_attribute *mattr,
Douglas Thompson079708b2007-07-19 01:49:58 -0700634 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700635{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300636 struct mem_ctl_info *mci = to_mci(dev);
637 int cnt, row, chan, i;
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300638 mci->ue_mc = 0;
639 mci->ce_mc = 0;
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300640 mci->ue_noinfo_count = 0;
641 mci->ce_noinfo_count = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700642
643 for (row = 0; row < mci->nr_csrows; row++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300644 struct csrow_info *ri = mci->csrows[row];
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700645
646 ri->ue_count = 0;
647 ri->ce_count = 0;
648
649 for (chan = 0; chan < ri->nr_channels; chan++)
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300650 ri->channels[chan]->ce_count = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700651 }
652
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300653 cnt = 1;
654 for (i = 0; i < mci->n_layers; i++) {
655 cnt *= mci->layers[i].size;
656 memset(mci->ce_per_layer[i], 0, cnt * sizeof(u32));
657 memset(mci->ue_per_layer[i], 0, cnt * sizeof(u32));
658 }
659
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700660 mci->start_time = jiffies;
661 return count;
662}
663
Borislav Petkov39094442010-11-24 19:52:09 +0100664/* Memory scrubbing interface:
665 *
666 * A MC driver can limit the scrubbing bandwidth based on the CPU type.
667 * Therefore, ->set_sdram_scrub_rate should be made to return the actual
668 * bandwidth that is accepted or 0 when scrubbing is to be disabled.
669 *
670 * Negative value still means that an error has occurred while setting
671 * the scrub rate.
672 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300673static ssize_t mci_sdram_scrub_rate_store(struct device *dev,
674 struct device_attribute *mattr,
Borislav Petkoveba042a2010-05-25 18:21:07 +0200675 const char *data, size_t count)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700676{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300677 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkoveba042a2010-05-25 18:21:07 +0200678 unsigned long bandwidth = 0;
Borislav Petkov39094442010-11-24 19:52:09 +0100679 int new_bw = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700680
Borislav Petkoveba042a2010-05-25 18:21:07 +0200681 if (strict_strtoul(data, 10, &bandwidth) < 0)
682 return -EINVAL;
683
Borislav Petkov39094442010-11-24 19:52:09 +0100684 new_bw = mci->set_sdram_scrub_rate(mci, bandwidth);
Markus Trippelsdorf49496032011-04-20 14:28:45 -0400685 if (new_bw < 0) {
686 edac_printk(KERN_WARNING, EDAC_MC,
687 "Error setting scrub rate to: %lu\n", bandwidth);
688 return -EINVAL;
Borislav Petkoveba042a2010-05-25 18:21:07 +0200689 }
Borislav Petkov39094442010-11-24 19:52:09 +0100690
Markus Trippelsdorf49496032011-04-20 14:28:45 -0400691 return count;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700692}
693
Borislav Petkov39094442010-11-24 19:52:09 +0100694/*
695 * ->get_sdram_scrub_rate() return value semantics same as above.
696 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300697static ssize_t mci_sdram_scrub_rate_show(struct device *dev,
698 struct device_attribute *mattr,
699 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700700{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300701 struct mem_ctl_info *mci = to_mci(dev);
Borislav Petkov39094442010-11-24 19:52:09 +0100702 int bandwidth = 0;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700703
Borislav Petkov39094442010-11-24 19:52:09 +0100704 bandwidth = mci->get_sdram_scrub_rate(mci);
705 if (bandwidth < 0) {
706 edac_printk(KERN_DEBUG, EDAC_MC, "Error reading scrub rate\n");
707 return bandwidth;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700708 }
Borislav Petkoveba042a2010-05-25 18:21:07 +0200709
Borislav Petkov39094442010-11-24 19:52:09 +0100710 return sprintf(data, "%d\n", bandwidth);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700711}
712
713/* default attribute files for the MCI object */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300714static ssize_t mci_ue_count_show(struct device *dev,
715 struct device_attribute *mattr,
716 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700717{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300718 struct mem_ctl_info *mci = to_mci(dev);
719
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300720 return sprintf(data, "%d\n", mci->ue_mc);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700721}
722
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300723static ssize_t mci_ce_count_show(struct device *dev,
724 struct device_attribute *mattr,
725 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700726{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300727 struct mem_ctl_info *mci = to_mci(dev);
728
Mauro Carvalho Chehab5926ff52012-02-09 11:05:20 -0300729 return sprintf(data, "%d\n", mci->ce_mc);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700730}
731
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300732static ssize_t mci_ce_noinfo_show(struct device *dev,
733 struct device_attribute *mattr,
734 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700735{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300736 struct mem_ctl_info *mci = to_mci(dev);
737
Douglas Thompson079708b2007-07-19 01:49:58 -0700738 return sprintf(data, "%d\n", mci->ce_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700739}
740
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300741static ssize_t mci_ue_noinfo_show(struct device *dev,
742 struct device_attribute *mattr,
743 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700744{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300745 struct mem_ctl_info *mci = to_mci(dev);
746
Douglas Thompson079708b2007-07-19 01:49:58 -0700747 return sprintf(data, "%d\n", mci->ue_noinfo_count);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700748}
749
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300750static ssize_t mci_seconds_show(struct device *dev,
751 struct device_attribute *mattr,
752 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700753{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300754 struct mem_ctl_info *mci = to_mci(dev);
755
Douglas Thompson079708b2007-07-19 01:49:58 -0700756 return sprintf(data, "%ld\n", (jiffies - mci->start_time) / HZ);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700757}
758
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300759static ssize_t mci_ctl_name_show(struct device *dev,
760 struct device_attribute *mattr,
761 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700762{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300763 struct mem_ctl_info *mci = to_mci(dev);
764
Douglas Thompson079708b2007-07-19 01:49:58 -0700765 return sprintf(data, "%s\n", mci->ctl_name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700766}
767
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300768static ssize_t mci_size_mb_show(struct device *dev,
769 struct device_attribute *mattr,
770 char *data)
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700771{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300772 struct mem_ctl_info *mci = to_mci(dev);
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300773 int total_pages = 0, csrow_idx, j;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700774
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300775 for (csrow_idx = 0; csrow_idx < mci->nr_csrows; csrow_idx++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300776 struct csrow_info *csrow = mci->csrows[csrow_idx];
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700777
Mauro Carvalho Chehab1eef1282013-03-11 09:07:46 -0300778 for (j = 0; j < csrow->nr_channels; j++) {
779 struct dimm_info *dimm = csrow->channels[j]->dimm;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700780
Mauro Carvalho Chehab1eef1282013-03-11 09:07:46 -0300781 total_pages += dimm->nr_pages;
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -0300782 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700783 }
784
Douglas Thompson079708b2007-07-19 01:49:58 -0700785 return sprintf(data, "%u\n", PAGES_TO_MiB(total_pages));
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700786}
787
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300788static ssize_t mci_max_location_show(struct device *dev,
789 struct device_attribute *mattr,
790 char *data)
791{
792 struct mem_ctl_info *mci = to_mci(dev);
793 int i;
794 char *p = data;
795
796 for (i = 0; i < mci->n_layers; i++) {
797 p += sprintf(p, "%s %d ",
798 edac_layer_name[mci->layers[i].type],
799 mci->layers[i].size - 1);
800 }
801
802 return p - data;
803}
804
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300805#ifdef CONFIG_EDAC_DEBUG
806static ssize_t edac_fake_inject_write(struct file *file,
807 const char __user *data,
808 size_t count, loff_t *ppos)
809{
810 struct device *dev = file->private_data;
811 struct mem_ctl_info *mci = to_mci(dev);
812 static enum hw_event_mc_err_type type;
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300813 u16 errcount = mci->fake_inject_count;
814
815 if (!errcount)
816 errcount = 1;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300817
818 type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED
819 : HW_EVENT_ERR_CORRECTED;
820
821 printk(KERN_DEBUG
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300822 "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",
823 errcount,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300824 (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE",
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300825 errcount > 1 ? "s" : "",
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300826 mci->fake_inject_layer[0],
827 mci->fake_inject_layer[1],
828 mci->fake_inject_layer[2]
829 );
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300830 edac_mc_handle_error(type, mci, errcount, 0, 0, 0,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300831 mci->fake_inject_layer[0],
832 mci->fake_inject_layer[1],
833 mci->fake_inject_layer[2],
Mauro Carvalho Chehab03f7eae2012-06-04 11:29:25 -0300834 "FAKE ERROR", "for EDAC testing only");
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300835
836 return count;
837}
838
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300839static const struct file_operations debug_fake_inject_fops = {
Wei Yongjundb7312a2012-10-17 16:32:01 +0800840 .open = simple_open,
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300841 .write = edac_fake_inject_write,
842 .llseek = generic_file_llseek,
843};
844#endif
845
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700846/* default Control file */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300847DEVICE_ATTR(reset_counters, S_IWUSR, NULL, mci_reset_counters_store);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700848
849/* default Attribute files */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300850DEVICE_ATTR(mc_name, S_IRUGO, mci_ctl_name_show, NULL);
851DEVICE_ATTR(size_mb, S_IRUGO, mci_size_mb_show, NULL);
852DEVICE_ATTR(seconds_since_reset, S_IRUGO, mci_seconds_show, NULL);
853DEVICE_ATTR(ue_noinfo_count, S_IRUGO, mci_ue_noinfo_show, NULL);
854DEVICE_ATTR(ce_noinfo_count, S_IRUGO, mci_ce_noinfo_show, NULL);
855DEVICE_ATTR(ue_count, S_IRUGO, mci_ue_count_show, NULL);
856DEVICE_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL);
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300857DEVICE_ATTR(max_location, S_IRUGO, mci_max_location_show, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700858
859/* memory scrubber attribute file */
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -0300860DEVICE_ATTR(sdram_scrub_rate, 0, NULL, NULL);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700861
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300862static struct attribute *mci_attrs[] = {
863 &dev_attr_reset_counters.attr,
864 &dev_attr_mc_name.attr,
865 &dev_attr_size_mb.attr,
866 &dev_attr_seconds_since_reset.attr,
867 &dev_attr_ue_noinfo_count.attr,
868 &dev_attr_ce_noinfo_count.attr,
869 &dev_attr_ue_count.attr,
870 &dev_attr_ce_count.attr,
Mauro Carvalho Chehab8ad6c782012-03-21 17:13:24 -0300871 &dev_attr_max_location.attr,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700872 NULL
873};
874
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300875static struct attribute_group mci_attr_grp = {
876 .attrs = mci_attrs,
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700877};
878
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300879static const struct attribute_group *mci_attr_groups[] = {
880 &mci_attr_grp,
881 NULL
Mauro Carvalho Chehabcc301b32009-09-24 16:23:42 -0300882};
883
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300884static void mci_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300885{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300886 struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
887
Joe Perches956b9ba2012-04-29 17:08:39 -0300888 edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300889 kfree(mci);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300890}
891
892static struct device_type mci_attr_type = {
893 .groups = mci_attr_groups,
894 .release = mci_attr_release,
Mauro Carvalho Chehabcc301b32009-09-24 16:23:42 -0300895};
896
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300897#ifdef CONFIG_EDAC_DEBUG
Rob Herringe7930ba2012-06-11 21:32:12 -0500898static struct dentry *edac_debugfs;
899
900int __init edac_debugfs_init(void)
901{
902 edac_debugfs = debugfs_create_dir("edac", NULL);
903 if (IS_ERR(edac_debugfs)) {
904 edac_debugfs = NULL;
905 return -ENOMEM;
906 }
907 return 0;
908}
909
910void __exit edac_debugfs_exit(void)
911{
912 debugfs_remove(edac_debugfs);
913}
914
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300915int edac_create_debug_nodes(struct mem_ctl_info *mci)
916{
917 struct dentry *d, *parent;
918 char name[80];
919 int i;
920
Rob Herringe7930ba2012-06-11 21:32:12 -0500921 if (!edac_debugfs)
922 return -ENODEV;
923
924 d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300925 if (!d)
926 return -ENOMEM;
927 parent = d;
928
929 for (i = 0; i < mci->n_layers; i++) {
930 sprintf(name, "fake_inject_%s",
931 edac_layer_name[mci->layers[i].type]);
932 d = debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent,
933 &mci->fake_inject_layer[i]);
934 if (!d)
935 goto nomem;
936 }
937
938 d = debugfs_create_bool("fake_inject_ue", S_IRUGO | S_IWUSR, parent,
939 &mci->fake_inject_ue);
940 if (!d)
941 goto nomem;
942
Mauro Carvalho Chehab38ced282012-06-12 10:55:57 -0300943 d = debugfs_create_u16("fake_inject_count", S_IRUGO | S_IWUSR, parent,
944 &mci->fake_inject_count);
945 if (!d)
946 goto nomem;
947
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300948 d = debugfs_create_file("fake_inject", S_IWUSR, parent,
949 &mci->dev,
950 &debug_fake_inject_fops);
951 if (!d)
952 goto nomem;
953
Rob Herringe7930ba2012-06-11 21:32:12 -0500954 mci->debugfs = parent;
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -0300955 return 0;
956nomem:
957 debugfs_remove(mci->debugfs);
958 return -ENOMEM;
959}
960#endif
961
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700962/*
963 * Create a new Memory Controller kobject instance,
964 * mc<id> under the 'mc' directory
965 *
966 * Return:
967 * 0 Success
968 * !0 Failure
969 */
970int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
971{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300972 int i, err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700973
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300974 /*
975 * The memory controller needs its own bus, in order to avoid
976 * namespace conflicts at /sys/bus/edac.
Douglas Thompson42a8e392007-07-19 01:50:10 -0700977 */
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300978 mci->bus.name = kasprintf(GFP_KERNEL, "mc%d", mci->mc_idx);
979 if (!mci->bus.name)
980 return -ENOMEM;
Joe Perches956b9ba2012-04-29 17:08:39 -0300981 edac_dbg(0, "creating bus %s\n", mci->bus.name);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300982 err = bus_register(&mci->bus);
983 if (err < 0)
984 return err;
985
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -0300986 /* get the /sys/devices/system/edac subsys reference */
987 mci->dev.type = &mci_attr_type;
988 device_initialize(&mci->dev);
989
990 mci->dev.parent = mci_pdev;
991 mci->dev.bus = &mci->bus;
992 dev_set_name(&mci->dev, "mc%d", mci->mc_idx);
993 dev_set_drvdata(&mci->dev, mci);
994 pm_runtime_forbid(&mci->dev);
995
Joe Perches956b9ba2012-04-29 17:08:39 -0300996 edac_dbg(0, "creating device %s\n", dev_name(&mci->dev));
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300997 err = device_add(&mci->dev);
998 if (err < 0) {
Mauro Carvalho Chehab3d958822013-02-15 07:51:25 -0300999 edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev));
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001000 bus_unregister(&mci->bus);
1001 kfree(mci->bus.name);
1002 return err;
Douglas Thompson42a8e392007-07-19 01:50:10 -07001003 }
1004
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -03001005 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
1006 if (mci->get_sdram_scrub_rate) {
1007 dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
1008 dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
1009 }
1010 if (mci->set_sdram_scrub_rate) {
1011 dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
1012 dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
1013 }
1014 err = device_create_file(&mci->dev,
1015 &dev_attr_sdram_scrub_rate);
1016 if (err) {
1017 edac_dbg(1, "failure: create sdram_scrub_rate\n");
1018 goto fail2;
1019 }
1020 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001021 /*
1022 * Create the dimm/rank devices
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001023 */
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001024 for (i = 0; i < mci->tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001025 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001026 /* Only expose populated DIMMs */
1027 if (dimm->nr_pages == 0)
1028 continue;
1029#ifdef CONFIG_EDAC_DEBUG
Joe Perches956b9ba2012-04-29 17:08:39 -03001030 edac_dbg(1, "creating dimm%d, located at ", i);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001031 if (edac_debug_level >= 1) {
1032 int lay;
1033 for (lay = 0; lay < mci->n_layers; lay++)
1034 printk(KERN_CONT "%s %d ",
1035 edac_layer_name[mci->layers[lay].type],
1036 dimm->location[lay]);
1037 printk(KERN_CONT "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001038 }
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001039#endif
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001040 err = edac_create_dimm_object(mci, dimm, i);
1041 if (err) {
Joe Perches956b9ba2012-04-29 17:08:39 -03001042 edac_dbg(1, "failure: create dimm %d obj\n", i);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001043 goto fail;
1044 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001045 }
1046
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001047#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001048 err = edac_create_csrow_objects(mci);
1049 if (err < 0)
1050 goto fail;
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001051#endif
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001052
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -03001053#ifdef CONFIG_EDAC_DEBUG
1054 edac_create_debug_nodes(mci);
1055#endif
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001056 return 0;
1057
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001058fail:
Douglas Thompson079708b2007-07-19 01:49:58 -07001059 for (i--; i >= 0; i--) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001060 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001061 if (dimm->nr_pages == 0)
1062 continue;
Lans Zhang44d22e22012-12-24 14:01:34 +01001063 device_unregister(&dimm->dev);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001064 }
Mauro Carvalho Chehabe7100472013-02-19 08:04:55 -03001065fail2:
Lans Zhang44d22e22012-12-24 14:01:34 +01001066 device_unregister(&mci->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001067 bus_unregister(&mci->bus);
1068 kfree(mci->bus.name);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001069 return err;
1070}
1071
1072/*
1073 * remove a Memory Controller instance
1074 */
1075void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1076{
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001077 int i;
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001078
Joe Perches956b9ba2012-04-29 17:08:39 -03001079 edac_dbg(0, "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001080
Mauro Carvalho Chehab452a6bf2012-03-26 09:35:11 -03001081#ifdef CONFIG_EDAC_DEBUG
1082 debugfs_remove(mci->debugfs);
1083#endif
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001084#ifdef CONFIG_EDAC_LEGACY_SYSFS
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001085 edac_delete_csrow_objects(mci);
Mauro Carvalho Chehab19974712012-03-21 17:06:53 -03001086#endif
Mauro Carvalho Chehaba895bf82012-01-28 09:09:38 -03001087
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001088 for (i = 0; i < mci->tot_dimms; i++) {
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001089 struct dimm_info *dimm = mci->dimms[i];
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001090 if (dimm->nr_pages == 0)
1091 continue;
Joe Perches956b9ba2012-04-29 17:08:39 -03001092 edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev));
Lans Zhang44d22e22012-12-24 14:01:34 +01001093 device_unregister(&dimm->dev);
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001094 }
Douglas Thompson7c9281d2007-07-19 01:49:33 -07001095}
Doug Thompson8096cfa2007-07-19 01:50:27 -07001096
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001097void edac_unregister_sysfs(struct mem_ctl_info *mci)
Doug Thompson8096cfa2007-07-19 01:50:27 -07001098{
Joe Perches956b9ba2012-04-29 17:08:39 -03001099 edac_dbg(1, "Unregistering device %s\n", dev_name(&mci->dev));
Lans Zhang44d22e22012-12-24 14:01:34 +01001100 device_unregister(&mci->dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001101 bus_unregister(&mci->bus);
1102 kfree(mci->bus.name);
1103}
Doug Thompson8096cfa2007-07-19 01:50:27 -07001104
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001105static void mc_attr_release(struct device *dev)
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001106{
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001107 /*
1108 * There's no container structure here, as this is just the mci
1109 * parent device, used to create the /sys/devices/mc sysfs node.
1110 * So, there are no attributes on it.
1111 */
Joe Perches956b9ba2012-04-29 17:08:39 -03001112 edac_dbg(1, "Releasing device %s\n", dev_name(dev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001113 kfree(dev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001114}
1115
1116static struct device_type mc_attr_type = {
1117 .release = mc_attr_release,
1118};
1119/*
1120 * Init/exit code for the module. Basically, creates/removes /sys/class/rc
1121 */
1122int __init edac_mc_sysfs_init(void)
1123{
1124 struct bus_type *edac_subsys;
1125 int err;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001126
Kay Sieversfe5ff8b2011-12-14 15:21:07 -08001127 /* get the /sys/devices/system/edac subsys reference */
1128 edac_subsys = edac_get_sysfs_subsys();
1129 if (edac_subsys == NULL) {
Joe Perches956b9ba2012-04-29 17:08:39 -03001130 edac_dbg(1, "no edac_subsys\n");
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001131 err = -EINVAL;
1132 goto out;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001133 }
1134
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001135 mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL);
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001136 if (!mci_pdev) {
1137 err = -ENOMEM;
1138 goto out_put_sysfs;
1139 }
Doug Thompson8096cfa2007-07-19 01:50:27 -07001140
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001141 mci_pdev->bus = edac_subsys;
1142 mci_pdev->type = &mc_attr_type;
1143 device_initialize(mci_pdev);
1144 dev_set_name(mci_pdev, "mc");
1145
1146 err = device_add(mci_pdev);
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001147 if (err < 0)
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001148 goto out_dev_free;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001149
Joe Perches956b9ba2012-04-29 17:08:39 -03001150 edac_dbg(0, "device %s created\n", dev_name(mci_pdev));
Mauro Carvalho Chehabde3910eb2012-04-24 15:05:43 -03001151
Doug Thompson8096cfa2007-07-19 01:50:27 -07001152 return 0;
Denis Kirjanov2d56b102012-10-25 19:42:58 +04001153
1154 out_dev_free:
1155 kfree(mci_pdev);
1156 out_put_sysfs:
1157 edac_put_sysfs_subsys();
1158 out:
1159 return err;
Doug Thompson8096cfa2007-07-19 01:50:27 -07001160}
1161
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -03001162void __exit edac_mc_sysfs_exit(void)
Doug Thompson8096cfa2007-07-19 01:50:27 -07001163{
Lans Zhang44d22e22012-12-24 14:01:34 +01001164 device_unregister(mci_pdev);
Kay Sieversfe5ff8b2011-12-14 15:21:07 -08001165 edac_put_sysfs_subsys();
Doug Thompson8096cfa2007-07-19 01:50:27 -07001166}