Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * edac_mc kernel module |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 3 | * (C) 2005-2007 Linux Networx (http://lnxi.com) |
| 4 | * |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 5 | * This file may be distributed under the terms of the |
| 6 | * GNU General Public License. |
| 7 | * |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 8 | * Written Doug Thompson <norsk5@xmission.com> www.softwarebitmaker.com |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 9 | * |
Mauro Carvalho Chehab | e710047 | 2013-02-19 08:04:55 -0300 | [diff] [blame] | 10 | * (c) 2012-2013 - Mauro Carvalho Chehab <mchehab@redhat.com> |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 11 | * The entire API were re-written, and ported to use struct device |
| 12 | * |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 15 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 17 | #include <linux/edac.h> |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 18 | #include <linux/bug.h> |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 19 | #include <linux/pm_runtime.h> |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 21 | |
Douglas Thompson | 20bcb7a | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 22 | #include "edac_core.h" |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 23 | #include "edac_module.h" |
| 24 | |
| 25 | /* MC EDAC Controls, setable by module parameter, and sysfs */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 26 | static int edac_mc_log_ue = 1; |
| 27 | static int edac_mc_log_ce = 1; |
Douglas Thompson | f044091 | 2007-07-19 01:50:19 -0700 | [diff] [blame] | 28 | static int edac_mc_panic_on_ue; |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 29 | static int edac_mc_poll_msec = 1000; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 30 | |
| 31 | /* Getter functions for above */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 32 | int edac_mc_get_log_ue(void) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 33 | { |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 34 | return edac_mc_log_ue; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 37 | int edac_mc_get_log_ce(void) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 38 | { |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 39 | return edac_mc_log_ce; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 42 | int edac_mc_get_panic_on_ue(void) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 43 | { |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 44 | return edac_mc_panic_on_ue; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 47 | /* this is temporary */ |
| 48 | int edac_mc_get_poll_msec(void) |
| 49 | { |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 50 | return edac_mc_poll_msec; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Arthur Jones | 096846e | 2008-07-25 01:49:09 -0700 | [diff] [blame] | 53 | static 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 72 | /* Parameter declarations for above */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 73 | module_param(edac_mc_panic_on_ue, int, 0644); |
| 74 | MODULE_PARM_DESC(edac_mc_panic_on_ue, "Panic on uncorrected error: 0=off 1=on"); |
| 75 | module_param(edac_mc_log_ue, int, 0644); |
| 76 | MODULE_PARM_DESC(edac_mc_log_ue, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 77 | "Log uncorrectable error to console: 0=off 1=on"); |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 78 | module_param(edac_mc_log_ce, int, 0644); |
| 79 | MODULE_PARM_DESC(edac_mc_log_ce, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 80 | "Log correctable error to console: 0=off 1=on"); |
Arthur Jones | 096846e | 2008-07-25 01:49:09 -0700 | [diff] [blame] | 81 | module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int, |
| 82 | &edac_mc_poll_msec, 0644); |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 83 | MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 84 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 85 | static struct device *mci_pdev; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 86 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 87 | /* |
| 88 | * various constants for Memory Controllers |
| 89 | */ |
Borislav Petkov | 8b7719e | 2013-03-25 15:41:55 +0100 | [diff] [blame] | 90 | static const char * const mem_types[] = { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 91 | [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 Jiang | 1a9b85e | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 101 | [MEM_RMBS] = "RMBS", |
| 102 | [MEM_DDR2] = "Unbuffered-DDR2", |
| 103 | [MEM_FB_DDR2] = "FullyBuffered-DDR2", |
Benjamin Herrenschmidt | 1d5f726 | 2008-02-07 00:14:52 -0800 | [diff] [blame] | 104 | [MEM_RDDR2] = "Registered-DDR2", |
Yang Shi | b1cfebc | 2009-06-30 11:41:22 -0700 | [diff] [blame] | 105 | [MEM_XDR] = "XDR", |
| 106 | [MEM_DDR3] = "Unbuffered-DDR3", |
| 107 | [MEM_RDDR3] = "Registered-DDR3" |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Borislav Petkov | 8b7719e | 2013-03-25 15:41:55 +0100 | [diff] [blame] | 110 | static const char * const dev_types[] = { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 111 | [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 Petkov | 8b7719e | 2013-03-25 15:41:55 +0100 | [diff] [blame] | 121 | static const char * const edac_caps[] = { |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 122 | [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 Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 134 | #ifdef CONFIG_EDAC_LEGACY_SYSFS |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 135 | /* |
| 136 | * EDAC sysfs CSROW data structures and methods |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 137 | */ |
| 138 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 139 | #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 Hemminger | fbe2d36 | 2013-02-21 21:44:17 -0800 | [diff] [blame] | 146 | static struct device_attribute dev_attr_legacy_##_name = __ATTR(_name, _mode, _show, _store) |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 147 | |
| 148 | struct 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 159 | /* Set of more default csrow<id> attribute show/store functions */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 160 | static ssize_t csrow_ue_count_show(struct device *dev, |
| 161 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 162 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 163 | struct csrow_info *csrow = to_csrow(dev); |
| 164 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 165 | return sprintf(data, "%u\n", csrow->ue_count); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 168 | static ssize_t csrow_ce_count_show(struct device *dev, |
| 169 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 170 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 171 | struct csrow_info *csrow = to_csrow(dev); |
| 172 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 173 | return sprintf(data, "%u\n", csrow->ce_count); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 176 | static ssize_t csrow_size_show(struct device *dev, |
| 177 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 178 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 179 | struct csrow_info *csrow = to_csrow(dev); |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 180 | int i; |
| 181 | u32 nr_pages = 0; |
| 182 | |
| 183 | for (i = 0; i < csrow->nr_channels; i++) |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 184 | nr_pages += csrow->channels[i]->dimm->nr_pages; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 185 | return sprintf(data, "%u\n", PAGES_TO_MiB(nr_pages)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 188 | static ssize_t csrow_mem_type_show(struct device *dev, |
| 189 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 190 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 191 | struct csrow_info *csrow = to_csrow(dev); |
| 192 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 193 | return sprintf(data, "%s\n", mem_types[csrow->channels[0]->dimm->mtype]); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 196 | static ssize_t csrow_dev_type_show(struct device *dev, |
| 197 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 198 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 199 | struct csrow_info *csrow = to_csrow(dev); |
| 200 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 201 | return sprintf(data, "%s\n", dev_types[csrow->channels[0]->dimm->dtype]); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 204 | static ssize_t csrow_edac_mode_show(struct device *dev, |
| 205 | struct device_attribute *mattr, |
| 206 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 207 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 208 | struct csrow_info *csrow = to_csrow(dev); |
| 209 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 210 | return sprintf(data, "%s\n", edac_caps[csrow->channels[0]->dimm->edac_mode]); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* show/store functions for DIMM Label attributes */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 214 | static ssize_t channel_dimm_label_show(struct device *dev, |
| 215 | struct device_attribute *mattr, |
| 216 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 217 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 218 | struct csrow_info *csrow = to_csrow(dev); |
| 219 | unsigned chan = to_channel(mattr); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 220 | struct rank_info *rank = csrow->channels[chan]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 221 | |
Arthur Jones | 124682c | 2008-07-25 01:49:12 -0700 | [diff] [blame] | 222 | /* if field has not been initialized, there is nothing to send */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 223 | if (!rank->dimm->label[0]) |
Arthur Jones | 124682c | 2008-07-25 01:49:12 -0700 | [diff] [blame] | 224 | return 0; |
| 225 | |
| 226 | return snprintf(data, EDAC_MC_LABEL_LEN, "%s\n", |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 227 | rank->dimm->label); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 230 | static ssize_t channel_dimm_label_store(struct device *dev, |
| 231 | struct device_attribute *mattr, |
| 232 | const char *data, size_t count) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 233 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 234 | struct csrow_info *csrow = to_csrow(dev); |
| 235 | unsigned chan = to_channel(mattr); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 236 | struct rank_info *rank = csrow->channels[chan]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 237 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 238 | ssize_t max_size = 0; |
| 239 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 240 | max_size = min((ssize_t) count, (ssize_t) EDAC_MC_LABEL_LEN - 1); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 241 | strncpy(rank->dimm->label, data, max_size); |
| 242 | rank->dimm->label[max_size] = '\0'; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 243 | |
| 244 | return max_size; |
| 245 | } |
| 246 | |
| 247 | /* show function for dynamic chX_ce_count attribute */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 248 | static ssize_t channel_ce_count_show(struct device *dev, |
| 249 | struct device_attribute *mattr, char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 250 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 251 | struct csrow_info *csrow = to_csrow(dev); |
| 252 | unsigned chan = to_channel(mattr); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 253 | struct rank_info *rank = csrow->channels[chan]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 254 | |
| 255 | return sprintf(data, "%u\n", rank->ce_count); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 258 | /* cwrow<id>/attribute files */ |
| 259 | DEVICE_ATTR_LEGACY(size_mb, S_IRUGO, csrow_size_show, NULL); |
| 260 | DEVICE_ATTR_LEGACY(dev_type, S_IRUGO, csrow_dev_type_show, NULL); |
| 261 | DEVICE_ATTR_LEGACY(mem_type, S_IRUGO, csrow_mem_type_show, NULL); |
| 262 | DEVICE_ATTR_LEGACY(edac_mode, S_IRUGO, csrow_edac_mode_show, NULL); |
| 263 | DEVICE_ATTR_LEGACY(ue_count, S_IRUGO, csrow_ue_count_show, NULL); |
| 264 | DEVICE_ATTR_LEGACY(ce_count, S_IRUGO, csrow_ce_count_show, NULL); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 265 | |
| 266 | /* default attributes of the CSROW<id> object */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 267 | static 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 274 | NULL, |
| 275 | }; |
| 276 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 277 | static struct attribute_group csrow_attr_grp = { |
| 278 | .attrs = csrow_attrs, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 279 | }; |
| 280 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 281 | static const struct attribute_group *csrow_attr_groups[] = { |
| 282 | &csrow_attr_grp, |
| 283 | NULL |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 286 | static void csrow_attr_release(struct device *dev) |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 287 | { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 288 | struct csrow_info *csrow = container_of(dev, struct csrow_info, dev); |
| 289 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 290 | edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 291 | kfree(csrow); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 304 | #define EDAC_NR_CHANNELS 6 |
| 305 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 306 | DEVICE_CHANNEL(ch0_dimm_label, S_IRUGO | S_IWUSR, |
| 307 | channel_dimm_label_show, channel_dimm_label_store, 0); |
| 308 | DEVICE_CHANNEL(ch1_dimm_label, S_IRUGO | S_IWUSR, |
| 309 | channel_dimm_label_show, channel_dimm_label_store, 1); |
| 310 | DEVICE_CHANNEL(ch2_dimm_label, S_IRUGO | S_IWUSR, |
| 311 | channel_dimm_label_show, channel_dimm_label_store, 2); |
| 312 | DEVICE_CHANNEL(ch3_dimm_label, S_IRUGO | S_IWUSR, |
| 313 | channel_dimm_label_show, channel_dimm_label_store, 3); |
| 314 | DEVICE_CHANNEL(ch4_dimm_label, S_IRUGO | S_IWUSR, |
| 315 | channel_dimm_label_show, channel_dimm_label_store, 4); |
| 316 | DEVICE_CHANNEL(ch5_dimm_label, S_IRUGO | S_IWUSR, |
| 317 | channel_dimm_label_show, channel_dimm_label_store, 5); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 318 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 319 | /* Total possible dynamic DIMM Label attribute file table */ |
| 320 | static 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 329 | /* possible dynamic channel ce_count attribute files */ |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 330 | DEVICE_CHANNEL(ch0_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 331 | channel_ce_count_show, NULL, 0); |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 332 | DEVICE_CHANNEL(ch1_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 333 | channel_ce_count_show, NULL, 1); |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 334 | DEVICE_CHANNEL(ch2_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 335 | channel_ce_count_show, NULL, 2); |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 336 | DEVICE_CHANNEL(ch3_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 337 | channel_ce_count_show, NULL, 3); |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 338 | DEVICE_CHANNEL(ch4_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 339 | channel_ce_count_show, NULL, 4); |
Srivatsa S. Bhat | c8c64d1 | 2013-04-30 15:17:16 +0530 | [diff] [blame] | 340 | DEVICE_CHANNEL(ch5_ce_count, S_IRUGO, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 341 | channel_ce_count_show, NULL, 5); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 342 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 343 | /* Total possible dynamic ce_count attribute file table */ |
| 344 | static 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 351 | }; |
| 352 | |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 353 | static 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 Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 358 | nr_pages += csrow->channels[chan]->dimm->nr_pages; |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 359 | |
| 360 | return nr_pages; |
| 361 | } |
| 362 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 363 | /* Create a CSROW object under specifed edac_mc_device */ |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 364 | static int edac_create_csrow_object(struct mem_ctl_info *mci, |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 365 | struct csrow_info *csrow, int index) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 366 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 367 | int err, chan; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 368 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 369 | if (csrow->nr_channels >= EDAC_NR_CHANNELS) |
| 370 | return -ENODEV; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 371 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 372 | csrow->dev.type = &csrow_attr_type; |
| 373 | csrow->dev.bus = &mci->bus; |
| 374 | device_initialize(&csrow->dev); |
| 375 | csrow->dev.parent = &mci->dev; |
Borislav Petkov | 921a689 | 2012-09-13 18:46:39 +0200 | [diff] [blame] | 376 | csrow->mci = mci; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 377 | dev_set_name(&csrow->dev, "csrow%d", index); |
| 378 | dev_set_drvdata(&csrow->dev, csrow); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 379 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 380 | edac_dbg(0, "creating (virtual) csrow node %s\n", |
| 381 | dev_name(&csrow->dev)); |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 382 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 383 | err = device_add(&csrow->dev); |
| 384 | if (err < 0) |
| 385 | return err; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 386 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 387 | for (chan = 0; chan < csrow->nr_channels; chan++) { |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 388 | /* Only expose populated DIMMs */ |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 389 | if (!csrow->channels[chan]->dimm->nr_pages) |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 390 | continue; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 391 | 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 403 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 404 | return 0; |
| 405 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 406 | error: |
| 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 Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 414 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 415 | return err; |
| 416 | } |
| 417 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 418 | /* Create a CSROW object under specifed edac_mc_device */ |
| 419 | static int edac_create_csrow_objects(struct mem_ctl_info *mci) |
| 420 | { |
| 421 | int err, i, chan; |
| 422 | struct csrow_info *csrow; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 423 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 424 | for (i = 0; i < mci->nr_csrows; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 425 | csrow = mci->csrows[i]; |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 426 | if (!nr_pages_per_csrow(csrow)) |
| 427 | continue; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 428 | err = edac_create_csrow_object(mci, mci->csrows[i], i); |
Mauro Carvalho Chehab | 3d95882 | 2013-02-15 07:51:25 -0300 | [diff] [blame] | 429 | if (err < 0) { |
| 430 | edac_dbg(1, |
| 431 | "failure: create csrow objects for csrow %d\n", |
| 432 | i); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 433 | goto error; |
Mauro Carvalho Chehab | 3d95882 | 2013-02-15 07:51:25 -0300 | [diff] [blame] | 434 | } |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 435 | } |
| 436 | return 0; |
| 437 | |
| 438 | error: |
| 439 | for (--i; i >= 0; i--) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 440 | csrow = mci->csrows[i]; |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 441 | if (!nr_pages_per_csrow(csrow)) |
| 442 | continue; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 443 | for (chan = csrow->nr_channels - 1; chan >= 0; chan--) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 444 | if (!csrow->channels[chan]->dimm->nr_pages) |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 445 | continue; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 446 | 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 Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 451 | put_device(&mci->csrows[i]->dev); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | return err; |
| 455 | } |
| 456 | |
| 457 | static 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 Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 463 | csrow = mci->csrows[i]; |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 464 | if (!nr_pages_per_csrow(csrow)) |
| 465 | continue; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 466 | for (chan = csrow->nr_channels - 1; chan >= 0; chan--) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 467 | if (!csrow->channels[chan]->dimm->nr_pages) |
Mauro Carvalho Chehab | e39f4ea | 2012-03-29 12:20:22 -0300 | [diff] [blame] | 468 | continue; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 469 | edac_dbg(1, "Removing csrow %d channel %d sysfs nodes\n", |
| 470 | i, chan); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 471 | 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 Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 476 | device_unregister(&mci->csrows[i]->dev); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 477 | } |
| 478 | } |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 479 | #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 */ |
| 488 | static 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 Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 492 | |
Mauro Carvalho Chehab | 6e84d35 | 2012-04-30 10:24:43 -0300 | [diff] [blame] | 493 | return edac_dimm_info_location(dimm, data, PAGE_SIZE); |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | static 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 | |
| 508 | static 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 | |
| 524 | static 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 | |
| 532 | static 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 | |
| 540 | static 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 | |
| 548 | static 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 */ |
| 558 | static DEVICE_ATTR(dimm_label, S_IRUGO | S_IWUSR, |
| 559 | dimmdev_label_show, dimmdev_label_store); |
| 560 | static DEVICE_ATTR(dimm_location, S_IRUGO, dimmdev_location_show, NULL); |
| 561 | static DEVICE_ATTR(size, S_IRUGO, dimmdev_size_show, NULL); |
| 562 | static DEVICE_ATTR(dimm_mem_type, S_IRUGO, dimmdev_mem_type_show, NULL); |
| 563 | static DEVICE_ATTR(dimm_dev_type, S_IRUGO, dimmdev_dev_type_show, NULL); |
| 564 | static DEVICE_ATTR(dimm_edac_mode, S_IRUGO, dimmdev_edac_mode_show, NULL); |
| 565 | |
| 566 | /* attributes of the dimm<id>/rank<id> object */ |
| 567 | static 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 | |
| 577 | static struct attribute_group dimm_attr_grp = { |
| 578 | .attrs = dimm_attrs, |
| 579 | }; |
| 580 | |
| 581 | static const struct attribute_group *dimm_attr_groups[] = { |
| 582 | &dimm_attr_grp, |
| 583 | NULL |
| 584 | }; |
| 585 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 586 | static void dimm_attr_release(struct device *dev) |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 587 | { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 588 | struct dimm_info *dimm = container_of(dev, struct dimm_info, dev); |
| 589 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 590 | edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev)); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 591 | kfree(dimm); |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static 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 */ |
| 600 | static 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 Chehab | 9713fae | 2013-03-11 09:28:48 -0300 | [diff] [blame] | 612 | if (mci->csbased) |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 613 | 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 Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 621 | edac_dbg(0, "creating rank/dimm device %s\n", dev_name(&dimm->dev)); |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 622 | |
| 623 | return err; |
| 624 | } |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * Memory controller device |
| 628 | */ |
| 629 | |
| 630 | #define to_mci(k) container_of(k, struct mem_ctl_info, dev) |
| 631 | |
| 632 | static ssize_t mci_reset_counters_store(struct device *dev, |
| 633 | struct device_attribute *mattr, |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 634 | const char *data, size_t count) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 635 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 636 | struct mem_ctl_info *mci = to_mci(dev); |
| 637 | int cnt, row, chan, i; |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 638 | mci->ue_mc = 0; |
| 639 | mci->ce_mc = 0; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 640 | mci->ue_noinfo_count = 0; |
| 641 | mci->ce_noinfo_count = 0; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 642 | |
| 643 | for (row = 0; row < mci->nr_csrows; row++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 644 | struct csrow_info *ri = mci->csrows[row]; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 645 | |
| 646 | ri->ue_count = 0; |
| 647 | ri->ce_count = 0; |
| 648 | |
| 649 | for (chan = 0; chan < ri->nr_channels; chan++) |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 650 | ri->channels[chan]->ce_count = 0; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 653 | 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 660 | mci->start_time = jiffies; |
| 661 | return count; |
| 662 | } |
| 663 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 664 | /* 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 Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 673 | static ssize_t mci_sdram_scrub_rate_store(struct device *dev, |
| 674 | struct device_attribute *mattr, |
Borislav Petkov | eba042a | 2010-05-25 18:21:07 +0200 | [diff] [blame] | 675 | const char *data, size_t count) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 676 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 677 | struct mem_ctl_info *mci = to_mci(dev); |
Borislav Petkov | eba042a | 2010-05-25 18:21:07 +0200 | [diff] [blame] | 678 | unsigned long bandwidth = 0; |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 679 | int new_bw = 0; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 680 | |
Borislav Petkov | eba042a | 2010-05-25 18:21:07 +0200 | [diff] [blame] | 681 | if (strict_strtoul(data, 10, &bandwidth) < 0) |
| 682 | return -EINVAL; |
| 683 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 684 | new_bw = mci->set_sdram_scrub_rate(mci, bandwidth); |
Markus Trippelsdorf | 4949603 | 2011-04-20 14:28:45 -0400 | [diff] [blame] | 685 | if (new_bw < 0) { |
| 686 | edac_printk(KERN_WARNING, EDAC_MC, |
| 687 | "Error setting scrub rate to: %lu\n", bandwidth); |
| 688 | return -EINVAL; |
Borislav Petkov | eba042a | 2010-05-25 18:21:07 +0200 | [diff] [blame] | 689 | } |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 690 | |
Markus Trippelsdorf | 4949603 | 2011-04-20 14:28:45 -0400 | [diff] [blame] | 691 | return count; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 694 | /* |
| 695 | * ->get_sdram_scrub_rate() return value semantics same as above. |
| 696 | */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 697 | static ssize_t mci_sdram_scrub_rate_show(struct device *dev, |
| 698 | struct device_attribute *mattr, |
| 699 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 700 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 701 | struct mem_ctl_info *mci = to_mci(dev); |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 702 | int bandwidth = 0; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 703 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 704 | 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 708 | } |
Borislav Petkov | eba042a | 2010-05-25 18:21:07 +0200 | [diff] [blame] | 709 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 710 | return sprintf(data, "%d\n", bandwidth); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* default attribute files for the MCI object */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 714 | static ssize_t mci_ue_count_show(struct device *dev, |
| 715 | struct device_attribute *mattr, |
| 716 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 717 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 718 | struct mem_ctl_info *mci = to_mci(dev); |
| 719 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 720 | return sprintf(data, "%d\n", mci->ue_mc); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 723 | static ssize_t mci_ce_count_show(struct device *dev, |
| 724 | struct device_attribute *mattr, |
| 725 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 726 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 727 | struct mem_ctl_info *mci = to_mci(dev); |
| 728 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 729 | return sprintf(data, "%d\n", mci->ce_mc); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 732 | static ssize_t mci_ce_noinfo_show(struct device *dev, |
| 733 | struct device_attribute *mattr, |
| 734 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 735 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 736 | struct mem_ctl_info *mci = to_mci(dev); |
| 737 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 738 | return sprintf(data, "%d\n", mci->ce_noinfo_count); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 741 | static ssize_t mci_ue_noinfo_show(struct device *dev, |
| 742 | struct device_attribute *mattr, |
| 743 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 744 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 745 | struct mem_ctl_info *mci = to_mci(dev); |
| 746 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 747 | return sprintf(data, "%d\n", mci->ue_noinfo_count); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 750 | static ssize_t mci_seconds_show(struct device *dev, |
| 751 | struct device_attribute *mattr, |
| 752 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 753 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 754 | struct mem_ctl_info *mci = to_mci(dev); |
| 755 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 756 | return sprintf(data, "%ld\n", (jiffies - mci->start_time) / HZ); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 759 | static ssize_t mci_ctl_name_show(struct device *dev, |
| 760 | struct device_attribute *mattr, |
| 761 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 762 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 763 | struct mem_ctl_info *mci = to_mci(dev); |
| 764 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 765 | return sprintf(data, "%s\n", mci->ctl_name); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 768 | static ssize_t mci_size_mb_show(struct device *dev, |
| 769 | struct device_attribute *mattr, |
| 770 | char *data) |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 771 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 772 | struct mem_ctl_info *mci = to_mci(dev); |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 773 | int total_pages = 0, csrow_idx, j; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 774 | |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 775 | for (csrow_idx = 0; csrow_idx < mci->nr_csrows; csrow_idx++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 776 | struct csrow_info *csrow = mci->csrows[csrow_idx]; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 777 | |
Mauro Carvalho Chehab | 1eef128 | 2013-03-11 09:07:46 -0300 | [diff] [blame] | 778 | for (j = 0; j < csrow->nr_channels; j++) { |
| 779 | struct dimm_info *dimm = csrow->channels[j]->dimm; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 780 | |
Mauro Carvalho Chehab | 1eef128 | 2013-03-11 09:07:46 -0300 | [diff] [blame] | 781 | total_pages += dimm->nr_pages; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 782 | } |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 785 | return sprintf(data, "%u\n", PAGES_TO_MiB(total_pages)); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Mauro Carvalho Chehab | 8ad6c78 | 2012-03-21 17:13:24 -0300 | [diff] [blame] | 788 | static 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 Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 805 | #ifdef CONFIG_EDAC_DEBUG |
| 806 | static 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 Chehab | 38ced28 | 2012-06-12 10:55:57 -0300 | [diff] [blame] | 813 | u16 errcount = mci->fake_inject_count; |
| 814 | |
| 815 | if (!errcount) |
| 816 | errcount = 1; |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 817 | |
| 818 | type = mci->fake_inject_ue ? HW_EVENT_ERR_UNCORRECTED |
| 819 | : HW_EVENT_ERR_CORRECTED; |
| 820 | |
| 821 | printk(KERN_DEBUG |
Mauro Carvalho Chehab | 38ced28 | 2012-06-12 10:55:57 -0300 | [diff] [blame] | 822 | "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 Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 824 | (type == HW_EVENT_ERR_UNCORRECTED) ? "UE" : "CE", |
Mauro Carvalho Chehab | 38ced28 | 2012-06-12 10:55:57 -0300 | [diff] [blame] | 825 | errcount > 1 ? "s" : "", |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 826 | mci->fake_inject_layer[0], |
| 827 | mci->fake_inject_layer[1], |
| 828 | mci->fake_inject_layer[2] |
| 829 | ); |
Mauro Carvalho Chehab | 38ced28 | 2012-06-12 10:55:57 -0300 | [diff] [blame] | 830 | edac_mc_handle_error(type, mci, errcount, 0, 0, 0, |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 831 | mci->fake_inject_layer[0], |
| 832 | mci->fake_inject_layer[1], |
| 833 | mci->fake_inject_layer[2], |
Mauro Carvalho Chehab | 03f7eae | 2012-06-04 11:29:25 -0300 | [diff] [blame] | 834 | "FAKE ERROR", "for EDAC testing only"); |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 835 | |
| 836 | return count; |
| 837 | } |
| 838 | |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 839 | static const struct file_operations debug_fake_inject_fops = { |
Wei Yongjun | db7312a | 2012-10-17 16:32:01 +0800 | [diff] [blame] | 840 | .open = simple_open, |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 841 | .write = edac_fake_inject_write, |
| 842 | .llseek = generic_file_llseek, |
| 843 | }; |
| 844 | #endif |
| 845 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 846 | /* default Control file */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 847 | DEVICE_ATTR(reset_counters, S_IWUSR, NULL, mci_reset_counters_store); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 848 | |
| 849 | /* default Attribute files */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 850 | DEVICE_ATTR(mc_name, S_IRUGO, mci_ctl_name_show, NULL); |
| 851 | DEVICE_ATTR(size_mb, S_IRUGO, mci_size_mb_show, NULL); |
| 852 | DEVICE_ATTR(seconds_since_reset, S_IRUGO, mci_seconds_show, NULL); |
| 853 | DEVICE_ATTR(ue_noinfo_count, S_IRUGO, mci_ue_noinfo_show, NULL); |
| 854 | DEVICE_ATTR(ce_noinfo_count, S_IRUGO, mci_ce_noinfo_show, NULL); |
| 855 | DEVICE_ATTR(ue_count, S_IRUGO, mci_ue_count_show, NULL); |
| 856 | DEVICE_ATTR(ce_count, S_IRUGO, mci_ce_count_show, NULL); |
Mauro Carvalho Chehab | 8ad6c78 | 2012-03-21 17:13:24 -0300 | [diff] [blame] | 857 | DEVICE_ATTR(max_location, S_IRUGO, mci_max_location_show, NULL); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 858 | |
| 859 | /* memory scrubber attribute file */ |
Mauro Carvalho Chehab | e710047 | 2013-02-19 08:04:55 -0300 | [diff] [blame] | 860 | DEVICE_ATTR(sdram_scrub_rate, 0, NULL, NULL); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 861 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 862 | static 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 Chehab | 8ad6c78 | 2012-03-21 17:13:24 -0300 | [diff] [blame] | 871 | &dev_attr_max_location.attr, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 872 | NULL |
| 873 | }; |
| 874 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 875 | static struct attribute_group mci_attr_grp = { |
| 876 | .attrs = mci_attrs, |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 877 | }; |
| 878 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 879 | static const struct attribute_group *mci_attr_groups[] = { |
| 880 | &mci_attr_grp, |
| 881 | NULL |
Mauro Carvalho Chehab | cc301b3 | 2009-09-24 16:23:42 -0300 | [diff] [blame] | 882 | }; |
| 883 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 884 | static void mci_attr_release(struct device *dev) |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 885 | { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 886 | struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); |
| 887 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 888 | edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 889 | kfree(mci); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | static struct device_type mci_attr_type = { |
| 893 | .groups = mci_attr_groups, |
| 894 | .release = mci_attr_release, |
Mauro Carvalho Chehab | cc301b3 | 2009-09-24 16:23:42 -0300 | [diff] [blame] | 895 | }; |
| 896 | |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 897 | #ifdef CONFIG_EDAC_DEBUG |
Rob Herring | e7930ba | 2012-06-11 21:32:12 -0500 | [diff] [blame] | 898 | static struct dentry *edac_debugfs; |
| 899 | |
| 900 | int __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 | |
| 910 | void __exit edac_debugfs_exit(void) |
| 911 | { |
| 912 | debugfs_remove(edac_debugfs); |
| 913 | } |
| 914 | |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 915 | int edac_create_debug_nodes(struct mem_ctl_info *mci) |
| 916 | { |
| 917 | struct dentry *d, *parent; |
| 918 | char name[80]; |
| 919 | int i; |
| 920 | |
Rob Herring | e7930ba | 2012-06-11 21:32:12 -0500 | [diff] [blame] | 921 | if (!edac_debugfs) |
| 922 | return -ENODEV; |
| 923 | |
| 924 | d = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs); |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 925 | 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 Chehab | 38ced28 | 2012-06-12 10:55:57 -0300 | [diff] [blame] | 943 | 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 Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 948 | 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 Herring | e7930ba | 2012-06-11 21:32:12 -0500 | [diff] [blame] | 954 | mci->debugfs = parent; |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 955 | return 0; |
| 956 | nomem: |
| 957 | debugfs_remove(mci->debugfs); |
| 958 | return -ENOMEM; |
| 959 | } |
| 960 | #endif |
| 961 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 962 | /* |
| 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 | */ |
| 970 | int edac_create_sysfs_mci_device(struct mem_ctl_info *mci) |
| 971 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 972 | int i, err; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 973 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 974 | /* |
| 975 | * The memory controller needs its own bus, in order to avoid |
| 976 | * namespace conflicts at /sys/bus/edac. |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 977 | */ |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 978 | mci->bus.name = kasprintf(GFP_KERNEL, "mc%d", mci->mc_idx); |
| 979 | if (!mci->bus.name) |
| 980 | return -ENOMEM; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 981 | edac_dbg(0, "creating bus %s\n", mci->bus.name); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 982 | err = bus_register(&mci->bus); |
| 983 | if (err < 0) |
| 984 | return err; |
| 985 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 986 | /* 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 Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 996 | edac_dbg(0, "creating device %s\n", dev_name(&mci->dev)); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 997 | err = device_add(&mci->dev); |
| 998 | if (err < 0) { |
Mauro Carvalho Chehab | 3d95882 | 2013-02-15 07:51:25 -0300 | [diff] [blame] | 999 | edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev)); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1000 | bus_unregister(&mci->bus); |
| 1001 | kfree(mci->bus.name); |
| 1002 | return err; |
Douglas Thompson | 42a8e39 | 2007-07-19 01:50:10 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Mauro Carvalho Chehab | e710047 | 2013-02-19 08:04:55 -0300 | [diff] [blame] | 1005 | 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 Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1021 | /* |
| 1022 | * Create the dimm/rank devices |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1023 | */ |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1024 | for (i = 0; i < mci->tot_dimms; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1025 | struct dimm_info *dimm = mci->dimms[i]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1026 | /* Only expose populated DIMMs */ |
| 1027 | if (dimm->nr_pages == 0) |
| 1028 | continue; |
| 1029 | #ifdef CONFIG_EDAC_DEBUG |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1030 | edac_dbg(1, "creating dimm%d, located at ", i); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1031 | 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 Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1038 | } |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1039 | #endif |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1040 | err = edac_create_dimm_object(mci, dimm, i); |
| 1041 | if (err) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1042 | edac_dbg(1, "failure: create dimm %d obj\n", i); |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1043 | goto fail; |
| 1044 | } |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1047 | #ifdef CONFIG_EDAC_LEGACY_SYSFS |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1048 | err = edac_create_csrow_objects(mci); |
| 1049 | if (err < 0) |
| 1050 | goto fail; |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1051 | #endif |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1052 | |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 1053 | #ifdef CONFIG_EDAC_DEBUG |
| 1054 | edac_create_debug_nodes(mci); |
| 1055 | #endif |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1056 | return 0; |
| 1057 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1058 | fail: |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 1059 | for (i--; i >= 0; i--) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1060 | struct dimm_info *dimm = mci->dimms[i]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1061 | if (dimm->nr_pages == 0) |
| 1062 | continue; |
Lans Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 1063 | device_unregister(&dimm->dev); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1064 | } |
Mauro Carvalho Chehab | e710047 | 2013-02-19 08:04:55 -0300 | [diff] [blame] | 1065 | fail2: |
Lans Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 1066 | device_unregister(&mci->dev); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1067 | bus_unregister(&mci->bus); |
| 1068 | kfree(mci->bus.name); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1069 | return err; |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * remove a Memory Controller instance |
| 1074 | */ |
| 1075 | void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) |
| 1076 | { |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1077 | int i; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1078 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1079 | edac_dbg(0, "\n"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1080 | |
Mauro Carvalho Chehab | 452a6bf | 2012-03-26 09:35:11 -0300 | [diff] [blame] | 1081 | #ifdef CONFIG_EDAC_DEBUG |
| 1082 | debugfs_remove(mci->debugfs); |
| 1083 | #endif |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1084 | #ifdef CONFIG_EDAC_LEGACY_SYSFS |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1085 | edac_delete_csrow_objects(mci); |
Mauro Carvalho Chehab | 1997471 | 2012-03-21 17:06:53 -0300 | [diff] [blame] | 1086 | #endif |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 1087 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1088 | for (i = 0; i < mci->tot_dimms; i++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1089 | struct dimm_info *dimm = mci->dimms[i]; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1090 | if (dimm->nr_pages == 0) |
| 1091 | continue; |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1092 | edac_dbg(0, "removing device %s\n", dev_name(&dimm->dev)); |
Lans Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 1093 | device_unregister(&dimm->dev); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1094 | } |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 1095 | } |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1096 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1097 | void edac_unregister_sysfs(struct mem_ctl_info *mci) |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1098 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1099 | edac_dbg(1, "Unregistering device %s\n", dev_name(&mci->dev)); |
Lans Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 1100 | device_unregister(&mci->dev); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1101 | bus_unregister(&mci->bus); |
| 1102 | kfree(mci->bus.name); |
| 1103 | } |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1104 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1105 | static void mc_attr_release(struct device *dev) |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1106 | { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1107 | /* |
| 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 Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1112 | edac_dbg(1, "Releasing device %s\n", dev_name(dev)); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1113 | kfree(dev); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | static 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 | */ |
| 1122 | int __init edac_mc_sysfs_init(void) |
| 1123 | { |
| 1124 | struct bus_type *edac_subsys; |
| 1125 | int err; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1126 | |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 1127 | /* get the /sys/devices/system/edac subsys reference */ |
| 1128 | edac_subsys = edac_get_sysfs_subsys(); |
| 1129 | if (edac_subsys == NULL) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1130 | edac_dbg(1, "no edac_subsys\n"); |
Denis Kirjanov | 2d56b10 | 2012-10-25 19:42:58 +0400 | [diff] [blame] | 1131 | err = -EINVAL; |
| 1132 | goto out; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1135 | mci_pdev = kzalloc(sizeof(*mci_pdev), GFP_KERNEL); |
Denis Kirjanov | 2d56b10 | 2012-10-25 19:42:58 +0400 | [diff] [blame] | 1136 | if (!mci_pdev) { |
| 1137 | err = -ENOMEM; |
| 1138 | goto out_put_sysfs; |
| 1139 | } |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1140 | |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1141 | 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 Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1147 | if (err < 0) |
Denis Kirjanov | 2d56b10 | 2012-10-25 19:42:58 +0400 | [diff] [blame] | 1148 | goto out_dev_free; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1149 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1150 | edac_dbg(0, "device %s created\n", dev_name(mci_pdev)); |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 1151 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1152 | return 0; |
Denis Kirjanov | 2d56b10 | 2012-10-25 19:42:58 +0400 | [diff] [blame] | 1153 | |
| 1154 | out_dev_free: |
| 1155 | kfree(mci_pdev); |
| 1156 | out_put_sysfs: |
| 1157 | edac_put_sysfs_subsys(); |
| 1158 | out: |
| 1159 | return err; |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 1162 | void __exit edac_mc_sysfs_exit(void) |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1163 | { |
Lans Zhang | 44d22e2 | 2012-12-24 14:01:34 +0100 | [diff] [blame] | 1164 | device_unregister(mci_pdev); |
Kay Sievers | fe5ff8b | 2011-12-14 15:21:07 -0800 | [diff] [blame] | 1165 | edac_put_sysfs_subsys(); |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 1166 | } |