Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * edac_mc kernel module |
Doug Thompson | 49c0dab7 | 2006-07-10 04:45:19 -0700 | [diff] [blame] | 3 | * (C) 2005, 2006 Linux Networx (http://lnxi.com) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 4 | * This file may be distributed under the terms of the |
| 5 | * GNU General Public License. |
| 6 | * |
| 7 | * Written by Thayne Harbaugh |
| 8 | * Based on work by Dan Hollis <goemon at anime dot net> and others. |
| 9 | * http://www.anime.net/~goemon/linux-ecc/ |
| 10 | * |
| 11 | * Modified by Dave Peterson and Doug Thompson |
| 12 | * |
| 13 | */ |
| 14 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/proc_fs.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/smp.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/sysctl.h> |
| 22 | #include <linux/highmem.h> |
| 23 | #include <linux/timer.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/jiffies.h> |
| 26 | #include <linux/spinlock.h> |
| 27 | #include <linux/list.h> |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 28 | #include <linux/ctype.h> |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 29 | #include <linux/edac.h> |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 30 | #include <linux/bitops.h> |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | #include <asm/page.h> |
| 33 | #include <asm/edac.h> |
Douglas Thompson | 20bcb7a | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 34 | #include "edac_core.h" |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 35 | #include "edac_module.h" |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 36 | |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 37 | #define CREATE_TRACE_POINTS |
| 38 | #define TRACE_INCLUDE_PATH ../../include/ras |
| 39 | #include <ras/ras_event.h> |
| 40 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 41 | /* lock to memory controller's control array */ |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 42 | static DEFINE_MUTEX(mem_ctls_mutex); |
Robert P. J. Day | ff6ac2a | 2008-04-29 01:03:17 -0700 | [diff] [blame] | 43 | static LIST_HEAD(mc_devices); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 44 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 45 | #ifdef CONFIG_EDAC_DEBUG |
| 46 | |
Mauro Carvalho Chehab | a4b4be3 | 2012-01-27 10:26:13 -0300 | [diff] [blame] | 47 | static void edac_mc_dump_channel(struct rank_info *chan) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 48 | { |
| 49 | debugf4("\tchannel = %p\n", chan); |
| 50 | debugf4("\tchannel->chan_idx = %d\n", chan->chan_idx); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 51 | debugf4("\tchannel->csrow = %p\n\n", chan->csrow); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 52 | debugf4("\tchannel->dimm = %p\n", chan->dimm); |
| 53 | } |
| 54 | |
| 55 | static void edac_mc_dump_dimm(struct dimm_info *dimm) |
| 56 | { |
| 57 | int i; |
| 58 | |
| 59 | debugf4("\tdimm = %p\n", dimm); |
| 60 | debugf4("\tdimm->label = '%s'\n", dimm->label); |
| 61 | debugf4("\tdimm->nr_pages = 0x%x\n", dimm->nr_pages); |
| 62 | debugf4("\tdimm location "); |
| 63 | for (i = 0; i < dimm->mci->n_layers; i++) { |
| 64 | printk(KERN_CONT "%d", dimm->location[i]); |
| 65 | if (i < dimm->mci->n_layers - 1) |
| 66 | printk(KERN_CONT "."); |
| 67 | } |
| 68 | printk(KERN_CONT "\n"); |
| 69 | debugf4("\tdimm->grain = %d\n", dimm->grain); |
| 70 | debugf4("\tdimm->nr_pages = 0x%x\n", dimm->nr_pages); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 73 | static void edac_mc_dump_csrow(struct csrow_info *csrow) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 74 | { |
| 75 | debugf4("\tcsrow = %p\n", csrow); |
| 76 | debugf4("\tcsrow->csrow_idx = %d\n", csrow->csrow_idx); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 77 | debugf4("\tcsrow->first_page = 0x%lx\n", csrow->first_page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 78 | debugf4("\tcsrow->last_page = 0x%lx\n", csrow->last_page); |
| 79 | debugf4("\tcsrow->page_mask = 0x%lx\n", csrow->page_mask); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 80 | debugf4("\tcsrow->nr_channels = %d\n", csrow->nr_channels); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 81 | debugf4("\tcsrow->channels = %p\n", csrow->channels); |
| 82 | debugf4("\tcsrow->mci = %p\n\n", csrow->mci); |
| 83 | } |
| 84 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 85 | static void edac_mc_dump_mci(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 86 | { |
| 87 | debugf3("\tmci = %p\n", mci); |
| 88 | debugf3("\tmci->mtype_cap = %lx\n", mci->mtype_cap); |
| 89 | debugf3("\tmci->edac_ctl_cap = %lx\n", mci->edac_ctl_cap); |
| 90 | debugf3("\tmci->edac_cap = %lx\n", mci->edac_cap); |
| 91 | debugf4("\tmci->edac_check = %p\n", mci->edac_check); |
| 92 | debugf3("\tmci->nr_csrows = %d, csrows = %p\n", |
| 93 | mci->nr_csrows, mci->csrows); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 94 | debugf3("\tmci->nr_dimms = %d, dimms = %p\n", |
| 95 | mci->tot_dimms, mci->dimms); |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 96 | debugf3("\tdev = %p\n", mci->pdev); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 97 | debugf3("\tmod_name:ctl_name = %s:%s\n", mci->mod_name, mci->ctl_name); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 98 | debugf3("\tpvt_info = %p\n\n", mci->pvt_info); |
| 99 | } |
| 100 | |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 101 | #endif /* CONFIG_EDAC_DEBUG */ |
| 102 | |
Borislav Petkov | 239642f | 2009-11-12 15:33:16 +0100 | [diff] [blame] | 103 | /* |
| 104 | * keep those in sync with the enum mem_type |
| 105 | */ |
| 106 | const char *edac_mem_types[] = { |
| 107 | "Empty csrow", |
| 108 | "Reserved csrow type", |
| 109 | "Unknown csrow type", |
| 110 | "Fast page mode RAM", |
| 111 | "Extended data out RAM", |
| 112 | "Burst Extended data out RAM", |
| 113 | "Single data rate SDRAM", |
| 114 | "Registered single data rate SDRAM", |
| 115 | "Double data rate SDRAM", |
| 116 | "Registered Double data rate SDRAM", |
| 117 | "Rambus DRAM", |
| 118 | "Unbuffered DDR2 RAM", |
| 119 | "Fully buffered DDR2", |
| 120 | "Registered DDR2 RAM", |
| 121 | "Rambus XDR", |
| 122 | "Unbuffered DDR3 RAM", |
| 123 | "Registered DDR3 RAM", |
| 124 | }; |
| 125 | EXPORT_SYMBOL_GPL(edac_mem_types); |
| 126 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 127 | /** |
| 128 | * edac_align_ptr - Prepares the pointer offsets for a single-shot allocation |
| 129 | * @p: pointer to a pointer with the memory offset to be used. At |
| 130 | * return, this will be incremented to point to the next offset |
| 131 | * @size: Size of the data structure to be reserved |
| 132 | * @n_elems: Number of elements that should be reserved |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 133 | * |
| 134 | * If 'size' is a constant, the compiler will optimize this whole function |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 135 | * down to either a no-op or the addition of a constant to the value of '*p'. |
| 136 | * |
| 137 | * The 'p' pointer is absolutely needed to keep the proper advancing |
| 138 | * further in memory to the proper offsets when allocating the struct along |
| 139 | * with its embedded structs, as edac_device_alloc_ctl_info() does it |
| 140 | * above, for example. |
| 141 | * |
| 142 | * At return, the pointer 'p' will be incremented to be used on a next call |
| 143 | * to this function. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 144 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 145 | void *edac_align_ptr(void **p, unsigned size, int n_elems) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 146 | { |
| 147 | unsigned align, r; |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 148 | void *ptr = *p; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 149 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 150 | *p += size * n_elems; |
| 151 | |
| 152 | /* |
| 153 | * 'p' can possibly be an unaligned item X such that sizeof(X) is |
| 154 | * 'size'. Adjust 'p' so that its alignment is at least as |
| 155 | * stringent as what the compiler would provide for X and return |
| 156 | * the aligned result. |
| 157 | * Here we assume that the alignment of a "long long" is the most |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 158 | * stringent alignment that the compiler will ever provide by default. |
| 159 | * As far as I know, this is a reasonable assumption. |
| 160 | */ |
| 161 | if (size > sizeof(long)) |
| 162 | align = sizeof(long long); |
| 163 | else if (size > sizeof(int)) |
| 164 | align = sizeof(long); |
| 165 | else if (size > sizeof(short)) |
| 166 | align = sizeof(int); |
| 167 | else if (size > sizeof(char)) |
| 168 | align = sizeof(short); |
| 169 | else |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 170 | return (char *)ptr; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 171 | |
| 172 | r = size % align; |
| 173 | |
| 174 | if (r == 0) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 175 | return (char *)ptr; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 176 | |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 177 | *p += align - r; |
| 178 | |
Douglas Thompson | 7391c6d | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 179 | return (void *)(((unsigned long)ptr) + align - r); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 182 | /** |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 183 | * edac_mc_alloc: Allocate and partially fill a struct mem_ctl_info structure |
| 184 | * @mc_num: Memory controller number |
| 185 | * @n_layers: Number of MC hierarchy layers |
| 186 | * layers: Describes each layer as seen by the Memory Controller |
| 187 | * @size_pvt: size of private storage needed |
| 188 | * |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 189 | * |
| 190 | * Everything is kmalloc'ed as one big chunk - more efficient. |
| 191 | * Only can be used if all structures have the same lifetime - otherwise |
| 192 | * you have to allocate and initialize your own structures. |
| 193 | * |
| 194 | * Use edac_mc_free() to free mc structures allocated by this function. |
| 195 | * |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 196 | * NOTE: drivers handle multi-rank memories in different ways: in some |
| 197 | * drivers, one multi-rank memory stick is mapped as one entry, while, in |
| 198 | * others, a single multi-rank memory stick would be mapped into several |
| 199 | * entries. Currently, this function will allocate multiple struct dimm_info |
| 200 | * on such scenarios, as grouping the multiple ranks require drivers change. |
| 201 | * |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 202 | * Returns: |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 203 | * On failure: NULL |
| 204 | * On success: struct mem_ctl_info pointer |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 205 | */ |
Mauro Carvalho Chehab | ca0907b | 2012-05-02 14:37:00 -0300 | [diff] [blame] | 206 | struct mem_ctl_info *edac_mc_alloc(unsigned mc_num, |
| 207 | unsigned n_layers, |
| 208 | struct edac_mc_layer *layers, |
| 209 | unsigned sz_pvt) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 210 | { |
| 211 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 212 | struct edac_mc_layer *layer; |
| 213 | struct csrow_info *csi, *csr; |
Mauro Carvalho Chehab | a4b4be3 | 2012-01-27 10:26:13 -0300 | [diff] [blame] | 214 | struct rank_info *chi, *chp, *chan; |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 215 | struct dimm_info *dimm; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 216 | u32 *ce_per_layer[EDAC_MAX_LAYERS], *ue_per_layer[EDAC_MAX_LAYERS]; |
| 217 | unsigned pos[EDAC_MAX_LAYERS]; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 218 | unsigned size, tot_dimms = 1, count = 1; |
| 219 | unsigned tot_csrows = 1, tot_channels = 1, tot_errcount = 0; |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 220 | void *pvt, *p, *ptr = NULL; |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame^] | 221 | int i, j, row, chn, n, len; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 222 | bool per_rank = false; |
| 223 | |
| 224 | BUG_ON(n_layers > EDAC_MAX_LAYERS || n_layers == 0); |
| 225 | /* |
| 226 | * Calculate the total amount of dimms and csrows/cschannels while |
| 227 | * in the old API emulation mode |
| 228 | */ |
| 229 | for (i = 0; i < n_layers; i++) { |
| 230 | tot_dimms *= layers[i].size; |
| 231 | if (layers[i].is_virt_csrow) |
| 232 | tot_csrows *= layers[i].size; |
| 233 | else |
| 234 | tot_channels *= layers[i].size; |
| 235 | |
| 236 | if (layers[i].type == EDAC_MC_LAYER_CHIP_SELECT) |
| 237 | per_rank = true; |
| 238 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 239 | |
| 240 | /* Figure out the offsets of the various items from the start of an mc |
| 241 | * structure. We want the alignment of each item to be at least as |
| 242 | * stringent as what the compiler would provide if we could simply |
| 243 | * hardcode everything into a single struct. |
| 244 | */ |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 245 | mci = edac_align_ptr(&ptr, sizeof(*mci), 1); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 246 | layer = edac_align_ptr(&ptr, sizeof(*layer), n_layers); |
| 247 | csi = edac_align_ptr(&ptr, sizeof(*csi), tot_csrows); |
| 248 | chi = edac_align_ptr(&ptr, sizeof(*chi), tot_csrows * tot_channels); |
| 249 | dimm = edac_align_ptr(&ptr, sizeof(*dimm), tot_dimms); |
| 250 | for (i = 0; i < n_layers; i++) { |
| 251 | count *= layers[i].size; |
| 252 | debugf4("%s: errcount layer %d size %d\n", __func__, i, count); |
| 253 | ce_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count); |
| 254 | ue_per_layer[i] = edac_align_ptr(&ptr, sizeof(u32), count); |
| 255 | tot_errcount += 2 * count; |
| 256 | } |
| 257 | |
| 258 | debugf4("%s: allocating %d error counters\n", __func__, tot_errcount); |
Mauro Carvalho Chehab | 93e4fe6 | 2012-04-16 10:18:12 -0300 | [diff] [blame] | 259 | pvt = edac_align_ptr(&ptr, sz_pvt, 1); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 260 | size = ((unsigned long)pvt) + sz_pvt; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 261 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 262 | debugf1("%s(): allocating %u bytes for mci data (%d %s, %d csrows/channels)\n", |
| 263 | __func__, size, |
| 264 | tot_dimms, |
| 265 | per_rank ? "ranks" : "dimms", |
| 266 | tot_csrows * tot_channels); |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 267 | mci = kzalloc(size, GFP_KERNEL); |
| 268 | if (mci == NULL) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 269 | return NULL; |
| 270 | |
| 271 | /* Adjust pointers so they point within the memory we just allocated |
| 272 | * rather than an imaginary chunk of memory located at address 0. |
| 273 | */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 274 | layer = (struct edac_mc_layer *)(((char *)mci) + ((unsigned long)layer)); |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 275 | csi = (struct csrow_info *)(((char *)mci) + ((unsigned long)csi)); |
Mauro Carvalho Chehab | a4b4be3 | 2012-01-27 10:26:13 -0300 | [diff] [blame] | 276 | chi = (struct rank_info *)(((char *)mci) + ((unsigned long)chi)); |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 277 | dimm = (struct dimm_info *)(((char *)mci) + ((unsigned long)dimm)); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 278 | for (i = 0; i < n_layers; i++) { |
| 279 | mci->ce_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ce_per_layer[i])); |
| 280 | mci->ue_per_layer[i] = (u32 *)((char *)mci + ((unsigned long)ue_per_layer[i])); |
| 281 | } |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 282 | pvt = sz_pvt ? (((char *)mci) + ((unsigned long)pvt)) : NULL; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 283 | |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 284 | /* setup index and various internal pointers */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 285 | mci->mc_idx = mc_num; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 286 | mci->csrows = csi; |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 287 | mci->dimms = dimm; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 288 | mci->tot_dimms = tot_dimms; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 289 | mci->pvt_info = pvt; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 290 | mci->n_layers = n_layers; |
| 291 | mci->layers = layer; |
| 292 | memcpy(mci->layers, layers, sizeof(*layer) * n_layers); |
| 293 | mci->nr_csrows = tot_csrows; |
| 294 | mci->num_cschannel = tot_channels; |
| 295 | mci->mem_is_per_rank = per_rank; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 296 | |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 297 | /* |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 298 | * Fill the csrow struct |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 299 | */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 300 | for (row = 0; row < tot_csrows; row++) { |
| 301 | csr = &csi[row]; |
| 302 | csr->csrow_idx = row; |
| 303 | csr->mci = mci; |
| 304 | csr->nr_channels = tot_channels; |
| 305 | chp = &chi[row * tot_channels]; |
| 306 | csr->channels = chp; |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 307 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 308 | for (chn = 0; chn < tot_channels; chn++) { |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 309 | chan = &chp[chn]; |
| 310 | chan->chan_idx = chn; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 311 | chan->csrow = csr; |
| 312 | } |
| 313 | } |
Mauro Carvalho Chehab | a7d7d2e | 2012-01-27 14:12:32 -0300 | [diff] [blame] | 314 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 315 | /* |
| 316 | * Fill the dimm struct |
| 317 | */ |
| 318 | memset(&pos, 0, sizeof(pos)); |
| 319 | row = 0; |
| 320 | chn = 0; |
| 321 | debugf4("%s: initializing %d %s\n", __func__, tot_dimms, |
| 322 | per_rank ? "ranks" : "dimms"); |
| 323 | for (i = 0; i < tot_dimms; i++) { |
| 324 | chan = &csi[row].channels[chn]; |
| 325 | dimm = EDAC_DIMM_PTR(layer, mci->dimms, n_layers, |
| 326 | pos[0], pos[1], pos[2]); |
| 327 | dimm->mci = mci; |
| 328 | |
| 329 | debugf2("%s: %d: %s%zd (%d:%d:%d): row %d, chan %d\n", __func__, |
| 330 | i, per_rank ? "rank" : "dimm", (dimm - mci->dimms), |
| 331 | pos[0], pos[1], pos[2], row, chn); |
| 332 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 333 | /* |
| 334 | * Copy DIMM location and initialize it. |
| 335 | */ |
| 336 | len = sizeof(dimm->label); |
| 337 | p = dimm->label; |
| 338 | n = snprintf(p, len, "mc#%u", mc_num); |
| 339 | p += n; |
| 340 | len -= n; |
| 341 | for (j = 0; j < n_layers; j++) { |
| 342 | n = snprintf(p, len, "%s#%u", |
| 343 | edac_layer_name[layers[j].type], |
| 344 | pos[j]); |
| 345 | p += n; |
| 346 | len -= n; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 347 | dimm->location[j] = pos[j]; |
| 348 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 349 | if (len <= 0) |
| 350 | break; |
| 351 | } |
| 352 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 353 | /* Link it to the csrows old API data */ |
| 354 | chan->dimm = dimm; |
| 355 | dimm->csrow = row; |
| 356 | dimm->cschannel = chn; |
| 357 | |
| 358 | /* Increment csrow location */ |
| 359 | row++; |
| 360 | if (row == tot_csrows) { |
| 361 | row = 0; |
| 362 | chn++; |
| 363 | } |
| 364 | |
| 365 | /* Increment dimm location */ |
| 366 | for (j = n_layers - 1; j >= 0; j--) { |
| 367 | pos[j]++; |
| 368 | if (pos[j] < layers[j].size) |
| 369 | break; |
| 370 | pos[j] = 0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 374 | mci->op_state = OP_ALLOC; |
Mauro Carvalho Chehab | 6fe1108 | 2010-08-12 00:30:25 -0300 | [diff] [blame] | 375 | INIT_LIST_HEAD(&mci->grp_kobj_list); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 376 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 377 | /* at this point, the root kobj is valid, and in order to |
| 378 | * 'free' the object, then the function: |
| 379 | * edac_mc_unregister_sysfs_main_kobj() must be called |
| 380 | * which will perform kobj unregistration and the actual free |
| 381 | * will occur during the kobject callback operation |
| 382 | */ |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 383 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 384 | return mci; |
| 385 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 386 | EXPORT_SYMBOL_GPL(edac_mc_alloc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 387 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 388 | /** |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 389 | * edac_mc_free |
| 390 | * 'Free' a previously allocated 'mci' structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 391 | * @mci: pointer to a struct mem_ctl_info structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 392 | */ |
| 393 | void edac_mc_free(struct mem_ctl_info *mci) |
| 394 | { |
Mauro Carvalho Chehab | bbc560a | 2010-08-16 18:22:43 -0300 | [diff] [blame] | 395 | debugf1("%s()\n", __func__); |
| 396 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame^] | 397 | edac_unregister_sysfs(mci); |
Mauro Carvalho Chehab | accf74f | 2010-08-16 18:34:37 -0300 | [diff] [blame] | 398 | |
| 399 | /* free the mci instance memory here */ |
| 400 | kfree(mci); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 401 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 402 | EXPORT_SYMBOL_GPL(edac_mc_free); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 403 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 404 | |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 405 | /** |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 406 | * find_mci_by_dev |
| 407 | * |
| 408 | * scan list of controllers looking for the one that manages |
| 409 | * the 'dev' device |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 410 | * @dev: pointer to a struct device related with the MCI |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 411 | */ |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 412 | struct mem_ctl_info *find_mci_by_dev(struct device *dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 413 | { |
| 414 | struct mem_ctl_info *mci; |
| 415 | struct list_head *item; |
| 416 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 417 | debugf3("%s()\n", __func__); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 418 | |
| 419 | list_for_each(item, &mc_devices) { |
| 420 | mci = list_entry(item, struct mem_ctl_info, link); |
| 421 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 422 | if (mci->pdev == dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 423 | return mci; |
| 424 | } |
| 425 | |
| 426 | return NULL; |
| 427 | } |
Mauro Carvalho Chehab | 939747bd | 2010-08-10 11:22:01 -0300 | [diff] [blame] | 428 | EXPORT_SYMBOL_GPL(find_mci_by_dev); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 429 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 430 | /* |
| 431 | * handler for EDAC to check if NMI type handler has asserted interrupt |
| 432 | */ |
| 433 | static int edac_mc_assert_error_check_and_clear(void) |
| 434 | { |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 435 | int old_state; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 436 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 437 | if (edac_op_state == EDAC_OPSTATE_POLL) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 438 | return 1; |
| 439 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 440 | old_state = edac_err_assert; |
| 441 | edac_err_assert = 0; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 442 | |
Dave Jiang | 66ee2f9 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 443 | return old_state; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /* |
| 447 | * edac_mc_workq_function |
| 448 | * performs the operation scheduled by a workq request |
| 449 | */ |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 450 | static void edac_mc_workq_function(struct work_struct *work_req) |
| 451 | { |
Jean Delvare | fbeb438 | 2009-04-13 14:40:21 -0700 | [diff] [blame] | 452 | struct delayed_work *d_work = to_delayed_work(work_req); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 453 | struct mem_ctl_info *mci = to_edac_mem_ctl_work(d_work); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 454 | |
| 455 | mutex_lock(&mem_ctls_mutex); |
| 456 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 457 | /* if this control struct has movd to offline state, we are done */ |
| 458 | if (mci->op_state == OP_OFFLINE) { |
| 459 | mutex_unlock(&mem_ctls_mutex); |
| 460 | return; |
| 461 | } |
| 462 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 463 | /* Only poll controllers that are running polled and have a check */ |
| 464 | if (edac_mc_assert_error_check_and_clear() && (mci->edac_check != NULL)) |
| 465 | mci->edac_check(mci); |
| 466 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 467 | mutex_unlock(&mem_ctls_mutex); |
| 468 | |
| 469 | /* Reschedule */ |
Dave Jiang | 4de78c6 | 2007-07-19 01:49:54 -0700 | [diff] [blame] | 470 | queue_delayed_work(edac_workqueue, &mci->work, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 471 | msecs_to_jiffies(edac_mc_get_poll_msec())); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /* |
| 475 | * edac_mc_workq_setup |
| 476 | * initialize a workq item for this mci |
| 477 | * passing in the new delay period in msec |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 478 | * |
| 479 | * locking model: |
| 480 | * |
| 481 | * called with the mem_ctls_mutex held |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 482 | */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 483 | static void edac_mc_workq_setup(struct mem_ctl_info *mci, unsigned msec) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 484 | { |
| 485 | debugf0("%s()\n", __func__); |
| 486 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 487 | /* if this instance is not in the POLL state, then simply return */ |
| 488 | if (mci->op_state != OP_RUNNING_POLL) |
| 489 | return; |
| 490 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 491 | INIT_DELAYED_WORK(&mci->work, edac_mc_workq_function); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 492 | queue_delayed_work(edac_workqueue, &mci->work, msecs_to_jiffies(msec)); |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * edac_mc_workq_teardown |
| 497 | * stop the workq processing on this mci |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 498 | * |
| 499 | * locking model: |
| 500 | * |
| 501 | * called WITHOUT lock held |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 502 | */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 503 | static void edac_mc_workq_teardown(struct mem_ctl_info *mci) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 504 | { |
| 505 | int status; |
| 506 | |
Borislav Petkov | 00740c5 | 2010-09-26 12:42:23 +0200 | [diff] [blame] | 507 | if (mci->op_state != OP_RUNNING_POLL) |
| 508 | return; |
| 509 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 510 | status = cancel_delayed_work(&mci->work); |
| 511 | if (status == 0) { |
| 512 | debugf0("%s() not canceled, flush the queue\n", |
| 513 | __func__); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 514 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 515 | /* workq instance might be running, wait for it */ |
| 516 | flush_workqueue(edac_workqueue); |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
| 520 | /* |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 521 | * edac_mc_reset_delay_period(unsigned long value) |
| 522 | * |
| 523 | * user space has updated our poll period value, need to |
| 524 | * reset our workq delays |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 525 | */ |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 526 | void edac_mc_reset_delay_period(int value) |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 527 | { |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 528 | struct mem_ctl_info *mci; |
| 529 | struct list_head *item; |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 530 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 531 | mutex_lock(&mem_ctls_mutex); |
| 532 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 533 | /* scan the list and turn off all workq timers, doing so under lock |
| 534 | */ |
| 535 | list_for_each(item, &mc_devices) { |
| 536 | mci = list_entry(item, struct mem_ctl_info, link); |
| 537 | |
| 538 | if (mci->op_state == OP_RUNNING_POLL) |
| 539 | cancel_delayed_work(&mci->work); |
| 540 | } |
| 541 | |
| 542 | mutex_unlock(&mem_ctls_mutex); |
| 543 | |
| 544 | |
| 545 | /* re-walk the list, and reset the poll delay */ |
| 546 | mutex_lock(&mem_ctls_mutex); |
| 547 | |
| 548 | list_for_each(item, &mc_devices) { |
| 549 | mci = list_entry(item, struct mem_ctl_info, link); |
| 550 | |
| 551 | edac_mc_workq_setup(mci, (unsigned long) value); |
| 552 | } |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 553 | |
| 554 | mutex_unlock(&mem_ctls_mutex); |
| 555 | } |
| 556 | |
Doug Thompson | bce1968 | 2007-07-26 10:41:14 -0700 | [diff] [blame] | 557 | |
| 558 | |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 559 | /* Return 0 on success, 1 on failure. |
| 560 | * Before calling this function, caller must |
| 561 | * assign a unique value to mci->mc_idx. |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 562 | * |
| 563 | * locking model: |
| 564 | * |
| 565 | * called with the mem_ctls_mutex lock held |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 566 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 567 | static int add_mc_to_global_list(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 568 | { |
| 569 | struct list_head *item, *insert_before; |
| 570 | struct mem_ctl_info *p; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 571 | |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 572 | insert_before = &mc_devices; |
| 573 | |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 574 | p = find_mci_by_dev(mci->pdev); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 575 | if (unlikely(p != NULL)) |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 576 | goto fail0; |
| 577 | |
| 578 | list_for_each(item, &mc_devices) { |
| 579 | p = list_entry(item, struct mem_ctl_info, link); |
| 580 | |
| 581 | if (p->mc_idx >= mci->mc_idx) { |
| 582 | if (unlikely(p->mc_idx == mci->mc_idx)) |
| 583 | goto fail1; |
| 584 | |
| 585 | insert_before = item; |
| 586 | break; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 587 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | list_add_tail_rcu(&mci->link, insert_before); |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 591 | atomic_inc(&edac_handlers); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 592 | return 0; |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 593 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 594 | fail0: |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 595 | edac_printk(KERN_WARNING, EDAC_MC, |
Mauro Carvalho Chehab | fd68750 | 2012-03-16 07:44:18 -0300 | [diff] [blame] | 596 | "%s (%s) %s %s already assigned %d\n", dev_name(p->pdev), |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 597 | edac_dev_name(mci), p->mod_name, p->ctl_name, p->mc_idx); |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 598 | return 1; |
| 599 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 600 | fail1: |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 601 | edac_printk(KERN_WARNING, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 602 | "bug in low-level driver: attempt to assign\n" |
| 603 | " duplicate mc_idx %d in %s()\n", p->mc_idx, __func__); |
Doug Thompson | 2d7bbb9 | 2006-06-30 01:56:08 -0700 | [diff] [blame] | 604 | return 1; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 607 | static void del_mc_from_global_list(struct mem_ctl_info *mci) |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 608 | { |
Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 609 | atomic_dec(&edac_handlers); |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 610 | list_del_rcu(&mci->link); |
Lai Jiangshan | e2e7709 | 2011-05-26 16:25:58 -0700 | [diff] [blame] | 611 | |
| 612 | /* these are for safe removal of devices from global list while |
| 613 | * NMI handlers may be traversing list |
| 614 | */ |
| 615 | synchronize_rcu(); |
| 616 | INIT_LIST_HEAD(&mci->link); |
Dave Peterson | a1d03fc | 2006-03-26 01:38:46 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 619 | /** |
Douglas Thompson | 5da0831 | 2007-07-19 01:49:31 -0700 | [diff] [blame] | 620 | * edac_mc_find: Search for a mem_ctl_info structure whose index is 'idx'. |
| 621 | * |
| 622 | * If found, return a pointer to the structure. |
| 623 | * Else return NULL. |
| 624 | * |
| 625 | * Caller must hold mem_ctls_mutex. |
| 626 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 627 | struct mem_ctl_info *edac_mc_find(int idx) |
Douglas Thompson | 5da0831 | 2007-07-19 01:49:31 -0700 | [diff] [blame] | 628 | { |
| 629 | struct list_head *item; |
| 630 | struct mem_ctl_info *mci; |
| 631 | |
| 632 | list_for_each(item, &mc_devices) { |
| 633 | mci = list_entry(item, struct mem_ctl_info, link); |
| 634 | |
| 635 | if (mci->mc_idx >= idx) { |
| 636 | if (mci->mc_idx == idx) |
| 637 | return mci; |
| 638 | |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | return NULL; |
| 644 | } |
| 645 | EXPORT_SYMBOL(edac_mc_find); |
| 646 | |
| 647 | /** |
Dave Peterson | 472678e | 2006-03-26 01:38:49 -0800 | [diff] [blame] | 648 | * edac_mc_add_mc: Insert the 'mci' structure into the mci global list and |
| 649 | * create sysfs entries associated with mci structure |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 650 | * @mci: pointer to the mci structure to be added to the list |
| 651 | * |
| 652 | * Return: |
| 653 | * 0 Success |
| 654 | * !0 Failure |
| 655 | */ |
| 656 | |
| 657 | /* FIXME - should a warning be printed if no error detection? correction? */ |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 658 | int edac_mc_add_mc(struct mem_ctl_info *mci) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 659 | { |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 660 | debugf0("%s()\n", __func__); |
Doug Thompson | b8f6f97 | 2007-07-19 01:50:26 -0700 | [diff] [blame] | 661 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 662 | #ifdef CONFIG_EDAC_DEBUG |
| 663 | if (edac_debug_level >= 3) |
| 664 | edac_mc_dump_mci(mci); |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 665 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 666 | if (edac_debug_level >= 4) { |
| 667 | int i; |
| 668 | |
| 669 | for (i = 0; i < mci->nr_csrows; i++) { |
| 670 | int j; |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 671 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 672 | edac_mc_dump_csrow(&mci->csrows[i]); |
| 673 | for (j = 0; j < mci->csrows[i].nr_channels; j++) |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 674 | edac_mc_dump_channel(&mci->csrows[i]. |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 675 | channels[j]); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 676 | } |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 677 | for (i = 0; i < mci->tot_dimms; i++) |
| 678 | edac_mc_dump_dimm(&mci->dimms[i]); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 679 | } |
| 680 | #endif |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 681 | mutex_lock(&mem_ctls_mutex); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 682 | |
| 683 | if (add_mc_to_global_list(mci)) |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 684 | goto fail0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 685 | |
| 686 | /* set load time so that error rate can be tracked */ |
| 687 | mci->start_time = jiffies; |
| 688 | |
eric wollesen | 9794f33 | 2007-02-12 00:53:08 -0800 | [diff] [blame] | 689 | if (edac_create_sysfs_mci_device(mci)) { |
| 690 | edac_mc_printk(mci, KERN_WARNING, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 691 | "failed to create sysfs device\n"); |
eric wollesen | 9794f33 | 2007-02-12 00:53:08 -0800 | [diff] [blame] | 692 | goto fail1; |
| 693 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 694 | |
Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 695 | /* If there IS a check routine, then we are running POLLED */ |
| 696 | if (mci->edac_check != NULL) { |
| 697 | /* This instance is NOW RUNNING */ |
| 698 | mci->op_state = OP_RUNNING_POLL; |
| 699 | |
| 700 | edac_mc_workq_setup(mci, edac_mc_get_poll_msec()); |
| 701 | } else { |
| 702 | mci->op_state = OP_RUNNING_INTERRUPT; |
| 703 | } |
| 704 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 705 | /* Report action taken */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 706 | edac_mc_printk(mci, KERN_INFO, "Giving out device to '%s' '%s':" |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 707 | " DEV %s\n", mci->mod_name, mci->ctl_name, edac_dev_name(mci)); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 708 | |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 709 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 710 | return 0; |
| 711 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 712 | fail1: |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 713 | del_mc_from_global_list(mci); |
| 714 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 715 | fail0: |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 716 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 028a7b6 | 2006-03-26 01:38:47 -0800 | [diff] [blame] | 717 | return 1; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 718 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 719 | EXPORT_SYMBOL_GPL(edac_mc_add_mc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 720 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 721 | /** |
Dave Peterson | 472678e | 2006-03-26 01:38:49 -0800 | [diff] [blame] | 722 | * edac_mc_del_mc: Remove sysfs entries for specified mci structure and |
| 723 | * remove mci structure from global list |
Doug Thompson | 37f0458 | 2006-06-30 01:56:07 -0700 | [diff] [blame] | 724 | * @pdev: Pointer to 'struct device' representing mci structure to remove. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 725 | * |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 726 | * Return pointer to removed mci structure, or NULL if device not found. |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 727 | */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 728 | struct mem_ctl_info *edac_mc_del_mc(struct device *dev) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 729 | { |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 730 | struct mem_ctl_info *mci; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 731 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 732 | debugf0("%s()\n", __func__); |
| 733 | |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 734 | mutex_lock(&mem_ctls_mutex); |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 735 | |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 736 | /* find the requested mci struct in the global list */ |
| 737 | mci = find_mci_by_dev(dev); |
| 738 | if (mci == NULL) { |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 739 | mutex_unlock(&mem_ctls_mutex); |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 740 | return NULL; |
| 741 | } |
| 742 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 743 | del_mc_from_global_list(mci); |
Matthias Kaehlcke | 63b7df9 | 2007-07-19 01:49:38 -0700 | [diff] [blame] | 744 | mutex_unlock(&mem_ctls_mutex); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 745 | |
Borislav Petkov | bb31b312 | 2010-12-02 17:48:35 +0100 | [diff] [blame] | 746 | /* flush workq processes */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 747 | edac_mc_workq_teardown(mci); |
Borislav Petkov | bb31b312 | 2010-12-02 17:48:35 +0100 | [diff] [blame] | 748 | |
| 749 | /* marking MCI offline */ |
| 750 | mci->op_state = OP_OFFLINE; |
| 751 | |
| 752 | /* remove from sysfs */ |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 753 | edac_remove_sysfs_mci_device(mci); |
| 754 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 755 | edac_printk(KERN_INFO, EDAC_MC, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 756 | "Removed device %d for %s %s: DEV %s\n", mci->mc_idx, |
Stephen Rothwell | 17aa7e0 | 2008-05-05 13:54:19 +1000 | [diff] [blame] | 757 | mci->mod_name, mci->ctl_name, edac_dev_name(mci)); |
Doug Thompson | bf52fa4 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 758 | |
Dave Peterson | 18dbc33 | 2006-03-26 01:38:50 -0800 | [diff] [blame] | 759 | return mci; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 760 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 761 | EXPORT_SYMBOL_GPL(edac_mc_del_mc); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 762 | |
Adrian Bunk | 2da1c11 | 2007-07-19 01:49:32 -0700 | [diff] [blame] | 763 | static void edac_mc_scrub_block(unsigned long page, unsigned long offset, |
| 764 | u32 size) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 765 | { |
| 766 | struct page *pg; |
| 767 | void *virt_addr; |
| 768 | unsigned long flags = 0; |
| 769 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 770 | debugf3("%s()\n", __func__); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 771 | |
| 772 | /* ECC error page was not in our memory. Ignore it. */ |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 773 | if (!pfn_valid(page)) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 774 | return; |
| 775 | |
| 776 | /* Find the actual page structure then map it and fix */ |
| 777 | pg = pfn_to_page(page); |
| 778 | |
| 779 | if (PageHighMem(pg)) |
| 780 | local_irq_save(flags); |
| 781 | |
Cong Wang | 4e5df7c | 2011-11-25 23:14:19 +0800 | [diff] [blame] | 782 | virt_addr = kmap_atomic(pg); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 783 | |
| 784 | /* Perform architecture specific atomic scrub operation */ |
| 785 | atomic_scrub(virt_addr + offset, size); |
| 786 | |
| 787 | /* Unmap and complete */ |
Cong Wang | 4e5df7c | 2011-11-25 23:14:19 +0800 | [diff] [blame] | 788 | kunmap_atomic(virt_addr); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 789 | |
| 790 | if (PageHighMem(pg)) |
| 791 | local_irq_restore(flags); |
| 792 | } |
| 793 | |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 794 | /* FIXME - should return -1 */ |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 795 | int edac_mc_find_csrow_by_page(struct mem_ctl_info *mci, unsigned long page) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 796 | { |
| 797 | struct csrow_info *csrows = mci->csrows; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 798 | int row, i, j, n; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 799 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 800 | debugf1("MC%d: %s(): 0x%lx\n", mci->mc_idx, __func__, page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 801 | row = -1; |
| 802 | |
| 803 | for (i = 0; i < mci->nr_csrows; i++) { |
| 804 | struct csrow_info *csrow = &csrows[i]; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 805 | n = 0; |
| 806 | for (j = 0; j < csrow->nr_channels; j++) { |
| 807 | struct dimm_info *dimm = csrow->channels[j].dimm; |
| 808 | n += dimm->nr_pages; |
| 809 | } |
| 810 | if (n == 0) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 811 | continue; |
| 812 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 813 | debugf3("MC%d: %s(): first(0x%lx) page(0x%lx) last(0x%lx) " |
| 814 | "mask(0x%lx)\n", mci->mc_idx, __func__, |
| 815 | csrow->first_page, page, csrow->last_page, |
| 816 | csrow->page_mask); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 817 | |
| 818 | if ((page >= csrow->first_page) && |
| 819 | (page <= csrow->last_page) && |
| 820 | ((page & csrow->page_mask) == |
| 821 | (csrow->first_page & csrow->page_mask))) { |
| 822 | row = i; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | if (row == -1) |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 828 | edac_mc_printk(mci, KERN_ERR, |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 829 | "could not look up page error address %lx\n", |
| 830 | (unsigned long)page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 831 | |
| 832 | return row; |
| 833 | } |
Dave Peterson | 9110540 | 2006-03-26 01:38:55 -0800 | [diff] [blame] | 834 | EXPORT_SYMBOL_GPL(edac_mc_find_csrow_by_page); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 835 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 836 | const char *edac_layer_name[] = { |
| 837 | [EDAC_MC_LAYER_BRANCH] = "branch", |
| 838 | [EDAC_MC_LAYER_CHANNEL] = "channel", |
| 839 | [EDAC_MC_LAYER_SLOT] = "slot", |
| 840 | [EDAC_MC_LAYER_CHIP_SELECT] = "csrow", |
| 841 | }; |
| 842 | EXPORT_SYMBOL_GPL(edac_layer_name); |
| 843 | |
| 844 | static void edac_inc_ce_error(struct mem_ctl_info *mci, |
| 845 | bool enable_per_layer_report, |
| 846 | const int pos[EDAC_MAX_LAYERS]) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 847 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 848 | int i, index = 0; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 849 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 850 | mci->ce_mc++; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 851 | |
| 852 | if (!enable_per_layer_report) { |
| 853 | mci->ce_noinfo_count++; |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | for (i = 0; i < mci->n_layers; i++) { |
| 858 | if (pos[i] < 0) |
| 859 | break; |
| 860 | index += pos[i]; |
| 861 | mci->ce_per_layer[i][index]++; |
| 862 | |
| 863 | if (i < mci->n_layers - 1) |
| 864 | index *= mci->layers[i + 1].size; |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | static void edac_inc_ue_error(struct mem_ctl_info *mci, |
| 869 | bool enable_per_layer_report, |
| 870 | const int pos[EDAC_MAX_LAYERS]) |
| 871 | { |
| 872 | int i, index = 0; |
| 873 | |
Mauro Carvalho Chehab | 5926ff5 | 2012-02-09 11:05:20 -0300 | [diff] [blame] | 874 | mci->ue_mc++; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 875 | |
| 876 | if (!enable_per_layer_report) { |
| 877 | mci->ce_noinfo_count++; |
| 878 | return; |
| 879 | } |
| 880 | |
| 881 | for (i = 0; i < mci->n_layers; i++) { |
| 882 | if (pos[i] < 0) |
| 883 | break; |
| 884 | index += pos[i]; |
| 885 | mci->ue_per_layer[i][index]++; |
| 886 | |
| 887 | if (i < mci->n_layers - 1) |
| 888 | index *= mci->layers[i + 1].size; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | static void edac_ce_error(struct mem_ctl_info *mci, |
| 893 | const int pos[EDAC_MAX_LAYERS], |
| 894 | const char *msg, |
| 895 | const char *location, |
| 896 | const char *label, |
| 897 | const char *detail, |
| 898 | const char *other_detail, |
| 899 | const bool enable_per_layer_report, |
| 900 | const unsigned long page_frame_number, |
| 901 | const unsigned long offset_in_page, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 902 | long grain) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 903 | { |
| 904 | unsigned long remapped_page; |
| 905 | |
| 906 | if (edac_mc_get_log_ce()) { |
| 907 | if (other_detail && *other_detail) |
| 908 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 909 | "CE %s on %s (%s %s - %s)\n", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 910 | msg, label, location, |
| 911 | detail, other_detail); |
| 912 | else |
| 913 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 914 | "CE %s on %s (%s %s)\n", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 915 | msg, label, location, |
| 916 | detail); |
| 917 | } |
| 918 | edac_inc_ce_error(mci, enable_per_layer_report, pos); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 919 | |
| 920 | if (mci->scrub_mode & SCRUB_SW_SRC) { |
| 921 | /* |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 922 | * Some memory controllers (called MCs below) can remap |
| 923 | * memory so that it is still available at a different |
| 924 | * address when PCI devices map into memory. |
| 925 | * MC's that can't do this, lose the memory where PCI |
| 926 | * devices are mapped. This mapping is MC-dependent |
| 927 | * and so we call back into the MC driver for it to |
| 928 | * map the MC page to a physical (CPU) page which can |
| 929 | * then be mapped to a virtual page - which can then |
| 930 | * be scrubbed. |
| 931 | */ |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 932 | remapped_page = mci->ctl_page_to_phys ? |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 933 | mci->ctl_page_to_phys(mci, page_frame_number) : |
| 934 | page_frame_number; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 935 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 936 | edac_mc_scrub_block(remapped_page, |
| 937 | offset_in_page, grain); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 938 | } |
| 939 | } |
| 940 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 941 | static void edac_ue_error(struct mem_ctl_info *mci, |
| 942 | const int pos[EDAC_MAX_LAYERS], |
| 943 | const char *msg, |
| 944 | const char *location, |
| 945 | const char *label, |
| 946 | const char *detail, |
| 947 | const char *other_detail, |
| 948 | const bool enable_per_layer_report) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 949 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 950 | if (edac_mc_get_log_ue()) { |
| 951 | if (other_detail && *other_detail) |
| 952 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 953 | "UE %s on %s (%s %s - %s)\n", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 954 | msg, label, location, detail, |
| 955 | other_detail); |
| 956 | else |
| 957 | edac_mc_printk(mci, KERN_WARNING, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 958 | "UE %s on %s (%s %s)\n", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 959 | msg, label, location, detail); |
| 960 | } |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 961 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 962 | if (edac_mc_get_panic_on_ue()) { |
| 963 | if (other_detail && *other_detail) |
| 964 | panic("UE %s on %s (%s%s - %s)\n", |
| 965 | msg, label, location, detail, other_detail); |
| 966 | else |
| 967 | panic("UE %s on %s (%s%s)\n", |
| 968 | msg, label, location, detail); |
| 969 | } |
| 970 | |
| 971 | edac_inc_ue_error(mci, enable_per_layer_report, pos); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 972 | } |
| 973 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 974 | #define OTHER_LABEL " or " |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 975 | |
| 976 | /** |
| 977 | * edac_mc_handle_error - reports a memory event to userspace |
| 978 | * |
| 979 | * @type: severity of the error (CE/UE/Fatal) |
| 980 | * @mci: a struct mem_ctl_info pointer |
| 981 | * @page_frame_number: mem page where the error occurred |
| 982 | * @offset_in_page: offset of the error inside the page |
| 983 | * @syndrome: ECC syndrome |
| 984 | * @top_layer: Memory layer[0] position |
| 985 | * @mid_layer: Memory layer[1] position |
| 986 | * @low_layer: Memory layer[2] position |
| 987 | * @msg: Message meaningful to the end users that |
| 988 | * explains the event |
| 989 | * @other_detail: Technical details about the event that |
| 990 | * may help hardware manufacturers and |
| 991 | * EDAC developers to analyse the event |
| 992 | * @arch_log: Architecture-specific struct that can |
| 993 | * be used to add extended information to the |
| 994 | * tracepoint, like dumping MCE registers. |
| 995 | */ |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 996 | void edac_mc_handle_error(const enum hw_event_mc_err_type type, |
| 997 | struct mem_ctl_info *mci, |
| 998 | const unsigned long page_frame_number, |
| 999 | const unsigned long offset_in_page, |
| 1000 | const unsigned long syndrome, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1001 | const int top_layer, |
| 1002 | const int mid_layer, |
| 1003 | const int low_layer, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1004 | const char *msg, |
| 1005 | const char *other_detail, |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1006 | const void *arch_log) |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1007 | { |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1008 | /* FIXME: too much for stack: move it to some pre-alocated area */ |
| 1009 | char detail[80], location[80]; |
| 1010 | char label[(EDAC_MC_LABEL_LEN + 1 + sizeof(OTHER_LABEL)) * mci->tot_dimms]; |
| 1011 | char *p; |
| 1012 | int row = -1, chan = -1; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1013 | int pos[EDAC_MAX_LAYERS] = { top_layer, mid_layer, low_layer }; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1014 | int i; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1015 | long grain; |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1016 | bool enable_per_layer_report = false; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1017 | u16 error_count; /* FIXME: make it a parameter */ |
| 1018 | u8 grain_bits; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1019 | |
Dave Peterson | 537fba2 | 2006-03-26 01:38:40 -0800 | [diff] [blame] | 1020 | debugf3("MC%d: %s()\n", mci->mc_idx, __func__); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1021 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1022 | /* |
| 1023 | * Check if the event report is consistent and if the memory |
| 1024 | * location is known. If it is known, enable_per_layer_report will be |
| 1025 | * true, the DIMM(s) label info will be filled and the per-layer |
| 1026 | * error counters will be incremented. |
| 1027 | */ |
| 1028 | for (i = 0; i < mci->n_layers; i++) { |
| 1029 | if (pos[i] >= (int)mci->layers[i].size) { |
| 1030 | if (type == HW_EVENT_ERR_CORRECTED) |
| 1031 | p = "CE"; |
| 1032 | else |
| 1033 | p = "UE"; |
| 1034 | |
| 1035 | edac_mc_printk(mci, KERN_ERR, |
| 1036 | "INTERNAL ERROR: %s value is out of range (%d >= %d)\n", |
| 1037 | edac_layer_name[mci->layers[i].type], |
| 1038 | pos[i], mci->layers[i].size); |
| 1039 | /* |
| 1040 | * Instead of just returning it, let's use what's |
| 1041 | * known about the error. The increment routines and |
| 1042 | * the DIMM filter logic will do the right thing by |
| 1043 | * pointing the likely damaged DIMMs. |
| 1044 | */ |
| 1045 | pos[i] = -1; |
| 1046 | } |
| 1047 | if (pos[i] >= 0) |
| 1048 | enable_per_layer_report = true; |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1049 | } |
| 1050 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1051 | /* |
| 1052 | * Get the dimm label/grain that applies to the match criteria. |
| 1053 | * As the error algorithm may not be able to point to just one memory |
| 1054 | * stick, the logic here will get all possible labels that could |
| 1055 | * pottentially be affected by the error. |
| 1056 | * On FB-DIMM memory controllers, for uncorrected errors, it is common |
| 1057 | * to have only the MC channel and the MC dimm (also called "branch") |
| 1058 | * but the channel is not known, as the memory is arranged in pairs, |
| 1059 | * where each memory belongs to a separate channel within the same |
| 1060 | * branch. |
| 1061 | */ |
| 1062 | grain = 0; |
| 1063 | p = label; |
| 1064 | *p = '\0'; |
| 1065 | for (i = 0; i < mci->tot_dimms; i++) { |
| 1066 | struct dimm_info *dimm = &mci->dimms[i]; |
Dave Peterson | e7ecd89 | 2006-03-26 01:38:52 -0800 | [diff] [blame] | 1067 | |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1068 | if (top_layer >= 0 && top_layer != dimm->location[0]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1069 | continue; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1070 | if (mid_layer >= 0 && mid_layer != dimm->location[1]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1071 | continue; |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1072 | if (low_layer >= 0 && low_layer != dimm->location[2]) |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1073 | continue; |
| 1074 | |
| 1075 | /* get the max grain, over the error match range */ |
| 1076 | if (dimm->grain > grain) |
| 1077 | grain = dimm->grain; |
| 1078 | |
| 1079 | /* |
| 1080 | * If the error is memory-controller wide, there's no need to |
| 1081 | * seek for the affected DIMMs because the whole |
| 1082 | * channel/memory controller/... may be affected. |
| 1083 | * Also, don't show errors for empty DIMM slots. |
| 1084 | */ |
| 1085 | if (enable_per_layer_report && dimm->nr_pages) { |
| 1086 | if (p != label) { |
| 1087 | strcpy(p, OTHER_LABEL); |
| 1088 | p += strlen(OTHER_LABEL); |
| 1089 | } |
| 1090 | strcpy(p, dimm->label); |
| 1091 | p += strlen(p); |
| 1092 | *p = '\0'; |
| 1093 | |
| 1094 | /* |
| 1095 | * get csrow/channel of the DIMM, in order to allow |
| 1096 | * incrementing the compat API counters |
| 1097 | */ |
| 1098 | debugf4("%s: %s csrows map: (%d,%d)\n", |
| 1099 | __func__, |
| 1100 | mci->mem_is_per_rank ? "rank" : "dimm", |
| 1101 | dimm->csrow, dimm->cschannel); |
| 1102 | |
| 1103 | if (row == -1) |
| 1104 | row = dimm->csrow; |
| 1105 | else if (row >= 0 && row != dimm->csrow) |
| 1106 | row = -2; |
| 1107 | |
| 1108 | if (chan == -1) |
| 1109 | chan = dimm->cschannel; |
| 1110 | else if (chan >= 0 && chan != dimm->cschannel) |
| 1111 | chan = -2; |
| 1112 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1113 | } |
| 1114 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1115 | if (!enable_per_layer_report) { |
| 1116 | strcpy(label, "any memory"); |
| 1117 | } else { |
| 1118 | debugf4("%s: csrow/channel to increment: (%d,%d)\n", |
| 1119 | __func__, row, chan); |
| 1120 | if (p == label) |
| 1121 | strcpy(label, "unknown memory"); |
| 1122 | if (type == HW_EVENT_ERR_CORRECTED) { |
| 1123 | if (row >= 0) { |
| 1124 | mci->csrows[row].ce_count++; |
| 1125 | if (chan >= 0) |
| 1126 | mci->csrows[row].channels[chan].ce_count++; |
| 1127 | } |
| 1128 | } else |
| 1129 | if (row >= 0) |
| 1130 | mci->csrows[row].ue_count++; |
| 1131 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1132 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1133 | /* Fill the RAM location data */ |
| 1134 | p = location; |
| 1135 | for (i = 0; i < mci->n_layers; i++) { |
| 1136 | if (pos[i] < 0) |
| 1137 | continue; |
| 1138 | |
| 1139 | p += sprintf(p, "%s:%d ", |
| 1140 | edac_layer_name[mci->layers[i].type], |
| 1141 | pos[i]); |
| 1142 | } |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1143 | if (p > location) |
| 1144 | *(p - 1) = '\0'; |
| 1145 | |
| 1146 | /* Report the error via the trace interface */ |
| 1147 | |
| 1148 | error_count = 1; /* FIXME: allow change it */ |
| 1149 | grain_bits = fls_long(grain) + 1; |
| 1150 | trace_mc_event(type, msg, label, error_count, |
| 1151 | mci->mc_idx, top_layer, mid_layer, low_layer, |
| 1152 | PAGES_TO_MiB(page_frame_number) | offset_in_page, |
| 1153 | grain_bits, syndrome, other_detail); |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1154 | |
| 1155 | /* Memory type dependent details about the error */ |
| 1156 | if (type == HW_EVENT_ERR_CORRECTED) { |
| 1157 | snprintf(detail, sizeof(detail), |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1158 | "page:0x%lx offset:0x%lx grain:%ld syndrome:0x%lx", |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 1159 | page_frame_number, offset_in_page, |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1160 | grain, syndrome); |
| 1161 | edac_ce_error(mci, pos, msg, location, label, detail, |
| 1162 | other_detail, enable_per_layer_report, |
| 1163 | page_frame_number, offset_in_page, grain); |
| 1164 | } else { |
| 1165 | snprintf(detail, sizeof(detail), |
Mauro Carvalho Chehab | 53f2d02 | 2012-02-23 08:10:34 -0300 | [diff] [blame] | 1166 | "page:0x%lx offset:0x%lx grain:%ld", |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1167 | page_frame_number, offset_in_page, grain); |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1168 | |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1169 | edac_ue_error(mci, pos, msg, location, label, detail, |
| 1170 | other_detail, enable_per_layer_report); |
| 1171 | } |
Alan Cox | da9bb1d | 2006-01-18 17:44:13 -0800 | [diff] [blame] | 1172 | } |
Mauro Carvalho Chehab | 4275be6 | 2012-04-18 15:20:50 -0300 | [diff] [blame] | 1173 | EXPORT_SYMBOL_GPL(edac_mc_handle_error); |