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